Skip to main content

Reply to "Python code to issue TMCC, Legacy, and PDI Commands"

Checked in support for a Rotary Encoder. Think of these like digital potentiometers, except they rotate round-and-round, just like the big red throttle knob on the Cab 2.

I've incorporated this support into GpioHandler.gantry_crane and GpioHandler.track_crane to rotate the cab. Of course, with that said, when I unboxed my Lionel Legacy CSX Track Crane car, I found it was missing a gear necessary to rotate the cab! But my code does send the right commands and I can see the gears they did install turn in the correct direction. Sigh

Here's what the code looks like a user would have to write to build a dedicated panel to control a track crane car:

GpioHandler.crane_car(
address=91,
cab_pin1=20,
cab_pin2=21,
adc_channel=0, (1)
boom_pin=16,
bh_pin=25,
sh_pin=26,
boom_led_pin=23, (2)
bh_led_pin=24, (2)
sh_led_pin=22 (2)
)


Where:

  • address: TMCC ID of Crane car
  • cab_pin1, cab_pin2:rotary encoder GPIO pins on the Pi
  • adc_channel: the adc channel to read joystick input for boom, small hook, and big hook motion (1)
  • boom_pin, bh_pin, sh_pin: GPIO pins connected to buttons to select what the joystick controls; the boom, the big hook, and the small hook.
  • boom_led, bh_led, sh_led: GPIO pins to drive status less to show which component the joystick will control; boom, big hook, or small hook.

Notes:

  1. I chose to use a MCP3208 analog to digital converter to take input from the analog joystick potentiometer and convert it to digital, so the Pi can consume it. Various vendors supply "hats" which sit on top of the Pi's 40 pin GPIO header. You can stack hats one on top of another, as I've done in the picture below. It would also be possible to use Rotary Encoders to control boom motion, but a joystick with a simple up/down motion felt more natural. The code supports both the MCP3208 (12 bit) and MCP 3008 (10 bit) a to d converters (thanks to the gpiozero python library). One of these chips can support 8 joysticks (or potentiometers).
  2. Status LEDs are optional. I think it adds a nice touch, though, to show what function the joystick will control

All told, you are looking at less that $100 of parts, and all available from Amazon and one other online vendor. IMG_6552



Attachments

Images (1)
  • IMG_6552: Raspberry Pi 4B with MCP3208 ADC hat
×
×
×
×
×