Skip to main content

I see that the Arduino can be used to control lighting, motors, and sound.  I am not familiar enough with this item to know if it is usable for an electrically ignorant individual on a model train layout.  Anyone know of protocols or programing that can be used to control lighting, motors and sound on a model train layout or how the information can be found?

Original Post

Replies sorted oldest to newest

What cant you do with Arduino?

 

These little programmable boards are being used to control robots. That means attaching a motor driver board (a.k.a. a "shield") and driving motors, lights, sounds, sensors, you name it. They can be controlled through RF, bluetooth, wifi, or programmed to operate autonomously. Absolutely no reason why any of that could not work with model train.

You can spend months sifting through all the Arduino projects and stuff on the internet but as far as I know, no one has applied any of this to O gauge trains.

That means you would have to do all the research, hardware assembly, and coding yourself.

 

And while your at it, research the Raspberry Pi. Its a full-fledged computer that is about the size of a credit card, with its own operating system. It has video and audio outputs and you can even attach a camera to it. It has programmable pin-outs for LEDs and PWM for motors (with appropriate motor driver board attachment). Using wifi and remote desktop software, the Pi can be controlled by any other computer or tablet through a network connection.

Again, lots of documentation out there. You will have to be the one to learn it an apply it to your application.

 

I just bought an Arduino robot and a Raspberry Pi for my daughter for her birthday. We will be learning all this stuff together.

I've used the Arduino as the centerpiece of a complete automated control system;  the Arduino reads insulated third rail sensors and RFID readers, controls layout signals, accesories and turnouts, sends commands with the DCS and Legacy command bases, and interfaces with JMRI running on a PC to provide a touch-screen layout interface.

 

There aren't any out-of-the-box applications for the electrically ignorant… but I was completely electrically ignorant before I started!  Nearly everything I've learned about electronics has been through these projects.  I started with a very system using a Basic Stamp and a loop on the living room floor, and worked up to the installation I have today. 

Mike, you might begin with one of the Arduino starter kits.  I haven't used one, but a lot of companies make them (including the 'official' starter kit).  Start with simple experiments like rigging a pushbutton to light an LED.

 

Outside of those, the building blocks are basic digital electronics and basic C++ programming.  I don't know of a good intro to digital electronics, but the Arduino website has a reference page documenting most of the C++ and Arduino extensions you use in programming.  There are lots of C++ resources on the web, but most of it is oriented towards computers and may not be as helpful for Arduino.

 

In my case, one of the first things I did was hook up the Arduino to the TMCC command base, which required me to learn about serial interfaces and converting voltages from what microcontrollers output to what RS-232 devices expect.  Then I wrote some programs to control simple locomotive functions like a horn from the Arduino.

If you're interested in interfacing the Arduino to TMCC/Legacy, consider an Arduino Mega.

The Mega has 4 hardware serial ports, meaning you can dedicate one to talking to a serial device like the Command Base while one or more are connected to your computer.  If you are using a regular Arduino you may have to use a software serial port which is more complex and limiting.

Last edited by Professor Chaos
Originally Posted by Mike Bagaason:

Professor,

 

Thanks.  I will talk to my local electronic shop about the starter kit and will work on lighting first.  Then the mega stuff.

I am diving in as soon as possible.

There is small book by one of the Arduino founders (Massimo Banzi) that does a real good job of explaining the Arduino in simple layman's terms. Very easy read and easy to understand. It's titled "Getting Started with Arduino". I think I got mine at Radio Shack. I think for someone new to all this it would almost be a recommended read. That might be a good thing to start with and then go to one of the kits.

 

Make sure the kit has a manual also. I got the SparkFun Inventor's Kit for Arduino last winter to get going. They had a special sale and it was 60% off and free shiping. The sale is what pushed me over the edge to get started. The kit I got has a good manual with plenty of illustrations and lots of parts and example experiments. It includes everything you need to get started. Pre-written code is available for all the experiments as well as other tutorials and information on their website. This could be the case with other kits from other sites as well, haven't really looked at many of those?

 

Professor Chaos and the others are much more advanced than I am, I'm only just past the getting started point. It is very interesting and a lot of fun though!

 

 

I have utilized the Arduino for several projects on my layout. I picked the Arduino for

several reasons. The Arduino is open-source which means that the hardware is reasonably priced ($12 - $15 on ebay direct from China with free shipping) and development software is free. I receive them in about 7 days. Some include a USB cable for programming. Once programmed the program is retained even when power is removed. The Arduino has 14 digital input/output pins. Plugin interface boards (called shields) are available. I have used two different shields so far. One of these shields contains relays that can handle AC power for trains. Another shield contains a 9 X 14 LED array.

 

I use the Arduino + relay shield to control a Marx elevated train. It stops the train at

the station and leaves it in neutral and the train makes station anouncements. It then

cycles it into reverse for a very short burst and then into neutral where it pauses

until the train sounds the horn. It then cycles into forward and leaves the station.

After a delay the cycle is then repeated.

 

Another use is to blink three red lights on top of a bridge. The previous electronic

circuits had a tendency to get into sync and I wanted them to be randum. I programmed the Arduino to flash three outputs at slightly different rates.

 

The Arduino + LED array is mounted in an old Revel Blimp Kit and makes a digital

display. This will be hung from the ceiling and fly over the layout. The display is

programmed with scrolling messages. The program to make the LED matrix scroll messages is available on the internet so all I had to do was type in my message.

Mike,

 

Another great source of info for the Arduino is a book titled "Arduino Cookbook".  Is is pretty hefty and is full of example applications with the associated code.  The coding is fairly easy to learn given all the examples of how to do a specific things in the book.  As someone mentioned previously there are lots of free programs available on the internet.

I'd be really surprised if there aren't some train related projects already on the net.

 

There is just a ton of stuff that you can use the arduino for on a train layout.  

I bought an Arduino 2 years ago to fool with while I was recovering from some surgery.  It was great fun learning it, especially for led lighting, relays and photo sensors.  The parts are generally quite cheap.  Some of the shields can get up to $30 or $40.  ( and that is old info).  One of the really neat shields provides wireless capability..  

 

Ed

For those of you who are paying attention to this item:  There is another device called the Raspberry Pi which does the same type of thing.  It too has tutorials and programing to learn. 

I have picked up an Arduino beginners kit and have started the led lighting tutorial.  This will come in handy for lighting on the layout.

I have a lot of great ideas where I can use a programmable controller on the Choo Choo Barn layout but a have a few concerns.  First is reliability.  My display operates 7 hours a day, 7 days a week for 9 months. Will an Arduino hold up under this pressure? What happens when there's a brown-out or a total power failure while it is operating? One of my ideas incorporates stepper motors, servos and MPEGs for sounds. Will an Arduino with add ons handle such a thing? I need a contoller that will run a series of commands, working the motors, servos and sounds and then rest for a while and start all over again.

I fear that my brain is getting too old to learn how to write code but I imagine that once I've done one sequence of events, I can use this is a building block for many more exciting animated scenes. I can build the hardware, the animated parts, but I'm no a coder.

Anybody out there willing to tutor me?

YES...YES...YES...

 

There is no reason that the Arduino can't run continuously for long periods of time.  You can either use a UPS for brownouts or do an external watchdog reset. 

 

There are stepper motor boards that are very cheap for the Arduino, and it has a number of PWM outputs that you can control RC servos directly with, very handy.  MP3 sound would be an add-on, they also exist, though I haven't actually fooled with them.

Originally Posted by Choo Choo Barn:

Hey gunrunnerjohn, was the third YES in answer to my "tutoring" question? I've bought the "Dummies" books but they didn't have in them what I wanted, too general.

I think if you select a project, and do some code that you think is in the right direction,  then post it, then I'm pretty sure that folks will be unable to resist redirecting you.

Makes it interesting to all.

Professor Chaos, you are my hero ;-)  I have used relays and isolated tracks to automatically control multiple trains on a loop with sidings via conventional control, but now I want to do this with Legacy.  I think the solution will be to eventually use 10 or 12 RFID sensors (though just one to get started) as well as simple isolated-rail occupancy detection to keep track of the locations of specific locomotives.  What you have done is more than I aspire to, and I don't really want to use JMRI.  But you have already done everything I need to learn.
 
I think a few tips from you can save me a lot of pain, and hopefully prevent me from getting too far down the road before realizing there might have been a simpler approach.  So here are a few questions that I would appreciate comments from you or anyone else who has experience with Arduinos, RFID, and serial communications with 3-rail trains:
 
* The Arduino Cookbook shows how to connect a single RFID reader to an Arduino - directly, using the main I/O port.  You suggest the Mega which supports four serial ports (and I will certainly need to connect more than one RFID reader eventually, for full layout control.)  So does this mean that I will need 3 Megas if I want to monitor 10 or 12 RFID readers (at the entrance to any siding/turnout, I would think)?  And have them coordinate by talking to each other?  Or is there a better way to monitor that many scanners with just a single Arduino?  How many RFID readers are you connecting?
 
* There is an Arduino RFID shield available - but I'm not really clear why that is necessary if you can connect an RFID reader directly to a serial port?  How are you connecting yours?
 
* Can you please tell me which RFID readers and tags you are using, and where you are locating them?  I.e. under track, adjacent to track...  Bottom of locomotives...???
 
* I have Googled your comments on other boards trying to glean as much as I could from what you have already posted.  Here is one that scared me:
"The sensor interfaces are a simple optocoupler/RC long-period debounce/Schmitt trigger/shift register circuit that I developed on my own."  If you're talking about simple isolated-outside-rail train detection, I guess I had the idea that the ground signal could simply be connected to an Arduino input...silly me ;-)  Can you point me in the right direction in terms of what hardware is needed for simple isolated-rail train detection?  I.e. "A set of wheels is currently grounding the rail at location X" and I'm assuming there will be even more of these needed than RFID scanners.
 
* Your comment, below, about converting voltages so the serial output of an Arduino can communicate with a Legacy base...is also just beyond my reach.  Can you please point me in the right direction?  I agree, a great first project will be to simply try to get an Arduino to tell a loco to blow it's horn - via the Legacy base connected via serial cable.  Sort of a "hello world" ;-)
 
Thanks so much for your time!
 
Randy Peck
 
Originally Posted by Professor Chaos:
In my case, one of the first things I did was hook up the Arduino to the TMCC command base, which required me to learn about serial interfaces and converting voltages from what microcontrollers output to what RS-232 devices expect.  Then I wrote some programs to control simple locomotive functions like a horn from the Arduino.
If you're interested in interfacing the Arduino to TMCC/Legacy, consider an Arduino Mega.
The Mega has 4 hardware serial ports, meaning you can dedicate one to talking to a serial device like the Command Base while one or more are connected to your computer.  If you are using a regular Arduino you may have to use a software serial port which is more complex and limiting.

Hi Randy - let's see if I can answer some of your questions!

 

Easy things first:  Check this article about serial voltages. The output from the Arduino serial pins is 5V TTL;  you need to invert and regulate the voltage when communicating with an RS-232 device like a computer or the Legacy base.  A basic MAX232 circuit does this as shown in the Sparkfun tutorial.

 

I have two RFID readers hooked up, though you really only need one.  The RFID reader identifies the train when it first enters the mainline, and it is subsequently tracked by occupancy sensors.  I use the ID-20 reader available from Sparkfun;  each one is connected directly to a serial port of the Mega.  Note that you can attach different input and output devices to the same serial port if at the same baud.  For example, I have one serial port where the input reads an RFID reader and the output sends commands to the Legacy base.  But for 10-12 readers you would need some sort of multiplexing scheme.

 

I put the RFID readers in a trackside structure, or behind a billboard, as shown in the photos. RFID tags are stuck inside of a plastic tender, or the shell of a diesel. Steam locomotives with die-cast tenders have a particular piece of rolling stock associated with them to identify them to the system.

 

Under the track / under a locomotive doesn't work well because of all the metal around - not to mention the difficulty of burying the reader.

 

 

 

 

Attachments

Images (2)
  • rfid_1
  • rfid

Thanks Professor.  So are you saying that you only use a single RFID reader on your entire layout - and always start your trains running from a specific set of known locations?  And from that point on, since "you" (your Arduino or whatever, as programmed by you) are throwing all of the switches...you basically just need isolated rail triggers to know when that train has reached a given point on the layout.  I.e. since you know that Train 1 was at point A (where the RFID reader is located), then that must still be Train 1 at point X -- since *something* is there and based on your control programming, it couldn't be anything other than Train 1?

I must be missing something, because if that was the case -- a known starting configuration -- then you wouldn't even need a single RFID reader...you could just keep track of train movements based on assumptions...???

That can't be right ;-)  So how are you keeping track of so many locomotives on your layout all running around at once, without having a bunch of RFID readers?  With conventional control, it was easy to just turn the center rail power off and on...but now we need to know *which* loco is at any given point so we know which serial command to send to tell it to stop and start.  I was just ASSuming that you were using multiple RFID readers.

For sensing occupancy, I didn't want to connect the third rail directly to the Arduino.  In part, because for TMCC you can't connect the earth ground (which is what the Legacy base is using for serial communication) to the outside rail common.  There may be a way around this, but I had already developed a circuit to convert a noisy AC signal into a clean 5V input.

 

The basic sensor circuit is shown below, though I have altered some of the resistor values from the diagram.  The signal from the track goes through an AC optocoupler, and then the 'debouncing' circuit uses a resistor/capacitor to smooth the signal.  A Schmitt trigger then ensures the input sees a clean transition.  Same arrangement you would see if you looked up switch debouncing circuits, but much longer debounce time than for a typical switch.

 

It might be possible to handle all that debouncing entirely in software, but when I started I was using a microcontroller with very limited memory and power, so I wanted to do as much in hardware as possible.

 

I designed a circuit board to consolidate all the occupancy signals into a single stream of pulses that can be read by the Arduino's SPI interface.  All it does is feed the outputs of the Schmitt triggers into four shift registers which are daisy chained together.  Same idea if you look for examples of how to expand Arduino inputs with shift registers.  So in the end, the Arduino just loads in four bytes over the SPI interface, which represent the states of 32 occupancy sensors.

 

Hope that is helpful!  

Attachments

Images (3)
  • single
  • acsensor
  • sensor board in place
Originally Posted by Randy P.:

Thanks Professor.  So are you saying that you only use a single RFID reader on your entire layout - and always start your trains running from a specific set of known locations?  And from that point on, since "you" (your Arduino or whatever, as programmed by you) are throwing all of the switches...you basically just need isolated rail triggers to know when that train has reached a given point on the layout.  I.e. since you know that Train 1 was at point A (where the RFID reader is located), then that must still be Train 1 at point X -- since *something* is there and based on your control programming, it couldn't be anything other than Train 1?

I must be missing something, because if that was the case -- a known starting configuration -- then you wouldn't even need a single RFID reader...you could just keep track of train movements based on assumptions...???

That can't be right ;-)  So how are you keeping track of so many locomotives on your layout all running around at once, without having a bunch of RFID readers?  With conventional control, it was easy to just turn the center rail power off and on...but now we need to know *which* loco is at any given point so we know which serial command to send to tell it to stop and start.  I was just ASSuming that you were using multiple RFID readers.

 

You have the basic idea!  On my system, a train must 'enter' the layout at a defined point - where one of the RFID readers is.  Once it passes the RFID reader, the system tracks it by occupancy.  Trains are assumed to only go forward;  since I designed the system primarily for automatic running this is not a major limitation.

 

The way I have things set up, it is not actually necessary for a train to start on a siding.  Layout blocks only become 'active' once an automatically controlled train enters them.  So, I can stack a few trains behind each other on the mainline, and have them pass by the RFID reader (thereby 'entering' the system) one by one.

 

Of course, one has to make sure the trains that have already entered the layout don't progress into the inactive blocks before they're vacated!

 

 

For conventional control, RFID would not be necessary.  I am controlling the trains with TMCC and DCS, so the system has to know the ID# of the locomotive to issue the proper commands.  Hence each locomotive has one or more tags associated with it, either attached to the locomotive itself, or to a particular piece of rolling stock associated with that locomotive.

Last edited by Professor Chaos

Very interesting, and it certainly gives me food for thought.  That sounds much simpler than populating the layout with RFID sensors.

 

In lieu of grounding an insulated rail section to trigger occupancy, I might look at one of the commercial IR sensors out there.  They will close a relay and stay latched anywhere from .5 to 3 seconds after proximity is no longer detected - so no bounce.  Or use an insulated rail section to close a relay, and figure out a way to keep it from chattering...  I presume any of these relays could be set up to deliver the appropriate high or low signal to any of the Arduinos many digital inputs.

 

If anyone else has done this, I would love to hear about it.

 

Thanks Professor!

 

Randy

Dale, that may be the best approach for me.  Originally (because I am controlling with Legacy and not conventionally) I thought I would need to use a system that would identify *which* loco was at each location, hence my idea of having RFID readers all over the layout.  Now that Prof. Chaos has explained that this can be done with programming, as long as you know the starting point of each loco...then any sort of occupancy detection should work.  I only need a single RFID reader, for each train to pass by (in a known direction) in order to be initialized into the system.
 
A relay and capacitor (triggered by an insulated rail section) sounds like an inexpensive and simple means of toggling the binary occupancy input to an Arduino.  Ideally, I'd like that relay to remain closed long enough to ensure there is no "chatter" as the wheels pass over the rail.  I'll need to figure out what value of capacitor would be appropriate.  Any chance you know enough electronics to suggest a starting point?  I'm guessing that a high enough value to hold the points closed for a second or so would also require a capacitor "charge time" which would delay the contacts closing initially?  I want a delay in releasing but not the up-front delay ;-)
 
In the past, when doing this with conventional control, I have used DPDT 12vdc relays from Radio Shack like this:
 
 
I added a bridge rectifier, and latched the contacts closed as soon as it was tripped, and it was later automatically released.  But in this case I'd rather not latch it because there may not be a simple way to unlatch it -- and if a capacitor can hold it closed to provide a delay so that it stays closed until the last set of wheels has passed by...that would be terrific.
 
And as long as I have your attention, is there anything special I need to do other than run +3v (+5v?) or ground (as the case may be) directly through the relay contacts and into the Arduino I/O pin?  I'm thinking I may need a pull-up or pull-down resistor -- something I know nothing about but if I know I need it, then I can figure it out.  Lots of good tutorials on YouTube.
 
I love Prof. Chaos's idea of setting up 32 bits at a time and sending that as four serial bytes to the Arduino -- way better than dedicating a pin to every sensor.  But the hardware is way over my head, even after looking at the schematic he thoughtfully posted in this thread.  Maybe I could build one if I knew the part numbers...???  But as the Professor says, a step at a time, each building on the last.
 
Your thoughts and suggestions are most appreciated.  Thanks!
 
Randy
 
Originally Posted by Dale H:

If it is 3 rail,I am just curious why you dont use a relay and an insulated rail. The relay contacts are open or closed,easy to adapt for binary logic. A capacitor across the coil would eliminate "bounce".  Not a criticism just a question.

 

Dale H

 

Professor (or anyone), can you please clarify this statement: "For TMCC, you can't connect the earth ground (which is what the Legacy base is using for serial communication) to the outside rail common."
 
Is that because the outside rails when using TMCC/Legacy are also acting as antennas, and somehow that will interfere with an Arduino seeing one of its pins go from high to low if directly connected?  I accept your statement, of course, but I'd like to understand why.
 
Also, I can't believe the effort it must have taken to design your interface board, and have the circuit board manufactured...when you suggest "I was completely electrically ignorant before I started!"  Wow you have been a busy guy!  Have you considered selling those boards...I have an idea there may be some guys on this board (like me!) who could be interested... ;-)
 
Originally Posted by Professor Chaos:

For sensing occupancy, I didn't want to connect the third rail directly to the Arduino.  In part, because for TMCC you can't connect the earth ground (which is what the Legacy base is using for serial communication) to the outside rail common.

Sorry Professor, but I have another question.  I've just spent a couple of hours agog (yes, agog!) watching your three YouTube videos (ProfessorCha0Z) and comparing them to your track layout (posted in this thread: https://ogrforum.com/t...ly=12129987923999864)  The more I watch it, the more amazed I become -- this is not some trivial "follow the train ahead without hitting it" as I have done with relay logic.
 
Can you give me a hint as to how your algorithm is set up?  I presume you have an array or perhaps a linked list that stores occupancy data (vacant, or occupied by which loco and going in which direction.)  And perhaps a table containing routes from any given block...???
 
Do you just establish a starting configuration by running the trains past an RFID reader, and then let 'em loose to do random paths so long as they avoid collision, or does each train have its own route that it wants to take and your logic provides for that while preventing collisions?  When approaching a turnout when both routes are unoccupied, how does your code decide where to send a train?  Is it a random choice?  I just don't see any repetition in your videos -- it is absolutely amazing, especially when trains are heading towards each other and there are three of them to keep track of!
 
I'm assuming this is all handled in your custom Arduino code as you don't mention JMRI in your YouTube descriptions.  However it does look like JMRI might be able to handle something like this -- I did find information on Warrants here which seems as if it might be similar to what you are doing: http://jmri.sourceforge.net/he.../logix/Warrant.shtml
 
Thank you so much for sharing your knowledge, and for posting those videos - they are a joy to watch.
 
Randy
 
Originally Posted by Professor Chaos:

I've used the Arduino as the centerpiece of a complete automated control system;  the Arduino reads insulated third rail sensors and RFID readers, controls layout signals, accesories and turnouts, sends commands with the DCS and Legacy command bases, and interfaces with JMRI running on a PC to provide a touch-screen layout interface.

 

There aren't any out-of-the-box applications for the electrically ignorant… but I was completely electrically ignorant before I started!  Nearly everything I've learned about electronics has been through these projects.  I started with a very system using a Basic Stamp and a loop on the living room floor, and worked up to the installation I have today. 

 

That's very clever and interesting, Dale -- thanks for sharing.  (Also, Mr. Webmaster, when reading Dale's earlier post, I learned how to embed a link in a description, so I won't paste raw links again!)

 

I love the way you have set up delays for the long-long-short-long horn blast -- so creative!

 

Years ago I had a conventional layout that used similar relay logic as you are using for your SuperStreets -- basically it kept multiple motorized units running on a single loop without slamming into each other, much as you have done.  It worked, but was pretty herky-jerky.

 

I also designed a relay circuit that allowed four trains on a large loop with two sidings.  Two trains would sit in opposite sidings, while the other two trains could circle around until they entered the siding that their counterpart had just vacated.  Then they stopped, and the two trains that had been sitting would do the same thing -- in the opposite direction just for fun.  So four trains, with two running at any given time.  Each of the two sidings required five relays and several insulated rail sections, and I connected them together so no train would be released until all trains were in sidings.  So ten relays total, and theoretically I could have added any number of additional sidings for two more trains at a cost of five relays each.  It was a lot of fun and worked flawlessly.

 

But when I look at what Prof. Chaos has accomplished, it is in a completely new realm.  Trains taking seemingly random paths, often (but not always) running in opposite directions, three trains at once, and never colliding or getting into a standoff with an opposing train.  As much as I love everything electromechanical (I also collect antique pinball machines) and postwar, I am fascinated and enamored with microcontrollers and software.  TMCC may be technically outdated, but I love the relative simplicity.  It does everything I could want, and I can get my head around it -- so I'm excited to dive in.

 

Thanks for sharing the information, and for your thoughts.

 

Randy

Originally Posted by Dale H:

If it is 3 rail,I am just curious why you dont use a relay and an insulated rail. The relay contacts are open or closed,easy to adapt for binary logic. A capacitor across the coil would eliminate "bounce".  Not a criticism just a question.

 

Dale H

Relays would work, but wouldn't you still need some debouncing of the output for digital processing - don't the relay contacts bounce like switch contacts?

 

So on the input side it seems like the choice is between 32 relays, + 32 rectifiers + 32 capacitors to dechatter, vs. 8 quad optocoupler ICs + 4  SIP resistor arrays to limit current. The latter is more compact and easy to assemble (once you're making PCBs).

 

The Dark Side is strong, Dale… embrace the power of the Solid State.  

Last edited by Professor Chaos

Randy, believe it or not it wasn't that difficult… I started small with a two-sensor system running on a Basic Stamp on the living room floor and worked up from there.  There are lots of resources for learning digital electronics, and it was mostly a matter of adapting and combining bits and pieces I found here and there.

 

For designing the boards, I used a program called DipTrace, and generated Gerber files that you can send to a board house to be fabricated.  It was a lot of fun! I'm not going to embark on the board-selling business, but I have put the Diptrace files and the Gerber files in my Dropbox public folder if you want to take a look:  try this link and look in the AC sensor folder.

 

You will also find my Arduino code ("TrainControl") there.  (You will need to install the libraries in the libraries.zip file). Unfortunately the system has grown very complicated so it is probably hard to understand;  it has manual and automatic train running, control of layout signals via two different circuit interfaces, TMCC and DCS interfaces, monitoring of layout switch and accessory status, stored data for my layout configuration and locomotive collection; a JMRI interface, and now even a wireless remote control for my gantry crane.

 

It started out as just automatic train routing… depending on the operating mode, trains always seek the most permissive path, or follow the current turnout path unless it is a red signal.  There is also a 'reservations' system where trains are assigned a priority, and higher-priority trains can grab a block ahead of the current path unless another train absolutely needs it.  The idea was to make freight trains sit and wait for a passenger train (contrary to current Amtrak practice!).  A train can also be designated manual control, in which case the system will attempt to route automatic trains around an operator-controlled train.  The automatic logic is a complicated mess and I am not sure I even understand it any more!

 

I use JMRI to provide a touch-screen interface to the system, but all the logic is handled by the Arduino.  The JMRI interface is one of the more complicated parts of the system.  I emulate the C/MRI protocol to pass data back and forth between the Arduino and JMRI, and have some scripts running on JMRI to generate TMCC commands that are passed to the Arduino for transmission to the Legacy base. There is a screenshot of the JMRI panel in the Dropbox folder.

 

 

The issue with not connecting earth ground to outside rail has to do with how the TMCC signal is generated.  Dale Manquen is the expert on this, but as I understand it earth ground and the outside rail are the two halves of the antenna for transmitting commands to locomotives.  Connect them and you will short the TMCC signal.

 

So I wanted the system (which needs an earth ground reference for serial communication with the TMCC base) electrically isolated from the layout.  Also isolated from spikes and whatnot that might occur during derailments or from solenoid-powered accessories, which might not be appreciated by the digital electronics.

Last edited by Professor Chaos
Originally Posted by Dale H:

Not really. but I am not sure since I do not have the Arduino and its requirements. Again logic controllers can be programmed to ignore this bounce as you call it..  Relays, unlike solid state electronics take a bit of time to throw,they are not instantaneous. With the capacitor they do not really bounce,or should not at least. AC relays are also wound not to bounce. 

Dale, almost any relay will have contact bounce.  It won't be apparent in the electromechanical way you use them, but it sure will as input to a microprocessor that can process discrete input states in a microsecond or two.  Debouncing is a fact of life when you program a microprocessor.

 

As you say, the canned logic controllers have that built-in, but we're talking about programming something that costs $8-10 to do the task, not something that costs hundreds of dollars.

 

Your modesty is admirable, Professor ;-)  Thank you SO MUCH for answering all of my questions, and for your generosity in sharing your code and circuits.  Especially the code!  This is so much fun, and I haven't even ordered any hardware yet ;-)  Until I really studied your YouTube videos, it would never have occurred to me that something so complex was viable.  But your thoughts of starting with small steps and working up are well taken, and I will be very excited the first time I'm able to get a TMCC horn to blow via a command from an Arduino.  "A journey of 1000 miles begins with a single step."  And even more apropos, "Getting there is half the fun!"
 
Thanks again for all your help and generosity.
 
Randy
 
Originally Posted by Professor Chaos:

Randy, believe it or not it wasn't that difficult…

Originally Posted by Dale H:

John

 

My understanding is that the contacts and blades are formed in a slight arc. Some relays are different. When it makes contact,there is actually a slight wiping action, so no bounce really occurs. This maintains constant contact as long as the input voltage is there. Second there is a throw in voltage and drop out voltage. This is usually designed for a smooth operation to prolong contact and blade life. Relays would not last so long if they bounced.

Dale, trust me, virtually all relays have a period of uncertainty of the contact.  You are free not to believe it, but I've interfaced many micro's to relay circuits, and debouncing was ALWAYS required.

 

Add Reply

Post
×
×
×
×
Link copied to your clipboard.
×
×