Have you ever wanted a smart railroad that could be controlled from the comfort of your own cell phone? Imagine trains that could be programmed with a set of tasks but still allowing you to take over manual control at any time.
This site will detail my own adventures in building a wifi-enabled model railroad. The plan includes the following:
- ESP8266 in each locomotive to provide autonomous intelligence
- Raspberry Pi to provide the central server and web links
There are a lot of pieces already in progress for bringing everything together.
- Using an ESP8266-12F, the locomotives each have parameters defining minimum and maximum speeds. Software creates a buffering of speed and direction changes to give a smoother reaction and prevent bad things such as high speed direction reversals.
- A web page has been built to interact with the trains and control direction or speed. This relies heavily on javascript for a real-time display.
- MQTT has been chosen to maintain the live parameters of each train and each client controlling a train. This requires a greatly reduced level of network traffic for transferring information between each locomotive and web interface, and provides a higher level of reliability in making sure the information reaches its target.
- Camera interfaces are a tricky subject, however I have had some fairly successful tests using an ArduCam at 320×240. Unfortunately the ESP-12 is very limited on the number of I/O pins, so I have dropped the camera until I am able to start working with an ESP-32s.
And of course there are a number of devices that I still need to build. Many items around the layout with be controlled through infra-red LEDs. There will be a transmitter and receiver on the front of each locomotive to work with the following:
- Collision detection: Determine if there is something immediately in front of the loco
- Location: Each loco should always know where it is at on the layout
- Occupied sections: If the track in front of a train is already occupied by another train, we should know to slow down or stop until the next section is clear
- Turnouts: When approaching a turnout, you need to decide which way to go
- Crossing gates: Signal when a train is crossing a road
There will also be other functions on the layout which communicate through wifi, such as loading and unloading docks that may not be within sight of the locomotive. When hauling heavy loads up the mountain, two locomotives may need to work in tandem, and with use wifi to synchronize their speeds.
As mentioned above, the biggest part of this whole project will be the autonomous operations. Each locomotive will have a predefined set of tasks to complete. For example, a switcher sitting in a yard may need to pull all empty cars from a siding, drop them in front of various docks or take them to a loading bay, and finally stack up the loaded cars on another siding for pickup on the mainline. A mainline locomotive may similarly be tasked will picking up loads from one town and delivering them to the next town. A key part of all these operations is finding a way to detect how many cars are attached to a locomotive so it knows when it has properly disconnected from or reattached to a string of cars.
Overall this will be a multi-year project. In between creating all the electronic circuits and writing the code, I will also be building the layout to run this from. There’s a lot of work to be done, and I am but one person…