Trains.com

Subscriber & Member Login

Login, or register today to interact in our online community, comment on articles, receive our newsletter, manage your account online and more!

Arduino in model railroading

13169 views
34 replies
1 rating 2 rating 3 rating 4 rating 5 rating
  • Member since
    February 2002
  • From: Reading, PA
  • 30,002 posts
Posted by rrinker on Wednesday, November 4, 2015 4:14 PM

 The year I did FORTRAN in high school was the first year they DIDN'T use punch cards and send them to the district office to run on the mainframe. We had Apple II's with a pair of floppies and their FORTRAN. I taught the teacher as much as she taught me. I college we had a required FORTRAN course which was a super breeze for me since it was my second time with the language, if they gave out greater than a 4.0 I would have had like a 4.5 average. I made money the following years being a tutor for the class. Used it in the workign world exactly once - the place I worked as my first post-college job bought this used coordinate measuring machine that was driven by a PDP11-T/23. The computer wasn't working reliably when we got it so I fixed it up, and then I wrote a few FORTRAN programs to automate testing of some of our parts we made, and spit out a printed report. Lots of fun. And later when Windows NT came out, it was somewhat familiar under the hood - the PDP11 had RSX-11, which was written by the same guy who left DEC and went to Microsoft and designed NT.

                   --Randy


Modeling the Reading Railroad in the 1950's

 

Visit my web site at www.readingeastpenn.com for construction updates, DCC Info, and more.

  • Member since
    March 2007
  • From: College Station, TX
  • 675 posts
Posted by Arjay1969 on Friday, November 6, 2015 10:45 PM

A timely subject for me.

 

I'm working on a few grade crossings for my club right now. Some simple flashers, some flashers with gates, and four wig-wags.  These will all be arduino (Adafruit Pro Trinket, actually) based, using infrared proximity detectors purchased off of ebay (around $1 each).

The fun part was getting a startup and ending sequence written for the wig-wags so that it didn't just go immediately from idle (hanging straight down) to full swing, but gradually builds up the momentum through three or four swings, andgradually slows down to a stop at the end.

I'm almost ready to install the wig-wag prototype, and will be sure to get pictures and video to post. Smile

Robert Beaty

The Laughing Hippie

-----------------------------------------------------------------

The CF-7...a waste of a perfectly good F-unit!

-----------------------------------------------------------------

Then it comes to be that the soothing light at the

end of your tunnel, Was just a freight train coming

your way.          -Metallica, No Leaf Clover

-----------------------------------------------------------------

  • Member since
    July 2009
  • From: lavale, md
  • 4,678 posts
Posted by gregc on Saturday, November 7, 2015 5:48 AM

when I read some of these responses, I can't help but think that an Arduino is overkill for some of these projects.   (They have a 2nd processor that programs the primary processor thru USB and similar processors are used as DCC decoders and command station controllers).

But I realize they are the equivalent of the 60-in-1 electronic project kits and avoid using a cassette to store programs on early microprocessor kits I had when I was a kid.  Arduinos open the door to firmware projects for hobbyists and students and I'd like to offer some advice.  

software vs firmware -- a paycheck program is software and the microprocessing in your microwave runs firmware.  Firmware controls hardware, usually with real-time constraints (e.g. slowly lift a semaphore).

 

I believe a common novice shortcoming is to write a long sequence of code that manipulates data or hardware.  A better way of developing firmware is as a set of sub-functions that perform various types of hardware operations and to think of the program as a sequence of functions that affect hardware (e.g. LED on for a specified time, or slowly raise a semaphore).

It's easy to copy and paste code when doing something similar things.  But any time code is repeated, it's usually better to create a sub-function that can be re-used.  This not only makes the code smaller, it also makes it easier to maintain (only one place to fix a mistake).    It also makes developers think more generically about what they are doing and to develop a toolkit of sub-functions that can be used for different purposes and programs.    (At an even higher level is to let data drive the sequence).

another shortcoming is using constants instead of symbols.  A constant is value, "3", that appears in the code.  A symbol can be either a variable or some non-changeable named value.  A variable could be "flashRateSec" which is set to 3.  C-code used #defines for constants, "ClockTicMilleseconds", 1000, while other languages have things like variables called constant.  Seeing a symbol name in the code, "flashRate", is usually easier to maintain and understand than simply a number, 3.

While I write code for others to understand, I mostly write it so that I can understand it after not looking at for a couple weeks.

 

Being an EE, the one elective computer science course I took used a book entitled Algorithms + Data Structures = Programs which still guides me in developing telecom firmware at work today.  And along these lines, the following quote

I'd rather write programs that write programs than write programs -- Richard Sites.

 

While these suggestions may not seem so important while writing a first program, I think they will make more sense when writing a second, similar program.

greg - Philadelphia & Reading / Reading

  • Member since
    February 2002
  • From: Reading, PA
  • 30,002 posts
Posted by rrinker on Saturday, November 7, 2015 2:12 PM

 That's why I mentioned using things liek the Nano and Pro Mini. It IS overkill to build every system with an Uno or similar, as most of what's on there you will never use once development is complete and the project is operational. You don;t need fancy header pins, or the second micro for the USB port once everythign is up and running. ANd you can get Nanos on eBay for less than $3. Which yes, means you cna probably get bare ATMega 328's for 50 cents or something. While it's all possible to use an Arduino to get even bare chips set up, it moves beyond the basic novice level targeted by the Arduino concept.

 The Uno and a bunch of shields makes a great development system on the bench to design and test new projects, but even with the low cost it is just a bit too much to put them in every permanent project (vs hard wiring your own circuit following the design you came up with using the Uno and the shields). Sticking with something like the Nano instead of using bare micros keeps the loading and testing of code simple, and takes care of the basic housekeeping circuitry needed to run the micro. You just hook your circuit to the IO pins the same as it was wired to the Uno.

              --Randy


Modeling the Reading Railroad in the 1950's

 

Visit my web site at www.readingeastpenn.com for construction updates, DCC Info, and more.

  • Member since
    August 2011
  • 805 posts
Posted by narrow gauge nuclear on Tuesday, November 10, 2015 12:11 AM

Randy is spot on.  I have used the Arduino UNO rev 3 for all my development work on many projects from nuclear counters to MR stuff.  The UNO can be had for under $20.00.  The mini pro is always my final install as it is a full UNO with two extra added analog ports, but minus the UNO's built in USB port so programing the pro mini can easily be done with a detachable USB adapter.  Once programmed following deveolpment on the UNO the $4.00 pro-mini is a full micro controller on a tiny stick of a board and draws about 25ma (1/40th of an amp).

  I crash learned the development system for the Arduino (IDE -its programming language), in about two weeks well enough to do some rather complicated stuff and within a year was rather fully functional across the board.

The arduino was created for artists orginally!!!!  (Low to no tech folks to be sure)  I figured, how hard could it be?  I was right; it is rather easy if you get a good book that takes you by the hand.

 

Richard

If I can't fix it, I can fix it so it can't be fixed

Subscriber & Member Login

Login, or register today to interact in our online community, comment on articles, receive our newsletter, manage your account online and more!

Users Online

There are no community member online

Search the Community

ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT
Model Railroader Newsletter See all
Sign up for our FREE e-newsletter and get model railroad news in your inbox!