Skip to main content

Out of curiosity, has anyone here used and Arduino or other microprocessor projects for their O scale trains? I have had an Arduino for a bit of time, but have not really dove into the programming of it yet, but I am very interested in doing so. 

 

Just a thought of a simple learning project would be to take a few 0-27 passenger cars and a handful of RGB LED's and make a party train. The passenger car would be painted and lettered accordingly. Creating the filtered AC-DC and constant currant would not be an issue using a full wave bridge rectifier, filter cap and one of these guys

 

For those who are not familiar with what an arduino is, here is a link describing it. https://en.wikipedia.org/wiki/Arduino

 

NOTE FROM MODERATOR:  ebay link deleted...terms of service.

Last edited by OGR CEO-PUBLISHER
Original Post

Replies sorted oldest to newest

I have done a couple little things with the Arduino, but then I moved to the Microchip PIC processor.  My Super-Chuffer and my new sound board are PIC based.

 

The Arduino is great for beginners as they do a lot of the initialization stuff with their embedded code, so you just have to write the application.  Their programming language is pretty much ANSII C based.

 

  Originally Posted by zackesch:

Joe, 

 

Would it be safe to say you are using ac for the track, converting ac to dc and using an H bridge for motor control?  One of my thought experements was doing something like you are doing, but using the X-Bee instead of bluetooth. 

It is AC on the track but Pulse Width Modulated DC to the motor.  I have done a Bluetooth AC throttle (trackside) that will put pseudo-variable AC on the rails in 2 volt steps, but its too bulky for inside a loco.  There is a Picaxe circuit for an H bridge, but I just use a relay to reverse polarity to the motor.  Triacs for AC with Picaxe is difficult.

 

Feel free to ask me questions; I am not an EE, just self-taught in stuff.

 

Take care, Joe.

 

  P.S. Yes, I am converting the AC to DC with a bridge and filtering it with a large capacitor inside the ore car.  J.

Last edited by Joe Rampolla

There is a nice project for Arduino and model rail roads in the latest Nuts & Volts magazine. It senses train location with either photo resistors or photo transistors and activates a flashes crossing LEDs, reports train direction and when the train is past the crossing reports train speed to a 20 x 4 LCD screen.

 

I ordered all the parts, got them all and have it working with the photo resistors on a bread board. Next step is to try it on the layout. I got both photo resistors and transistors and plan to try both to see which works the best, if there is even any difference. It has been a fun project so far.

 

I also made some traffic lights with it, but got some MTH traffic lights for Christmas so I never used those on the layout. Have done a few other little things with it also, while trying to learn how it all worked. By no means do I have it mastered, but it's still fun to experiment with.

 

There are lots of projects available online for the Arduino. Example code, parts lists and just about all you need. Just have to customize it a little to suit your needs.

I have nothing against the Arduino.  I was comfortable with what I already knew in the BASIC programming language and I like that I could make up my own boards with just a chip socket for the Picaxe chip and not have that bulky Arduino stack of boards.  I think the code library for the Arduino  makes things, like string handling, so easy, but with the Picaxe, you have to write your own code or find something that has been published and tweak it.   

 

If I were young, I'd go with the Arduino.   (My age is showing!)

 

Thanks for the tip on the Nuts and Volts article!

 

 

Last edited by Joe Rampolla

It seems that the number of forum regulars who want to design and build their own R/C setup is growing steadily. Joe R. I enjoyed your description and video demo of your system. For fun, I also converted a K-Line speeder to work with my R/C control module which was mounted in a trailing car like yours. I agree that the PIC controller is best for our purpose because of size constraints. Also, it generates the PWM signal, but the so does Arduino . I've experimented with other forms of motor control, but have settled on PWM. Some things I have found useful for R/C operation are an automatic brake function between direction reversals and some kind of visual cue on the control car as to the amount of power being delivered to the loco. What kind of operating range did you obtain with your bluetooth setup and which bluetooth version are you using?

Originally Posted by Joe Rampolla:

I have nothing against the Arduino.  I was comfortable with what I already knew in the BASIC programming language and I like that I could make up my own boards with just a chip socket for the Picaxe chip and not have that bulky Arduino stack of boards.  I think the code library for the Arduino  makes things, like string handling, so easy, but with the Picaxe, you have to write your own code or find something that has been published and tweak it.   

 

If I were young, I'd go with the Arduino.   (My age is showing!)

 

Thanks for the tip on the Nuts and Volts article!

 

 

You are welcome. It's a neat little project.

 

I have had the PICAXE on my to-do list for sometime, but I got an Arduino kit for a steal, it jumped in front of the line and here I am. I used to program a little in Quick Basic and MS Pro Basic many years ago. Didn't keep up when Windows took off and they went to Visual Basic. You have re-kindled my interest and I think it's time to order some PICAXE stuff. I think the Arduino is supposed to be some kind of C, but it's not really all that much different than Basic. If you can still use Basic, I don't think you will have a problem with the Arduino.

Originally Posted by Calabrese94:

HAS anyone used Arduino for signals based applications ?

I think a couple of forum members have automated their layouts with Arduino, but I don't remember if they had done signals. Prof Chaos was one that I remember posting about layout control with Arduino. You may be able to search his posts looking for 'Arduino' and find some good information if it's still here. 

 

I am sure it is doable with Arduino, but for signals only Atlas has a pretty neat signal system that has already got everything you need built in to it. I have heard it was kind of like their track though, hard to find, but I have not checked for availability in a long while. If it is in short supply, I hope they get production going on it again soon. Ericstrains youtube channel has a two part series on the system that explains it well.

Last edited by rtr12

I've used the Arduino for  signaling and (and automatic layout control system).  You can cannibalize MTH signals and get 3-aspect signaling using three wires per signal head (taking advantage of each I/O pin being tristate).

 

I also have the Arduino talking to JMRI running on a computer, to provide a full GUI for control of switches, accessories, and operating cars.

Last edited by Professor Chaos
Originally Posted by BOB WALKER:

What kind of operating range did you obtain with your bluetooth setup and which bluetooth version are you using?

Hi Bob,

 

    The cheap Android tablet ($50) has Bluetooth 4.0 and the transceiver has been around a couple years, so it is not the "Smart Bluetooth."  I can run a few Bluetooth apps and a Bluetooth speaker at the same time.  I can get about 40 ft away and still run the handcar in the video (the house is 46ft wide and that is as far as I can test without going outside.)  I was told by someone that if you fool around with the antenna, you can get more range, but I haven't tried.  I am waiting for the BlueRail Trains DCC replacement boards.  My circuit is just too bulky to be practical inside a locomotive; might be alright in a tender.

 

Take care, Joe.

Last edited by Joe Rampolla
Originally Posted by zackesch:
The passenger car would be painted and lettered accordingly. Creating the filtered AC-DC and constant currant would not be an issue using a full wave bridge rectifier, filter cap and one of these guys

Be sure to bulk up on the filter cap on the input to those $1 DC-DC step down module (now deleted from your post).  Unlike signaling or accessory applications, a thorny issue with rolling stock applications is handling brief power interruptions from dirty track, going over switches, etc.  Even with seemingly small loads like LEDs, the 5V supply voltage drops rapidly and causes processor reset in a fraction of a second.  If heavy loads are involved (motors, smoke units, etc.) usually special consideration is required such as splitting off the processor power supply from the load power supply so the processor stays alive during the interruptions.

I don't know what a "party train" is so I googled it and apparently it's a song by The Gap Band.  So if this is what you mean, then a good follow on project to the LED lights is to add a low-cost (under $10) MP3 sound module that plays the Party Train song that you can sync to your flashing lights.  GRJ has found a low cost MP3 module that is easily controlled by an Arduino module.  Or even if by Party Train you do not mean the eponymous song, I'd think a train with people partying to flashing lights needs music!  See GRJ's thread for more info on MP3 sound modules; plus I'm sure he'd gladly provide tips on how to connect it to your Arduino controller.

I guess I wasn't clear on what was intended by "party train." The idea is instead of a solid warm LED, use RGB LED's to with a random frequency for each color channel to look like party lights kinda like what you see at weddings on the dance floor along with some music.

 

I'll take a look at that thread for the MP3 playback.

 

I wrote that post before my morning coffee fully kicked in. My brain to keyboard connection wasn't quite there yet.

 

With Prof. Chaos's layout as inspiration (see his YouTube videos and other posts here,) I am developing an autonomously-controlled layout using several Arduinos.

So far, I can throw turnouts by closing relay contacts briefly, read track occupancy via isolated rail closing relays and seeing those as inputs on the Arduino, read RFID tags of trains as they pass by the reader, and of course send Legacy and TMCC commands to locomotives.  Plus lots of other small things that make the project that much more fun, such as a "trigger/event" table that will do things like turn on the bell as a loco pulls out of a siding, and then turn it off when the loco reaches a certain speed.  And make appropriate announcements as the train leaves a siding, travels around the layout, and then enters another siding.  And control accessories such as turning on a freight station for a minute or so while the train is stopped.  And slow down the train as it crosses a curved trestle, and turn off the volume when the train enters a tunnel (and then turn it on again as it emerges.)

My goal is to have the system running up to 7 trains simultaneously on more-or-less random routes.  The trains will stop in stations, ring their bell, blow their whistle, make announcements, and move out again.

I've done all kinds of proof-of-concept tests, and have written a lot of the code and algorithms, but I'm still quite a ways off from being able to put all the pieces together and crossing my fingers ;-) 

My challenge at the moment is that not all of the Legacy commands seem to work exactly as documented in the Lionel spec.  For example, I can increase the RPMs of a diesel loco while it is standing still, but as soon as it's moving if I send it a command to increase the RPMs, it blows the horn.  There are a lot of commands that work when the loco is stationary but blow the horn when the engine is moving.  I'm going to have to analyze the output of the CAB 2 controller and compare it to the signals that I'm sending via my Arduino.

The strength of the Arduinos is that they are easy to program, there is a TON of hardware that will work with them (sensors, motors, communication, audio, etc.), they have tons of inputs and outputs (digital, PWM, serial, I2C, and SPI) and everything is very inexpensive.  The range of sensors that you can buy cheaply is staggering, and most are very easy to use.

Arduino microcontrollers are best suited to control applications where your project interacts with the real world.  Many other small systems such as Raspberry Pi have a lot more horsepower for crunching numbers, displaying graphics, etc. -- but tend not to have the I/O strength of Arduino.  For my project, I need a lot of inputs and outputs, and although the logic is rather complex, it doesn't really require much horsepower or memory, especially since I'm splitting the load among half a dozen Arduinos (they communicate with each other via an RS485 data bus.)

For a simpler project, you could easily put together an Arduino with a bank of relays and use it to control the turnouts on your layout.  I'm using Atlas #57 control boxes, and my Arduino simply monitors all of the boxes until it sees a button pressed, at which time it closes a pair of relay contacts for a fraction of a second to throw the switch machine.  I'm using relays that are sold on eBay on boards of 1, 2, 4, 8, and even 16 relays per board.  The ones I use only cost around $1/relay, and use a separate power supply for the relay coils -- so the outputs of the Arduino are not overloaded.

Of course you could just let the control button fire the switch machine, but by using an Arduino you can do even more -- such as throw routes with a single button press, or throw switches via your Legacy CAB 2 (the Arduino can decode the commands that the CAB2 spits out, and act upon them such as throw a turnout in this example.)  So it's sort of a DIY replacement for a Lionel TMCC switch controller.

Another fun thing would be to watch for an isolated rail section to be tripped, and turn on an accessory and/or play an audio clip and/or blow the locos whistle and have the loco make an announcement. 

Those are simple things to get started with, but you can do just about anything you can dream up that performs some task based on some form of input.

If you've read this far, please feel free to share your ideas or ask for help getting started.

Originally Posted by Randy P.:

and turn off the volume when the train enters a tunnel (and then turn it on again as it emerges.)

 

My challenge at the moment is that not all of the Legacy commands seem to work exactly as documented in the Lionel spec.  For example, I can increase the RPMs of a diesel loco while it is standing still, but as soon as it's moving if I send it a command to increase the RPMs, it blows the horn.  There are a lot of commands that work when the loco is stationary but blow the horn when the engine is moving.  I'm going to have to analyze the output of the CAB 2 controller and compare it to the signals that I'm sending via my Arduino.

 

I love the "volume down when entering the tunnel" idea.

 

As you suggested, compare the output of CAB2 with your Arduino commands. I think you'll find the difference--RPM up/down commands don't cause the horn to blow.

 

Sign up for the LCS Partner Program! Sounds like you are doing fun stuff.

 

Best,

Rudy

Director of Audio

Lionel, LLC

Another project that I have been sitting on for a while for the HO club I am part of is to make operating a bit more interesting, model a blue flag scenario. Once that individual is done switching that track/ set of tracks and give the crew the ok, they can hit a button which a blue led will shine depending on where its put, start a timer printed on an lcd screen and lock the switch "non-dcc electric turnout." Once the timer is out, blue light goes off and switching can continue as normal.   

Hi Rudy!  Nice to hear from you.  I'm glad you like my plan to turn the sound off when my trains are in tunnels -- it was an epiphany I had a few weeks ago when I should have been focusing on something entirely different ;-)
 
And as a matter of fact, I *am* a member of the LCS Partner Program!  But I don't want to bother you with technical questions until I feel like I've done everything I can to answer it myself.  The horn-blowing bug is very strange, but being a software guy, I know that strange things can happen no matter how simple they appear on the surface.  I'll set something up to show me exactly what is coming out of my Arduino's serial interface -- regardless of how certain I am about it from the programming side -- and see what I can figure out.  And I'll also use the LCS utility that allows me to monitor what comes out of the CAB2 and be sure that makes sense to me as well.  If I've gone down those roads and am still stumped, I'll reach out to you guys with some specifics.
Thanks for your note!
Randy
 
Originally Posted by Railsounds:
Originally Posted by Randy P.:

and turn off the volume when the train enters a tunnel (and then turn it on again as it emerges.)

 

My challenge at the moment is that not all of the Legacy commands seem to work exactly as documented in the Lionel spec.  For example, I can increase the RPMs of a diesel loco while it is standing still, but as soon as it's moving if I send it a command to increase the RPMs, it blows the horn.  There are a lot of commands that work when the loco is stationary but blow the horn when the engine is moving.  I'm going to have to analyze the output of the CAB 2 controller and compare it to the signals that I'm sending via my Arduino.

 

I love the "volume down when entering the tunnel" idea.

 

As you suggested, compare the output of CAB2 with your Arduino commands. I think you'll find the difference--RPM up/down commands don't cause the horn to blow.

 

Sign up for the LCS Partner Program! Sounds like you are doing fun stuff.

 

Best,

Rudy

Director of Audio

Lionel, LLC

 

I'm not sure I understand your question -- I connect wires  directly to my Arduinos using "screw terminal block connectors" that I buy on eBay.  Rather than trying to plug the end of a piece of wire into an Arduino female connector (which can fall out easily), you can use 8- and 10-pin screw terminal block connectors -- they plug into a whole bank of Arduino connectors and tend to stay in place but are still removable.  Then you can connect wires to them using a screw that crimps down on the end of your wire.
 
I haven't seen anyone else do this, but this is what I figured out on my own.  If I understood your question -- it was an excellent question because the answer is not obvious!  The only other thing I could think of would be to un-solder the headers and solder wires or "permanent" connectors directly to the Arduino board.
 
You could also remove the existing headers and solder the screw terminal blocks directly to the Arduino board -- but that makes it harder to replace the Arduino (you'd need to disconnect every wire rather than simply unplugging them in blocks of 8 or 10 at a time,) and also the ones I've seen would cover up the silk-screened pin labels on the board.
 
Originally Posted by rtr12:

Probably a dumb question, but what are you all using to connect your wiring to your arduinos?

 

Last edited by Randy P.
Originally Posted by rtr12:

Probably a dumb question, but what are you all using to connect your wiring to your arduinos?

In my case, the Arduino shares a ground with the Legacy base, so the ground has to be separate from layout common.  Inputs relying on layout common (like track occupancy) go through optocouplers to Arduino I/O pins.

Originally Posted by Randy P.:
I'm not sure I understand your question -- I connect wires  directly to my Arduinos using "screw terminal block connectors" that I buy on eBay.  Rather than trying to plug the end of a piece of wire into an Arduino female connector (which can fall out easily), you can use 8- and 10-pin screw terminal block connectors -- they plug into a whole bank of Arduino connectors and tend to stay in place but are still removable.  Then you can connect wires to them using a screw that crimps down on the end of your wire.
 
I haven't seen anyone else do this, but this is what I figured out on my own.  If I understood your question -- it was an excellent question because the answer is not obvious!  The only other thing I could think of would be to un-solder the headers and solder wires or "permanent" connectors directly to the Arduino board.
 
You could also remove the existing headers and solder the screw terminal blocks directly to the Arduino board -- but that makes it harder to replace the Arduino (you'd need to disconnect every wire rather than simply unplugging them in blocks of 8 or 10 at a time,) and also the ones I've seen would cover up the silk-screened pin labels on the board.
 
Originally Posted by rtr12:

Probably a dumb question, but what are you all using to connect your wiring to your arduinos?

 

Yes, Thanks! You got it perfectly. That's exactly what I was talking about. I looked around and didn't really see anything that looked like what I wanted. If you have found them on ebay, I just need to look further. Screw terminal blocks would be just perfect for this.

 

All I have ever done with the Arduino so far is bread board projects. Pinned jumpers work great for that. Now I finally got a project I want to make permanent and when I went to start wiring I found just what you said about the wires not working in the Arduino headers, unsoldering the headers sounds really ugly as does trying to use one of my pinned jumpers and having a splice a few inches away from the Arduino.

 

I was thinking I had seen a prototyping shield or something you could plug in and solder to, but I didn't find anything that looked like what I was wanting. I'll do some further searching with your suggestions and I should be able to finds something.

 

 

Originally Posted by Professor Chaos:
Originally Posted by rtr12:

Probably a dumb question, but what are you all using to connect your wiring to your arduinos?

In my case, the Arduino shares a ground with the Legacy base, so the ground has to be separate from layout common.  Inputs relying on layout common (like track occupancy) go through optocouplers to Arduino I/O pins.

I hadn't thought about that yet either. I am doing a train detector of sorts, but it will all be completely isolated for this particular project using photo resistors or transistors. It is nice to know about the isolation being needed though. Long term plans are to do more as I figure more things out. I still have a lot to learn about all this stuff and every tip helps. I will keep the opto-couplers in mind if/when I get to something like that. Stan2004 just gave me a lesson on those a few weeks ago and I ordered some of the ones he suggested for all around use. They are sitting here and waiting to be used.

 

Thanks to you both for the help.

Last edited by rtr12

Add Reply

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