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

Add Reply

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