Skip to main content

A few people have asked if the Python train control software I've been building could be used to build a physical train controller. As my goal was to build small panels to control operating accessories, switches, and track power, I hadn't really considered doing so.

My layout is basically U-shaped with a nice location in the center where a panel that would allow you to operate engines would be right at home. As my software supports all of the TMCC and Legacy commands, I've been able to control specific engines for some time now from a command line (set speed, direction, momentum, ring bells, blow horns, etc.) All that was missing was a way to key in an engine/train number and some sort of visual display...

Over the weekend, I wrote code to support a 4x4 matrix keypad, as shown below,IMG_1111

and a 2 line LCD screen. I can now key in the engine I want to control and see information about it on the LCD screen (the info was gleaned from reading the engine roster on my Base 3). I can read the TMCC ID, as entered on the keypad, and then send engine-specific commands.

Over the next few days, I'll be integrating this code with my support for rotary encoders and push buttons. My goal is to build a small panel that lets me enter an Engine (or Train) TMCC ID, and control speed, direction, couplers, horn, bell, reset, and start up/shut down. I'll also add a nice big red Halt button to do an emergency stop.

Pictures to com, but this is turning out to be easier than I thought!

  -- Dave

Attachments

Images (1)
  • IMG_1111
Original Post

Replies sorted oldest to newest

@BillYo414 posted:

I went to post on your other topic on my lunch today but got side tracked and never got around to it. I see you've been busy doing some other cool stuff instead! There will be custom run boxcars for the person that gives three rail O scale their handhelds back haha

Fabricating a handheld is a bit out of my skill zone. However, the software I’ve built would/could power such a device.

I’ll post some pictures of what I have later today.

  — Dave

You continue to impress Dave.  I keep looking for opportunities to jump in, but the train is moving pretty fast.  Pun intended.

I cloned your repo the other day and started browsing around.  To be honest, I wasn't quite sure where to start.  Maybe my Python is not as sharp as I thought.  If you're willing, perhaps you could give a little orientation/tour some time.  Hopefully there are others out there with interest that would benefit.

I do like the idea of building a handheld, but not out of necessity, more just for the fun of it.  Until my cab2 dies I suppose.  Maybe it's time to dust off the custom circuit board skills to integrate all the bits together.  An enclosure should be pretty straight forward these days with 3d printing and such.

You continue to impress Dave.  I keep looking for opportunities to jump in, but the train is moving pretty fast.  Pun intended.

I cloned your repo the other day and started browsing around.  To be honest, I wasn't quite sure where to start.  Maybe my Python is not as sharp as I thought.  If you're willing, perhaps you could give a little orientation/tour some time.  Hopefully there are others out there with interest that would benefit.

I do like the idea of building a handheld, but not out of necessity, more just for the fun of it.  Until my cab2 dies I suppose.  Maybe it's time to dust off the custom circuit board skills to integrate all the bits together.  An enclosure should be pretty straight forward these days with 3d printing and such.

I really need to spend some time writing some documentation. It is a part of the job.

happy to jump on a call sometime and give you an overview. As a quick start, have a look at src/cli/pytrain.py. If you have a base three, you can specify its IP address With the -base Command line option. If you are not running an LCS Ser2, also use -no_ser2.

  — Dave

Here are some pictures. This is using a 2 line display. I have a 4-line display on order ($12.00).

Here's the startup screen:

IMG_6574

I type "1" "8" and press the "#" key and:

IMG_6575

Again, the road name and number are read from the Base 3 directly.

Pressing "B" and you are prompted to enter a Train TMCC ID:

IMG_6576

I have a bit more work to do before I can actually use this to control an engine/train, but I hope to have something up and running by tomorrow to control speed. Again, I have all the command syntax and the ability to dispatch commands either to/thru an LCS Ser2 or directly via the Base 3 (via WiFi), but I have to write the bit to send the TMCC ID, control type (TMCC or Legacy) and scope (Engine or Train) from the keypad to the command dispatcher.

  -- Dave

Attachments

Images (3)
  • IMG_6574: Keypad, 2-line display, and rotary encoder to control speed
  • IMG_6575: After pressing "1", "8", "#"
  • IMG_6576: After pressing "B", "4", "2", "#"

I connected the "last mile" this evening, and can now switch engines using the keypad and control them independently .

I'm working on a generalized engine controller that essentially has all of the engine/train control functionality of the Cab 2 and Cab 3. This means you can operate an existing engine/train but not add new ones, edit existing ones (change road names, control type, etc) or delete them.

There are more basic commands than GPIO pins on a Raspberry Pi, but I just learned you can buy button boards that let you use the 2 wire I2C interface, meaning you could have scads of buttons! the controller will let you operate:

  • Speed (via rotary encoder)
  • Reset (Numeric 0)
  • Front/Rear couplers
  • Forward & Reverse Direction
  • Start up/shut down
  • Boost/Brake
  • Bell
  • Horn
  • RPM Up/Down
  • Momentum Up/Down
  • Volume Up/Down
  • Smoke Up/Down
  • Lights On/Off
  • Train Brake (via a potentiometer)


You would be left to wire up the buttons and other controls to your Pi, but my code (PyTrain) would take care of sending the appropriate commands (TMCC or Legacy protocol) when you operate the button or control.

I think this is going to be my first Control Panel!

  -- Dave

Great work!  And apologies if you already said this, but any thoughts about provisions for a rotary encoder, i.e., knob?

I'm not sure if you've ever seen the controllers used by AirWire and RailPro, but I think a lot of folks would be quite happy if someone adapted one of these to communicate with the Base-3.  Thanks for all of your hard work, and for sharing it on the Forum!!

@Ted S posted:

Great work!  And apologies if you already said this, but any thoughts about provisions for a rotary encoder, i.e., knob?

I'm not sure if you've ever seen the controllers used by AirWire and RailPro, but I think a lot of folks would be quite happy if someone adapted one of these to communicate with the Base-3.  Thanks for all of your hard work, and for sharing it on the Forum!!

Yup, there is support for a rotary encoder to control engine speed.

  -- Dave

Just finished some changes that let you use the rotary encoder and the cab2/cab3 at the same time. This was a little harder than I first thought, and I also found that the Cab 3 controller doesn't always stop the train from moving when you move the Cab 3 throttle to stop.

But all is now well. And it is very satisfying to see the speed I dial in on the rotary encoder display on the Cab 3 and my 4-line display, all in real time!

I just ordered a cheep project case from Amazon. Time to build a prototype!

  -- Dave

I am better with software than I am with hardware. With that said, I've started to assemble my prototype controller.

IMG_6628

The big red button on the top right will be an emergency Halt button. The little toggle switches will control smoke, rpm, labor effect, couplers, startup/shutdown, forward/reverse, and boost/brake. The other three big buttons (shown as pencil circles) will be bell, horn, and engine reset.

i have code to do the trade brake and the quilling horn, but I'm having trouble finding an inexpensive linear potentiometer that has a spring to return it to the off position. I've looked at hall-effect thumb switches, but they are pricy...

IMG_6629

Here is my Raspberry Pi 5 mounted to the bottom of the case. The only cords that will go into the box are power and the serial cable to the Ser2.

Hopefully I'll have it up and running by Monday!

  -- Dave

Attachments

Images (2)
  • IMG_6628
  • IMG_6629

Looking really good. In a pinch you can use a standard linear slider pot and a pair of springs or rubber bands to re-center. Another control you might consider is a cheap fsr or linear softpot. I’ve used both for analog synth work controlling the dynamics of a sound (VERY similar to “quilling” a whistle)…

@christie posted:

Looking really good. In a pinch you can use a standard linear slider pot and a pair of springs or rubber bands to re-center. Another control you might consider is a cheap fsr or linear softpot. I’ve used both for analog synth work controlling the dynamics of a sound (VERY similar to “quilling” a whistle)…

Great idea. I have one on order from Amazon ($12).

@cdswindell posted:

I went with a soft pot, bit to be honest, it was the first thing I found

Thought about this a bit more. For what it’s worth, the Lionel Cab-1L uses what I think is a little round FSR underneath the horn/whistle button. Search Amazon for “thin film pressure sensor” for similar parts. (At one point I wanted to repackage a Cab-1L as a table top unit rather than handheld, with the rotary encoder on the left (under my right thumb) and the keypad on the right (under my right finger tips). I never finished that one, but took pics after I opened it up).
Since these guys are 2 pin parts (variable resistor rather than potentiometer) you would need to add a fixed resistor to one leg to use it as a pot.

ECA7C41D-F911-424E-88FD-9F7D16B8B033

Attachments

Images (1)
  • ECA7C41D-F911-424E-88FD-9F7D16B8B033
Last edited by Rich Melvin
@cdswindell posted:


i have code to do the trade brake and the quilling horn, but I'm having trouble finding an inexpensive linear potentiometer that has a spring to return it to the off position. I've looked at hall-effect thumb switches, but they are pricy...

Dave if you're open to revising your design, check out "pitch benders" of the type that would be used on electronic synthesizer keyboards from Yamaha, Roland, or Korg.  The Yamaha modulation wheels in particular can be rocked up or down and have a spring return to center.  I suspect that these are made in much larger numbers than any Lionel train hardware.  LOVE what you're doing with this!!

@Ted S posted:

Dave if you're open to revising your design, check out "pitch benders" of the type that would be used on electronic synthesizer keyboards from Yamaha, Roland, or Korg.  The Yamaha modulation wheels in particular can be rocked up or down and have a spring return to center.  I suspect that these are made in much larger numbers than any Lionel train hardware.  LOVE what you're doing with this!!

I did a quick search for those but didn't see any that were relatively inexpensive (and, in fact, saw several over $100). Would love a reference, if you have one. Although my soft pot comes on Wednesday, I'm anxious to give it a try.

FWIW, I also found there are ADCs that work off of the I2C bus. This allows me to free up tje SPI pins to control more stuff!

  -- Dave

@christie posted:

Great. Lemme know if you have trouble with the thing - I’ve worked with them enough to know how to handle some oddities. Do be careful with the soldering iron heat on the connector pins - the whole thing is made from fragile flex plastic.

Thanks, I may do that. It won't be hear until Wednesday. Amazon usually can get me things in a day or two, this must be a less-frequently ordered item.

i assume I hook it up like a pot and read the voltage change as I move my finger up and down?

Thanks,

  -- Dave

@cdswindell posted:

Thanks, I may do that. It won't be hear until Wednesday. Amazon usually can get me things in a day or two, this must be a less-frequently ordered item.

i assume I hook it up like a pot and read the voltage change as I move my finger up and down?

Thanks,

  -- Dave

Yep, presumably you will be polling the device, looking for a change in value to sound a whistle, yes?

The issues I had were in voltage slewing at the beginning and end (mostly end) of events - and probably worse than your application since I was using only analog circuit control - not polled sampling.

[I’ve written and erased three versions of this, they all end up too long and have very little to do with trains]

Since there is no discrete finger down/up output on any of these devices, the value of the device may or may not be stable when you decide the event has started and ended.

Again, this is not a unique problem of softpots or fsrs, this applies to using any analog controller with a return to zero function where you want to trigger an event based on a change from a threshold value.

Feel free to email me for more details.

@christie posted:

Great. Lemme know if you have trouble with the thing - I’ve worked with them enough to know how to handle some oddities. Do be careful with the soldering iron heat on the connector pins - the whole thing is made from fragile flex plastic.

@christie, I. Having some problems with the soft pot. When I'm not pressing down on it, I see fluctuating readings from it, rather than a near zero value. Is this to be expected?

Thanks,

  -- Dave

Sorry for the delay, I’m on GMT for the rest of the year. Is the reading fluctuating wildly or just wobbling around a value? Try reading it with a simple meter when it’s lying loose, not mounted to anything.
I had some sensors that arrived from mouser/digikey folded in half (honestly!) that never worked right, but without touching it, you should have a reading that’s always below a threshold value.

@christie posted:

Sorry for the delay, I’m on GMT for the rest of the year. Is the reading fluctuating wildly or just wobbling around a value? Try reading it with a simple meter when it’s lying loose, not mounted to anything.
I had some sensors that arrived from mouser/digikey folded in half (honestly!) that never worked right, but without touching it, you should have a reading that’s always below a threshold value.

Good idea to check with a meter. I will next week when I'm back. I connected the sensor to 3.3 volts, and with no finger pressure, it was reading between 0.002 and 0.200. It just surprised me that it wobbled that much.

@christie posted:

Sorry for the delay, I’m on GMT for the rest of the year. Is the reading fluctuating wildly or just wobbling around a value? Try reading it with a simple meter when it’s lying loose, not mounted to anything.
I had some sensors that arrived from mouser/digikey folded in half (honestly!) that never worked right, but without touching it, you should have a reading that’s always below a threshold value.

I haven't checked with a meter, but I did back off of the sampling rate I was using on the Ads1115 I2C ADC I used to read values. When I went from 860 samples a second to 64, the unit stabilized considerably. That said, it is still reading around 0.12V when given a 3.3V feed.

When I press at the "least resistive" end, I get a consistent reading of around 0.0012V. I bought 2 of these things, I'll try the other one and see if I get the same results.

Does it make sense to you that I would get a larger value when no pressure is applied?

  -- Dave

@christie posted:

Sorry for the delay, I’m on GMT for the rest of the year. Is the reading fluctuating wildly or just wobbling around a value? Try reading it with a simple meter when it’s lying loose, not mounted to anything.
I had some sensors that arrived from mouser/digikey folded in half (honestly!) that never worked right, but without touching it, you should have a reading that’s always below a threshold value.

I just pulled out the meter. When there is no pressure applied, I'm getting a reading of "OC", which I assume means "Open Connection" (infinite resistance). Maybe I just don't understand how these soft pots work...

Not knowing exactly what part you ordered, is it a standard 3 pin part? Also, are both acting the same?

If a 3 pin part, Reading with a meter, resistance should be constant on the outer two pins. Resistance should vary based on touch position between the middle and either of the outer pins - from low to high with one connection, high to low with the other.

A standard application would have ground (0v) on one outer pin, +v (in your case 5 or 3.3 vdc I guess) on the other and you’d sample the middle pin.

For a digital input application i’d also try adding a 10k pull down resistor from the center pin to ground, that will probably stabilize your input.

Last edited by christie

Add Reply

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