{"id":127,"date":"2014-12-16T16:03:58","date_gmt":"2014-12-17T00:03:58","guid":{"rendered":"http:\/\/thenscaler.com\/?p=127"},"modified":"2014-12-16T16:22:15","modified_gmt":"2014-12-17T00:22:15","slug":"model-railroader-meet-arduino","status":"publish","type":"post","link":"https:\/\/thenscaler.com\/?p=127","title":{"rendered":"Model Railroader, Meet Arduino"},"content":{"rendered":"<p>I was not even slightly surprised when I opened the <a title=\"Model Railroader Magazine, Dec 2014\" href=\"http:\/\/mrr.trains.com\/issues\/2014\/december-2014\" target=\"_blank\">December 2014 Model Railroader Magazine<\/a>, to encounter &#8220;RFID for Model Railroad Operations.&#8221; There seems to be considerable interest in RFID among model railroaders,\u00a0enough that there\u00a0is\u00a0<a title=\"JMRI RFID\" href=\"http:\/\/jmri.sourceforge.net\/help\/en\/html\/hardware\/rfid\/index.shtml\" target=\"_blank\">JMRI support<\/a>\u00a0available, and this project looks like a particularly nice piece of work.<\/p>\n<p>The illustrations caught my eye and I recognized that at the heart of their system is an open source microcontroller board called the Arduino Uno.<\/p>\n<div id=\"attachment_181\" style=\"width: 310px\" class=\"wp-caption alignright\"><a href=\"https:\/\/thenscaler.com\/wp-content\/uploads\/2014\/11\/Uno.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-181\" class=\"wp-image-181 size-medium\" src=\"https:\/\/thenscaler.com\/wp-content\/uploads\/2014\/11\/Uno-300x199.jpg\" alt=\"Arduino Uno R3\" width=\"300\" height=\"199\" srcset=\"https:\/\/thenscaler.com\/wp-content\/uploads\/2014\/11\/Uno-300x199.jpg 300w, https:\/\/thenscaler.com\/wp-content\/uploads\/2014\/11\/Uno.jpg 600w\" sizes=\"auto, (max-width: 300px) 100vw, 300px\" \/><\/a><p id=\"caption-attachment-181\" class=\"wp-caption-text\">Arduino Uno R3<\/p><\/div>\n<p>You have to know what you are looking at, or dig into the article to get that bit of information.\u00a0\u00a0A one sentence editor&#8217;s note explains that Uno&#8217;s are &#8220;simple computers that can be programmed to do many useful model railroading tasks.&#8221;<\/p>\n<p>Oh, my.\u00a0 That&#8217;s no way to introduce a hobby to a new dance partner.\u00a0We&#8217;ve met once before in the <a title=\"Model Railroader Magazine, June 2013\" href=\"http:\/\/mrr.trains.com\/issues\/2013\/june-2013\" target=\"_blank\">June 2013 Model Railroader Magazine<\/a> article &#8220;High Tech Turnout Controls.&#8221; But everyone was a little shy back then, there was really not enough information about the new partner to truly understand its potential.\u00a0Referring to unseen\u00a0computer code that has to be compiled and uploaded was probably a bit frightening to some.\u00a0And, I suppose it didn&#8217;t help that the servo installation presented was, shall we say, a little too utilitarian.<\/p>\n<p>No matter.\u00a0Lets start over and get the introduction right this time,\u00a0because the dance has already begun!<\/p>\n<p><strong>What is a Microcontroller?<\/strong><\/p>\n<p>Microcontrollers are integrated circuit chips that have the basic logic and input\/output capabilities that constitute a simple computer. Microcontroller\u00a0boards place that chip with a few essential external components on a board with power and ways to plug things in. Microcontrollers have been around for a long time; you&#8217;ll find them in almost everything electronic.\u00a0 What&#8217;s new is how inexpensive the chips and supporting components have become.<\/p>\n<p>The best known, and by far best developed <a title=\"Open source\" href=\"http:\/\/en.wikipedia.org\/wiki\/Open_source\" target=\"_blank\">open source<\/a>\u00a0microcontroller board system is the <a title=\"The Arduino Project\" href=\"http:\/\/www.arduino.cc\">Arduino Project<\/a>. In <a title=\"Arduino - Introduction\" href=\"http:\/\/www.arduino.cc\/en\/Guide\/Introduction\">their words<\/a>:<\/p>\n<blockquote><p>Arduino is a tool for making computers that can sense and control more of the physical world than your desktop computer. It&#8217;s an open-source physical computing platform based on a simple microcontroller board, and a development environment for writing software for the board.<\/p><\/blockquote>\n<p>Microcontroller boards like Arduino\u00a0are simpler than microcomputers like the <a title=\"Rasperry Pi\" href=\"http:\/\/www.raspberrypi.org\/\" target=\"_blank\">Raspberry Pi<\/a> or the <a title=\"BeagleBoard.org\" href=\"http:\/\/beagleboard.org\" target=\"_blank\">Beaglebone<\/a>.\u00a0 Aside from differences in the controller\/processor used, the big difference is that microcomputers come with more peripheral components and memory to allow them to load an operating system.\u00a0 You don&#8217;t generally use an &#8220;operating system&#8221; with a microcontroller: rather the board is designed to run whatever code you&#8217;ve loaded in the board&#8217;s permanent memory. In essence, your program <strong>is<\/strong> the firmware\/operating system for the board.<\/p>\n<p>The Arduino interacts with the physical world using <em>sensors<\/em> and <em>actuators<\/em>. Sensors can be anything that responds to an external influence:<\/p>\n<ul>\n<li>buttons and switches,\n<p><div id=\"attachment_182\" style=\"width: 150px\" class=\"wp-caption alignright\"><a href=\"https:\/\/thenscaler.com\/wp-content\/uploads\/2014\/11\/micro-button.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-182\" class=\"wp-image-182 size-full\" src=\"https:\/\/thenscaler.com\/wp-content\/uploads\/2014\/11\/micro-button.jpg\" alt=\"micro button\" width=\"140\" height=\"140\" srcset=\"https:\/\/thenscaler.com\/wp-content\/uploads\/2014\/11\/micro-button.jpg 140w, https:\/\/thenscaler.com\/wp-content\/uploads\/2014\/11\/micro-button-50x50.jpg 50w\" sizes=\"auto, (max-width: 140px) 100vw, 140px\" \/><\/a><p id=\"caption-attachment-182\" class=\"wp-caption-text\">Micro Push Button<\/p><\/div><\/li>\n<li>optical sensors, such as photoresistors, IR\/UV and so on,<\/li>\n<li>current and voltage sensors,<\/li>\n<li>touch and proximity sensors,<\/li>\n<li>RFID sensors,<\/li>\n<li>GPS and other position sensors, include tilt and acceleration,<\/li>\n<li>USB and various kinds of\u00a0network communications,<\/li>\n<li>anything that can produce a 0-5v current to signal its state, either as an on\/off (digital) signal, or as\u00a0a variable current (analog).<\/li>\n<\/ul>\n<div id=\"attachment_183\" style=\"width: 160px\" class=\"wp-caption alignright\"><a href=\"https:\/\/thenscaler.com\/wp-content\/uploads\/2014\/11\/9degrees-Sensor.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-183\" class=\"wp-image-183 size-thumbnail\" src=\"https:\/\/thenscaler.com\/wp-content\/uploads\/2014\/11\/9degrees-Sensor-150x150.jpg\" alt=\"Combination accelerometer, Gyro and Magnetometer\" width=\"150\" height=\"150\" srcset=\"https:\/\/thenscaler.com\/wp-content\/uploads\/2014\/11\/9degrees-Sensor-150x150.jpg 150w, https:\/\/thenscaler.com\/wp-content\/uploads\/2014\/11\/9degrees-Sensor-300x300.jpg 300w, https:\/\/thenscaler.com\/wp-content\/uploads\/2014\/11\/9degrees-Sensor-50x50.jpg 50w, https:\/\/thenscaler.com\/wp-content\/uploads\/2014\/11\/9degrees-Sensor.jpg 600w\" sizes=\"auto, (max-width: 150px) 100vw, 150px\" \/><\/a><p id=\"caption-attachment-183\" class=\"wp-caption-text\">Combination accelerometer, gyro and magnetometer<\/p><\/div>\n<p>Sensors can be <a title=\"Over 200 sensors available at Sparkfun\" href=\"https:\/\/www.sparkfun.com\/categories\/23\" target=\"_blank\">a single chip\/component, or another board or external assembly<\/a>\u00a0that communicates with the Arduino.<\/p>\n<p>The code\u00a0you upload to\u00a0the Arduino can read the sensors and take logical actions based on those readings.\u00a0 It takes actions by controlling actuators. Actuators include:<\/p>\n<ul>\n<li>AC\/DC motors,<\/li>\n<li>servos &amp; steppers,<\/li>\n<li>switches, relays, transistors and other current amplification and modulation devices,<\/li>\n<li>LCD&#8217;s, LED&#8217;s, OLED&#8217;s\u00a0both individually and in arrays up to and including small screens,<\/li>\n<li>USB and various kinds of\u00a0network communications.<\/li>\n<\/ul>\n<div id=\"attachment_186\" style=\"width: 516px\" class=\"wp-caption aligncenter\"><a href=\"https:\/\/thenscaler.com\/wp-content\/uploads\/2014\/11\/touch-tft.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-186\" class=\"size-large wp-image-186\" src=\"https:\/\/thenscaler.com\/wp-content\/uploads\/2014\/11\/touch-tft-1024x768.jpg\" alt=\"Adafruit TFT Touchscreen\" width=\"506\" height=\"379\" srcset=\"https:\/\/thenscaler.com\/wp-content\/uploads\/2014\/11\/touch-tft-1024x768.jpg 1024w, https:\/\/thenscaler.com\/wp-content\/uploads\/2014\/11\/touch-tft-300x225.jpg 300w, https:\/\/thenscaler.com\/wp-content\/uploads\/2014\/11\/touch-tft.jpg 1200w\" sizes=\"auto, (max-width: 506px) 100vw, 506px\" \/><\/a><p id=\"caption-attachment-186\" class=\"wp-caption-text\">Adafruit 3.8&#8243; TFT Touchscreen and an Uno<\/p><\/div>\n<p><a title=\"Adafruit Industries\" href=\"http:\/\/adafruit.com\" target=\"_blank\">Adafruit Industries <\/a>has the above touchscreen, along with a lot of other cool sensor and actuator devices to use with Arduino.<\/p>\n<div id=\"attachment_184\" style=\"width: 160px\" class=\"wp-caption alignleft\"><a href=\"https:\/\/thenscaler.com\/wp-content\/uploads\/2014\/11\/stepper-motor.jpg\"><img loading=\"lazy\" decoding=\"async\" aria-describedby=\"caption-attachment-184\" class=\"size-thumbnail wp-image-184\" src=\"https:\/\/thenscaler.com\/wp-content\/uploads\/2014\/11\/stepper-motor-150x150.jpg\" alt=\"Stepper motor.\" width=\"150\" height=\"150\" srcset=\"https:\/\/thenscaler.com\/wp-content\/uploads\/2014\/11\/stepper-motor-150x150.jpg 150w, https:\/\/thenscaler.com\/wp-content\/uploads\/2014\/11\/stepper-motor-50x50.jpg 50w\" sizes=\"auto, (max-width: 150px) 100vw, 150px\" \/><\/a><p id=\"caption-attachment-184\" class=\"wp-caption-text\">Stepper motor.<\/p><\/div>\n<p>The basic structure of an Arduino sketch (program) is a continuous loop that checks the sensors and acts as required.\u00a0Depending on\u00a0the complexity of\u00a0the sketch, the basic sense\/act loop can cycle hundreds or thousands of times per second.\u00a0Since you are directly interacting with the hardware without an operating system, your sketch has fairly precise control of all interactions.<\/p>\n<p>&nbsp;<\/p>\n<p><strong>Programming?<\/strong><\/p>\n<p>The Arduino is a teaching and learning tool.\u00a0 If you don&#8217;t know anything about computer programming, this little board was\u00a0designed for you! You don&#8217;t really have to know C++ (the language used by the development\u00a0tool)\u00a0as such; you just\u00a0have to\u00a0learn and follow the basic rules as applied to the Arduino, all laid out in the tutorial system. If you can do basic math and logic, you can learn this.<\/p>\n<p>If anything, novices may have an advantage over folks who program larger and more complex systems&#8211;who may have to\u00a0rethink a few habits to adapt to the limits of the Arduino. The Arduino IDE hides most compiler preprocessing, which is great for newbies and lousy for those used to having total control of the preprocessing\/compiling process.<\/p>\n<p>Lets take the basic use case&#8211;turnout control&#8211;as discussed in the June 2013 MRR article. I&#8217;ve done a little <a title=\"Turnout Control with Arduino and Servos\" href=\"https:\/\/thenscaler.com\/?page_id=174\">Q&amp;D on the basics of setting up and using a servo for turnout control<\/a>; take a look to see what the code looks like. It&#8217;s a lot more straightforward than you might expect.<\/p>\n<p><strong>But What&#8217;s it For?<\/strong><\/p>\n<p>So turnout control is one use, but it may not be entirely clear why this is better than traditional turnout motors and wiring. From my point of view, it comes down to leverage: getting a lot more functionality for the money.<\/p>\n<p>Given that a single Arduino Uno ($25) can support multiple micro servos costing $2\u00a0&#8211; $4 each, its easy to see how an Uno running 4 turnout servos is saving money; even more if one Uno can manage an\u00a0Yard full of servos. Other functions that might be handled by accessory contacts on an expensive\u00a0turnout machine can be handled easily by the Arduino at the same time, like running signals, managing track power relays\u00a0or triggering other systems. As you stack related functionality onto a network of Arduinos, instead of investing in multiple single-purpose systems, the combined enhanced functionality and cost savings of this approach becomes quite compelling.<\/p>\n<p>Among model railroaders on the web who are working with Arduino, the most common thread I&#8217;m finding is to use the Arduino as an adjunct to the DCC system. An obvious approach is to use a stationary decoder as a &#8220;sensor&#8221; that the\u00a0Arduino responds to with whatever task you have in mind &#8212; for instance,\u00a0this would work well\u00a0where the Arduino is an animation controller.<\/p>\n<p>To get an\u00a0Arduino and DCC system to communicate with each other without a decoder,\u00a0you could\u00a0use the generic USB interface, which most Arduino boards\u00a0and many DCC systems support. Since DCC systems don&#8217;t speak Arduino, something like <a title=\"JMRI Home\" href=\"http:\/\/jmri.sourceforge.net\/\" target=\"_blank\">JMRI <\/a>is needed to glue it all together.<\/p>\n<p>Others, like the <a title=\"MRRWA\" href=\"http:\/\/mrrwa.org\/\" target=\"_blank\">Model Railroading with Arduino<\/a>\u00a0project, an off-shoot of the <a title=\"Open DCC\" href=\"http:\/\/sourceforge.net\/projects\/opendcc\/\" target=\"_blank\">Open DCC Project<\/a>,\u00a0are working on direct Arduino\/DCC interfaces. It&#8217;s pretty straight forward to interface an Arduino with the DCC command bus. Check out this project using an <a href=\"http:\/\/model-railroad-hobbyist.com\/node\/19446\" target=\"_blank\">Arduino Mini to create a 17 function DCC decoder<\/a>. As to the unreasonably low price the author reports for his Arduino Mini Pro, please see this <a title=\"Compatibles and clones\" href=\"http:\/\/blog.arduino.cc\/2013\/07\/10\/send-in-the-clones\/\" target=\"_blank\">post about Arduinos, compatibles and counterfeits<\/a>. If you find these things useful and want the benefits of further development, then you\u00a0should care about the ecosystem.\u00a0An <a title=\"Arduino Mini from SparkFun\" href=\"https:\/\/www.sparkfun.com\/products\/11113\" target=\"_blank\">official Mini Pro from SparkFun <\/a>lists for $9.95. and a portion of its proceeds are given back to the Arduino Project.<\/p>\n<p>Controlling turnouts with servos and an Arduino, RFID decoding or even creating a &#8220;programmable DCC decoder&#8221; using an Arduino\u00a0represents a small fraction of the potential of these devices. The trend today seems to be toward greater centralization of model railroad control systems. Embedded microcontrollers can be a step down that road as well, adding considerable functionality as &#8220;decoders with brains&#8221;; or they can take you in an entirely different direction&#8211;where semi-autonomous logic devices controlling different aspects of the layout interact with each other and with the operators in dynamic ways.<\/p>\n<p>I&#8217;ll give a little more substance to these ideas as this project progresses.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>I was not even slightly surprised when I opened the December 2014 Model Railroader Magazine, to encounter &#8220;RFID for Model Railroad Operations.&#8221; There seems to be considerable interest in RFID among model railroaders,\u00a0enough that there\u00a0is\u00a0JMRI support\u00a0available, and this project looks like a particularly nice piece of work. The illustrations caught my eye and I recognized [&hellip;]<\/p>\n","protected":false},"author":2,"featured_media":186,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[21],"tags":[22,23,26,27,25,24],"class_list":["post-127","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-layout-control","tag-arduino","tag-dcc","tag-jmri","tag-mrrwa","tag-opendcc","tag-rfid"],"_links":{"self":[{"href":"https:\/\/thenscaler.com\/index.php?rest_route=\/wp\/v2\/posts\/127","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/thenscaler.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/thenscaler.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/thenscaler.com\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/thenscaler.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=127"}],"version-history":[{"count":35,"href":"https:\/\/thenscaler.com\/index.php?rest_route=\/wp\/v2\/posts\/127\/revisions"}],"predecessor-version":[{"id":245,"href":"https:\/\/thenscaler.com\/index.php?rest_route=\/wp\/v2\/posts\/127\/revisions\/245"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/thenscaler.com\/index.php?rest_route=\/wp\/v2\/media\/186"}],"wp:attachment":[{"href":"https:\/\/thenscaler.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=127"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/thenscaler.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=127"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/thenscaler.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=127"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}