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

3866 views
22 replies
1 rating 2 rating 3 rating 4 rating 5 rating
  • Member since
    April 2015
  • 469 posts
Arduino
Posted by Enzoamps on Sunday, January 9, 2022 1:00 AM

In the current MR there is a letter from someone suggesting the earlier idea of using LEDs to represent fusees would be improved by making them flicker.  He said to power the LEDs with an Arduino.  SO far so good.

My career was in electronics, I started almost 70 years ago.  I have a wide range of electtronic skills, but Arduino ain't one of them.  I often see them ssuggested as a solution to some electronic probem, but they solution is usually something like, "Then, it is a simple matter to program the Arduino to..."

How on earth does one do that?

  • Member since
    July 2009
  • From: lavale, md
  • 4,678 posts
Posted by gregc on Sunday, January 9, 2022 4:29 AM

while the microprocessor revolution led to the high performance computers and servers we have today  it also resulted in small microcontrollers which are complete systems on a chip.  processors such at the Atmel 328p processor used on Arduinos include RAM and Flash memory, as well as a plethora of peripherals for interfacing to hardware.

i believe implementation of a "fusee" requires random timing for the flicker as well as random LED intensity.

The Arduino IDE supports development of code written in C++ and includes many of the standard C++ libraries including the random() function which can be used for timing.

the Atmel processor also includes a PWM output that can be used to control LED intensity.

modern electronics is no longer dominated by hardware requiring rewiring to change functionality.   It no longer requires replacing reprogramable EEPROM or FPGAs.   today's electronics is dominated by processors that can easily be reprogrammed in the field and over the internet.

the last project i worked on (femtoCell) had dozens of processors on a single chip and even the Arduino has separate processors for the user application and USB interface to the PC 

27

greg - Philadelphia & Reading / Reading

  • Member since
    January 2010
  • 170 posts
Posted by nycmodel on Sunday, January 9, 2022 6:32 AM

Google is your friend. Tons of information out there about Arduinos including model RR apps. I would suggest getting one of the startup kits that come with all you need to set up example apps. The examples cover much of the code. At least what you will need to experiment.

  • Member since
    July 2009
  • From: lavale, md
  • 4,678 posts
Posted by gregc on Sunday, January 9, 2022 6:58 AM

nycmodel
I would suggest getting one of the startup kits

a lot can be done with a Multifunction board

91

greg - Philadelphia & Reading / Reading

  • Member since
    December 2015
  • From: Shenandoah Valley
  • 9,094 posts
Posted by BigDaddy on Sunday, January 9, 2022 9:43 AM

An arduino program is called a sketch, because it was designed with artists in mind, not engineers.  I have a starter kit, but have not gotten around to playing with it.

You can find lots of canned programming, already written for you with Youtube, as well as your favorite search engine. 

Much of it is copy this and it will workThat may suit your needs but you won't really be able to write your own sketch.   There are starter lessons that teach you how to do small and then larger programming.

This is a quick video to show you how to get an led to blink.  Flikering is not just rapid blinking but varying on and off times.  But it does show how the resistor, led and arduino connect.

Henry

COB Potomac & Northern

Shenandoah Valley

  • Member since
    July 2009
  • From: lavale, md
  • 4,678 posts
Posted by gregc on Sunday, January 9, 2022 5:15 PM

Enzoamps
"Then, it is a simple matter to program the Arduino to..."

here's an example

const byte ledPin = 10;

unsigned long msecLst;
unsigned long Period = 100;

void loop()
{
    unsigned long msec = millis ();

    if ( (msec - msecLst) > Period)  {
        msecLst = msec;
        analogWrite (ledPin, random (200, 255));
    }
}

void setup()
{
    pinMode (ledPin, OUTPUT);
}

greg - Philadelphia & Reading / Reading

  • Member since
    February 2018
  • From: Flyover Country
  • 5,557 posts
Posted by York1 on Sunday, January 9, 2022 8:26 PM

For someone like me, the man who did these videos was just the right instructor for Arduino.

He explained everything, beginning with the basics.

https://www.youtube.com/c/mcwhorpj

York1 John       

  • Member since
    April 2015
  • 469 posts
Posted by Enzoamps on Sunday, January 9, 2022 11:34 PM

OK, the guy in the video York linked seemed basic enough.  I learned you have to use a computer to program it, and it has a USB for power and program.  I worked in digital for many years, but not in coding.  I did study FORTRAN about 60 years ago, but a C program looks like when my cat walks on my keyboard. It looks like you need some familiarity with its programming language.

  • Member since
    January 2009
  • From: Bakersfield, CA 93308
  • 6,526 posts
Posted by RR_Mel on Monday, January 10, 2022 12:22 AM

I started out in electronics in February 1958 and retired December 2007.  I never got into programming and decided I wanted to use Arduinos on my layout.  It was all new to me but I managed to figure out how to write some basic code.

I had some problems but the guys on the Forum helped me out when I got into a bind.  Randy Rinker was a big help.

After about four years I have a bit over a dozen Arduinos working very well.  I have several UNO Random Lighting Controllers each randomly turning 20 bulbs on and off in my structures.  

I have a 14 block signal system using a MEGA and a UNO controlling two signalized crossings.  I use the NANOs to drive emergency lighting on seven HO vehicles.  The NANOs work great for driving automation.

I was 79 years old when I bought my first Arduino and now at 84 years old I have 14 operating Arduinos on my layout and another one on the diorama I’m working on.

The Arduino is a blast, the limiting factor is your imagination.


Mel


 
My Model Railroad   
http://melvineperry.blogspot.com/
 
Bakersfield, California
 
Turned 84 in July, aging is definitely not for wimps.

  • Member since
    February 2018
  • From: Flyover Country
  • 5,557 posts
Posted by York1 on Monday, January 10, 2022 11:23 AM

Enzoamps
OK, the guy in the video York linked seemed basic enough.  I learned you have to use a computer to program it, and it has a USB for power and program.  I worked in digital for many years, but not in coding.  I did study FORTRAN about 60 years ago, but a C program looks like when my cat walks on my keyboard. It looks like you need some familiarity with its programming language.

I encourage you to take the plunge.

I knew nothing of programming before I started.  It took me several months to be able to write simple working programs.  I did try copying some things, but it wasn't as easy or satisfying as it sounds.

I also switched to using Nanos instead of Unos.  I bought five Nanos for $12.00.  They need a smaller USB cord to connect to a computer to program them.

I also don't use the computer to power them.  I soldered wires to the Nano chips and ran them to my 12 volt power supply.  The chip actually runs on 5 volts (I believe), so you could use a 5 volt power supply to run the chips.  The computer and USB cord were used only to program the chip.

I'm 70, and it was one of my more satisfying projects.

My first project was running the flashing rail crossing signals at my road crossings.  The only thing I regret is that I used photo cells instead of infrared sensors.  The crossing signals work great in the room light.  When the room lights get dimmed or turned out, the crossing signals turn on!

 

I started by buying a starter's kit.  It is not Arduino, which I found expensive, but Elegoo is the same set, but much less costly.

Have fun!

York1 John       

  • Member since
    September 2002
  • 7,486 posts
Posted by ndbprr on Monday, January 10, 2022 11:50 AM

So basically we are captive to computer building, programing and coding to run trains in circles for FUN!!  Looks to me like there will soon be an article in one of the magazines or you tube, " How I Installed a mainframe liquid cooled computer with 50 different add on to run my branchline engine and three cars on my two foot branch line"  the worst part is it will get rave reviews. I want to run trains not invest in the electronics hobby.

  • Member since
    August 2020
  • 84 posts
Posted by MrMe on Monday, January 10, 2022 2:24 PM

ndbprr

So basically we are captive to computer building, programing and coding to run trains in circles for FUN!! 

No, I don't think that's the case at all.

Some folks will always push the envelope, and that's generally a good thing. It's how new ideas come into being, followed by new products and so forth.

But you don't HAVE to be on the bleeding edge if you don't want to. My layout works just fine without any Arduinos. I actually have one sitting around, unused, that I needed once for a non-MRR task. But I have no desire to use it for the layout.  

ndbprr

How I Installed a mainframe liquid cooled computer

That's funny, because I once had the opportunity to acquire a "free" IBM System/370 Model 158 from my then-employer. I just had to pay for disassembly, crating, moving, and re-assembly. And all the environmentals. And it would have filled the basement so no room for a layout anyway. They ended up scrapping it on-site because those moving costs were more than it was worth. But just think, I could have run Linux under VM and had a really cool JMRI setup! Computer

  • Member since
    January 2009
  • From: Bakersfield, CA 93308
  • 6,526 posts
Posted by RR_Mel on Monday, January 10, 2022 2:52 PM

ndbprr

So basically we are captive to computer building, programing and coding to run trains in circles for FUN!!  Looks to me like there will soon be an article in one of the magazines or you tube, " How I Installed a mainframe liquid cooled computer with 50 different add on to run my branchline engine and three cars on my two foot branch line"  the worst part is it will get rave reviews. I want to run trains not invest in the electronics hobby.

 

I totally agree with you, while I do use the Arduinos for controlling accessories none have anything to do with train operations.  I will never use a computer to operate my layout, for me that would take all the fun out of running my model railroad.

The Arduino Random Lighting Controllers add realism to structure lighting, the random on off of the lights makes my houses look lived in.

The Arduino controlling my signals simply operate the track side signals from train position.

I programmed a NANO to randomly flash the emergency lights on my HO Police, Fire and Road Maintenance vehicles.  Non synchronized independent flashing lights really look sharp.
 
Mel


 
My Model Railroad   
http://melvineperry.blogspot.com/
 
Bakersfield, California
 
Turned 84 in July, aging is definitely not for wimps.

  • Member since
    July 2018
  • 661 posts
Posted by IDRick on Monday, January 10, 2022 3:51 PM

Enzoamps, I tried to send you a message but the forum software is not working correctly.  Search for "Geoff Bunza" and "campfire circuit" in google and you'll see one method of achieving flickering light.  Actually several interesting alternatives mentioned.

  • Member since
    August 2003
  • From: Midtown Sacramento
  • 3,340 posts
Posted by Jetrock on Monday, January 10, 2022 5:39 PM

I think the analog-electronics method used to create a flickering light (for a campfire rather than a fusee) was to wire the bulb to the audio output from an AM radio; fluctuations in the radio signal (especially if tuned to a radio channel) would make the light vary and flicker; I think there's an article about it in one of the Kalmbach books about adding animation and lighting to your layout. Of course it isn't necessary to learn programming to add a light to your layout, but for folks who already know how to do things with Arduinos, it's easy enough to add another one.

  • Member since
    March 2021
  • From: Vermont
  • 135 posts
Posted by Ablebakercharlie on Monday, January 10, 2022 6:22 PM

Jetrock
I think the analog-electronics method used to create a flickering light (for a campfire rather than a fusee) was to wire the bulb to the audio output from an AM radio; fluctuations in the radio signal (especially if tuned to a radio channel) would make the light vary and flicker;

This technique is mentioned in the book "A beginner's guide to creative effects for your model railroad" by Paul Newitt

  • Member since
    August 2003
  • From: Collinwood, Ohio, USA
  • 16,367 posts
Posted by gmpullman on Monday, January 10, 2022 6:38 PM

I bought a whole shoebox full of arduino stuff a couple years ago. Still sitting in the box... someday.

I wanted a fusee to protect a "hill holder" pin that I installed on a grade where I have to hold cars while the engines make some set-outs. I used a Hump Yard lever connected to a little bracket I made plus added a microswitch to activate the fusee "protection".

 car_stop1 by Edmund, on Flickr

I found a tiny length of red wire insulation and added the smallest red SMD LED to it:

 car_stop3 by Edmund, on Flickr

Logic Rail makes a board that is called the Fusee Simulator which is ideal for this use. You can set a few jumpers for duration, etc. I have mine set to run, IIRC, 20 seconds after the circuit is cleared. As the fusee "times out" it realistically sputters out before completely extinguishing. The board seems to have been redesigned (and price increased) since I bought mine.

No fuss, no muss. I'm all for learning new technology. I can program a decoder or set up wi-fi throttles with the best of 'em. But learning 3D cad for solid modeling or the arduino C++ sketch stuff, well, I may die of old age before I ever scratch that itch.

Good Luck, Ed

  • Member since
    July 2018
  • 661 posts
Posted by IDRick on Monday, January 10, 2022 9:11 PM

Nice solution, Ed!  Looks awesome and easy to do!

 

  • Member since
    December 2004
  • From: Pa.
  • 3,361 posts
Posted by DigitalGriffin on Friday, January 21, 2022 11:08 AM

The Arduino Development Environment is quite easy to use.  I taught several classes in it.  It does support C++, but most of the programming is "C" like in nature. (C does tend to be more compact in nature when compiled, and that is vital for Arduinos)

Basically there's a run loop and goes constantly.  As soon as the instructions are done executing, then go back to the beginning and start executing again at the top.  So what you would do is return a random value, and change the output pin (PWM) based on that random value (25->100%)   The current itself DOES NOT ALTER. But the time the LED spends on to off varies, and the process is so quick, your eyes cannot see it.   We are talking thousands of on off pulses a second.  So it looks like a continous light.

Don - Specializing in layout DC->DCC conversions

Modeling C&O transition era and steel industries There's Nothing Like Big Steam!

  • Member since
    December 2004
  • From: Pa.
  • 3,361 posts
Posted by DigitalGriffin on Friday, January 21, 2022 11:12 AM

Ed, write me, I can do a short zoom video and teach you.  It's not that hard.  I taught over 100 people how to program these boards years ago.  

Don - Specializing in layout DC->DCC conversions

Modeling C&O transition era and steel industries There's Nothing Like Big Steam!

  • Member since
    September 2003
  • 21,669 posts
Posted by Overmod on Saturday, January 22, 2022 11:15 AM

Don, you might contact Kalmbach and make arrangements with them to put the videos on the trains.com service.  There is precious little cutting-edge electronics apparently covered there now.

  • Member since
    December 2004
  • From: Pa.
  • 3,361 posts
Posted by DigitalGriffin on Saturday, January 22, 2022 1:16 PM

Ndbprr,

It depends on how you look at it.  To me using latches and 555 timer chips and servo spi chips is a lot more complicated than handling it in code.

The advantage is small modifications to the code are a lot easier than modifying physical components on a circuit.  For example, you use a servo to control a gate or semaphore.  You could hard code a spi controller.  But adjusting it would be a nightmare.   With Arduino it's a 1 number modification (the amount of movement required by servo). That is a 2 minute fix.

Don - Specializing in layout DC->DCC conversions

Modeling C&O transition era and steel industries There's Nothing Like Big Steam!

  • Member since
    January 2010
  • 170 posts
Posted by nycmodel on Saturday, January 22, 2022 3:29 PM

The whole idea with this software is to do in code what you would do with soldered components. Much easier to setup and correct. That's why I used an Arduino to automate my 2 grade crossings. Model Railroader used to have an Electronics Symposium. Maybe an Arduino Symposium would be a good addition.

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!