O Gauge Model Locomotive Control System

I’m Kolton, I’m a sysadmin for a small engineering company in Southeast Missouri. Given the company’s small nature, I wear a lot of (small) hats, so I have experience in doing a lot of different things, all of which have come in handy for my project.

For #devember2020, I’m going to continue working on a project a friend of mine got me interested in: building a device to control 3 rain O gauge model railroad locomotives and controlling it from a phone or computer.

I’m months into the project at this point, but it still needs a lot of work. Some video of my previous prototypes:

  1. The first try of the very first proof of concept prototype, really only intended to see if I could properly rectify and regulate the track power and control the motors. I didn’t think it’d be a bad idea to run it at 100% throttle: https://www.youtube.com/watch?v=xhnMtPucQiI
  2. Soon after the first try, with PWM control so it doesn’t run at 100% throttle: https://www.youtube.com/watch?v=M-aq_Had3lA
  3. A later revision board with the proof-of-concept angular ui: https://www.youtube.com/watch?v=Fiope6IU2A4
  4. nnnyyyooooomm https://www.youtube.com/watch?v=YfYNqKfLueE

The bad news is that I basically had to start over a month or so ago, when I ran into a bug in a critical Arduino library and couldn’t find a workaround. I ended up switching to an ESP32 and have found that I like it so much that, even if that bug were to be fixed, I think I’d stick with it; there’s so many features! I even got .wav sound to (mostly) work: https://youtu.be/LennGP4YGuo?t=12

My plans for the rest of the year, in no particular order:

  • Test new functional blocks of the hardware design once the components arrive
  • Setup accessory control via a slaved Arduino on either a SPI or I2C bus
  • Control electrocouplers without browning out the microcontroller or releasing the magic smoke
  • Try to figure out control of AC motors (DC works fine, currently)
  • Make the existing frontend work with the new api, then try to make it less terrible
  • Try to get an MQTT interface on the device working for multi locomotive control (Linode may or may not be useful for this)
  • Get OTA updates working (Linode might be useful for this)
  • Spin new boards after testing all the new functional blocks and all the hardware needed arrives

Use optocouplers to drive a Darlington or MOSFET. Beef up the power supply with a large capacitor and separate that part of the circuit with a Schottky diode from the control electronics.

AC motors work fine on DC. For directional control, swap polarity on either the anker (rotor) or the field coil (stator) (mind, not both!). On normal AC it’s usually done with an over-volt relay, use a full H-bridge chip for your digital system. It’s also worth noting that on commercial digital systems, an AC motor is usually swapped out for a DC one, which are better controllable, resulting in better running of the model.

Do note that pretty much everything you’re after is already available commercially:
As it happens, I have the black box version and it works OOTB as advertised.

I’ve actually already tried something similar on a previous revision: https://www.youtube.com/watch?v=tirBzuV_sM0

That test was with a sacrificial Arduino (a knockoff of a 3.3v Arduino Pro Mini), so if the magic smoke was let out, I’d be out $4 and not $20. The Arduino Nano 33 IoT was apparently less tolerant, so it’d reboot when a coupler was triggered for a few milliseconds and drained 2 470uF caps. This happened even after adding a big cap to the regulated power to the Arduino.

After more research and a closer investigation of a TMCC module, I’m going to try to use the AC off the track through a triac (itself controlled with an opto-triac) to drive the coupler. Just doubled checked and confirmed that I can drive them with AC.

Regardless, I’m going to have to learn how to do better isolation to protect the control electronics; thanks for the tips!

I’ve tried that and had trouble with it: over current protection was constantly tripping on the motor drivers. I might have had the motor wired wrong, so that’s something I’ll need to retest.

I’ve never worked with open frame AC motors before this project, so I’m learning a lot. Between researching, looking at the TMCC module, and opening more than a few of my friend’s locomotives, I think I’ve learned how they’re wired by default.

The TMCC module I have uses a handful of triacs, so I’ll try some thing similar when I get my opto triacs:

The TMCC module didn’t have the snubber network caps/resistors, but the data sheets of the triac/opto triacs did, so I threw them in there.

EDIT: Minor error in this picture in the note and the actual triac numbering: Using the actual part numbering, the correct pairs are D1/D2 and D3/D4, not D1/D3 and D2/D4 as the note says.

I know that commercial solutions exist, but they’re often expensive and closed source, if they’re even still supported.

Other than giving me an interesting project to work on (on someone else’s dime!), the overall goal of the project is to have an open source system that’s reasonably cheap and easy to get into with a lot of expansion options. I can’t just say “replace the AC motor with a DC motor” because that might be hard for someone just getting into the hobby. I’m planning on the motor driver hardware to be on a separate board, so if I have to control AC motors differently, a new module can be dropped in to do that. Worst case, “AC motors not supported” ¯\(ツ)

Hope I didn’t come off as confrontational; I appreciate the feedback!

1 Like

A wild update appears!

Just a quick update on what I currently have right now. Thanks to slow shipping, I won’t be able to get actual hardware running any time soon, so the only progress I have been able to make right now is on the software side.

I did manage to get a lot done: basic Angular 11 control panel, in-code deoxygen documentation for the firmware, update configuration and save config to sd card, control motor drivers (represented by LEDs), control external accessories via a slaved Arduino over I2C, and REST endpoints for those actions.

I still have a lot to do before I’m willing to call it ready:

  1. Finish implementing OTA updates
  2. AC motor and accessory control
  3. Finish implementing sound endpoints
  4. Configure from control panel (endpoints available, but interface doesn’t support it yet)
  5. Implement MQTT control
  6. Minor hardware testing
  7. Spin new boards!
  8. Probably a bunch of other things I forgot…
1 Like