Skip to main content

I posted a couple weeks back about my outdoor O Scale adventures, Arduino driven switch tracks, etc.  I was gauging interest in things I've learned / developed.  There was a general consensus in that thread that Arduinos are neat-o and sharing code would be very welcome.

I took some of the code I was using to decode / interface with the Legacy base (TMCC basic commands only) and turned that into a nice library that is easy to use.  Now, it will help to know something about these micro-controllers and how to use libraries (there are tons of resources online).  It's not hard, but I am assuming you can compile a sketch, hook up the three wires needed to interface with an RS-232 -> TTL converter (less than $10 online), and that you can figure out the ground and transmit wires from the Legacy Base (I didn't try this with the CAB-1 base).

If none of that scares you off and you want to receive TMCC decoded data, this is for you.

Download the zip and install the library, compile the example sketch, hook up your hardware, fire up the Serial Monitor, and watch the commands roll in as you press buttons on your remote.

You'll find the example and library well commented and pretty much everything you need to know is in there.

Enjoy!

 

-Randy

 

PS: I'm finishing up a 32" scratch-built turntable that uses a 100:1 stepper motor direct drive.  Guess what?  Arduino controlled using accessory commands on the Legacy Remote.  This is going outside on my garden railroad!  It's been much more work that I expected, but it's working just as I had planned and it looks amazing! 

Attachments

Files (1)
Last edited by Randy Owens
Original Post

Replies sorted oldest to newest

Matt is right.  It'll work fine.  The pinout from the command base of the CAB-1 is the only difference. 

RS-232 spec: pins 2 and 3 are transmit / receive with pin 5 being the ground.  Pin 2 and 3 are switched between the two bases.  RS-232, one end is traditionally thought of as the "computer" and the other end as a "peripheral".  Two devices can't talk and listen on the same pin.

What I can tell you about the cables: plug the Legacy side into the Legacy base and the Command Base side into the Arduino RS-232 -> TTL converter and you'll get Legacy communication traffic.  If you cut the cable (I did), the wiring, as I recall:

Red Wire -> GND

Brown -> Transmit from Legacy Base

Black -> Transmit from Command Base (I think)

I can't tell you which pin the brown and black wires go to (never cared to chase it down).  I didn't need the cable for anything other than my Arduinos (running three and more coming), so once I figured this out, I moved on the to the next problem.

 

-Randy

Didn't the original TMCC command base use 0-5V rather than the full voltage range specified by RS232?

If so, most RS232-TTL converters will still be ok with that. But you should be able to read the data without an RS232-TTL converter, by using the SoftwareSerial library and setting the inverse_logic parameter to true.

You would NOT want to do this with the Legacy base, as it puts out close to a full RS232 voltage swing.

Last edited by Professor Chaos
AmeenTrainGuy posted:

So what do I need to do to make it work on my cab 1? From what your saying I am understanding that the wires are half duplex and not full duplex right?

 

Thanks

Same thing for CAB-1 as Legacy except that the pinout from the command base has pins 2 and 3 crossed.  Legacy listens to the Command Base on one of the pin and talks on the other and vice-versa.

Here's what you need to make it go:

1) Get an Arduino (I use Nanos mostly)

2) Get a Converter (type this into Google: "rs232 to ttl converter")  New Egg has these for less than $4.

3) Wire up the converter to the Arduino as I previously posted

4) Load up the library into the Arduino dev tool and load my example sketch

5) Get a couple of DB-9 connectors or a serial cable.  You need pin 5 and either pin 2 or pin 3 on the Command Base (sorry, I don't know which because I didn't try it).  Wire those pins to the converter you bought as I indicated before in my earlier post.

6) If the pins are correct, the receive light will flash on the converter when the CAB sends commands to it.  If it doesn't light, use the other pin (if you're using pin 2, try pin 3 or vice-versa).

 

That's it.  If the RS-232 thing is confusing, try searching for info on the standards for  a 9 pin RS232.  It's super common / tons of details online about it.  Lionel did nothing secret or odd except maybe the voltage range....

 

The earlier comment about the +-5V signal from the Legacy Base, I think is correct according to the research I did.  I am using the converter because it uses optocouplers to isolate the signal completely and converts the 5V or whatever is coming in to 3.3V TTL.  This ensures that the Arduino lives a long and happy life.  It may otherwise without the converter, but I am staying within the specs that I've read.  And, beyond that, I am planning to use a signal booster very soon.  That converter will be happy with that signal which will be +- 12V.  Try going direct to the Arduino without the converter if you feel adventurous, but note that the Arduino might respond unfavorably / be damaged.  I have a number of Nanos onhand.  Maybe I'll give it a go when I get done with more pressing tasks.

 

I hope this helps!  Good luck!

 

-Randy

 

 

Randy,

Any updates? I'm just getting back into the train hobby after having been away for about the last 15 years. I jumped in with both feet and ran WOW Trains (the online train company specializing in Williams trains, initially). It's no wonder Williams went out of business, and I was stung by their practices, but I developed quite a collection, and in fact still have lots of NIB inventory.

Anyway, I have started exploring TMCC, as just before I got out of things I picked up a CAB1 and base when it first came out, knowing I'd want to use it in the future. I've tinkered very, very basically with an Arduino, and the thought of using it with my trains is intriguing. If I understand correctly, the Arduino would be the "receiver/interpreter" so to speak, that goes in the locomotive to carry out the commands issued from the Cab1, correct? Being able to do that without being tied to the expensive boards I've seen from only one or two sources is very attractive.

I just downloaded the zip file you posted and am excited to learn the possibilities of what I can do with the Arduino, but please pardon my ignorance in this regard, and let me know your thoughts.

Thanks!

Here's a link to C++ code that breaks down serial input TMCC commands from the Command Base to human readable text for console output that I wrote a while ago.   Would be nice if someone converted it to Arduino.  The last time I compiled it was pre-VS2008, and it needs tweaking to compile on current Visual Studio versions.

https://github.com/RothenHarper/CmdBaseReader

Enjoy ...

Hey ProfGT:

I never used an Arduino to control a loco, but it could be done.  I am using the microcontrollers for moving points and controlling accessories.  I'll my stuff is outdoors, so I use waterproof servos to move points and the Arduino makes a great servo controller.  Combine that with decoding signals from TMCC or Legacy, and it's works real nice.  I use optocouplers on a short section before each switchtrack to make everything auto-derail.  The Arduino sees the train coming and switches if necessary giving priority to the sensor over the TMCC commands.

I think the tinkering is most of the fun.

-Randy

Add Reply

Post

OGR Publishing, Inc., 1310 Eastside Centre Ct, Suite 6, Mountain Home, AR 72653
800-980-OGRR (6477)
www.ogaugerr.com

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