|
|
Log in / Subscribe / Register

DCC-EX: open-source model railroading

By Jake Edge
April 5, 2023

Everything Open

There's just something about trains—model trains in particular. At Everything Open 2023, Paul Antoine spoke about his experiences with the DCC-EX project, which has a variety of model-railroad automation hardware designs and software tools, all of which are freely available. There is a long legacy of sharing within the model railroading hobby, which continues today in the form of free and open-source software for it.

He began with some "model railway ground rules". They are not toys, but are generally detailed models and these days can have lots of microprocessors and software. "Not all model railroaders are Sheldon Cooper types, though some of us are." Meanwhile, "you may not say 'choo choo' every time you see a train or hear mention of model railways", which is a ground rule that he wishes he could convince his partners to follow.

Background

He got started in model railroading when he was ten years old and his father, who was in the audience for the talk, bought him a train set. He got interested in electronics and programming when he was 12 or 13; now all three of those things have collided in his work with DCC-EX. At age 13 in 1977, he joined the Fremantle and Districts model railway club where he met two important "life mentors"; those two built a model railway layout for the club, a picture of which can be seen in the video of the talk.

[Paul Antoine]

When that layout was no longer needed by the club, Antoine was able to buy it. The layout is fully automated and can run up to 25 trains at once. The automation used in the layout is "a good chunk of the Dwellingup telephone exchange", he said to laughter. Apparently some of the members worked for the telephone company and knew that the 48V relay boxes and other equipment were being replaced, so they arranged to have the "scrap" donated to the club. The complicated state machine and locomotive detection circuits use that equipment; it can keep the trains running fully automatically for many hours. The club would raise money by setting the layout up at shopping centers to attract people, so reliability was important; "it turns out the old relay boxes were pretty reliable because they used to run the telephones".

He showed a picture of singer Rod Stewart's intricate layout; the singer is particularly enamored with creating the buildings surrounding the tracks. In many ways, model railroading is similar to "maker" culture, though it substantially predates that movement. People get involved with whatever aspect they are most interested in: laying track, building scenes, adding lights and lighting, creating buildings, running the trains, designing and building the control electronics, and so on.

In the early days, automation was done with "transistor-style circuits" that were generally shared with other hobbyists as "open hardware". Someone who had a circuit that could be used as a throttle or that would flash the lights at a railway crossing would publish the schematic in a magazine or hand out copies of it to other club members. These days microcontrollers have become so cheap and ubiquitous that they have replaced most of those older techniques, but the open hardware ethic continues. Now model railroaders share designs and code. "Open source and open hardware have been a thing in the model railroading community for a very long time."

He showed two different track layouts, both of which were built around a single loop, but with multiple parallel paths, as well as some sidings and the like. Using the early control mechanisms would allow running a single train on either of those layouts, "maybe two if you wired it up cleverly". Once you could put a microprocessor into the locomotives, though, the more complicated of the two he showed could support up to, say, 20 different trains. You could "then tell locomotive number 35 to move—or to turn on its lights".

Locomotives have a motor and some gears inside the housing, which are driven by the DC voltage that is sent through the rails and into the train via the metal wheels. If you change the voltage, the speed increases or decreases; if you switch the polarity of the voltage, the train will go in the opposite direction. But the addition of a microcontroller to the locomotive changes all of that.

Instead of just voltage, a digital control protocol can be sent on the rails. You can send packets to the locomotive to tell it what to do. Those packets can change the speed and direction, but they can also turn on or off lights, change light colors (e.g. from a headlight to a red running light when changing direction), or have the locomotive emit sounds.

DCC

Digital Command Control (DCC) is the most popular protocol for controlling model railways, but there are others. DCC was designed by the German company Lenz Elektronik in the 1980s, then given to the US National Model Railroad Association (NMRA), which standardized it in 1993.

He showed a diagram of a DCC-controlled layout, with multiple locomotives, each with their own code, on the rails. The rails are fed from a command station, which creates the packets that are sent based on what it receives from multiple throttles. Each throttle can control one or more locomotives and can communicate over wires or wirelessly to the command station. The end result is that a throttle can tell a particular locomotive to do something and it will be the only one to act on the command because the packet is only addressed to it.

DCC added this individual-control ability, which allowed the commercial DCC product makers to add "a whole lot of margin" to their products. For example, a DC locomotive might sell for $275, but its DCC counterpart with sound capabilities might be nearly double the price ($475). Simple DCC controllers (command stations) start at over $200 and go as high as $1000 or more. Meanwhile, the manufacturers add their own form of lock-in by making the protocol proprietary between the throttles and the command station. "Yes, even in the world of model railroads, there's vendor lock-in ... oh joy," he said with a sad laugh.

He learned about the DCC-EX project while searching online last year and joined the project shortly after that. The project has several goals, one of which is "to make DCC far more affordable and accessible to everybody". The electronics in the low-end controller that he talked about could be obtained in China (even in small quantities) for around $10; the injection molding for the case is more expensive, but the electronics themselves are cheap because of today's automated factories.

So the project wanted to figure out if it could use Arduino boards and shields as the basis for DCC equipment. The hope was that the project could "out-innovate the market". As with the home router market, the manufacturers of this equipment stop updating it relatively quickly after it is released, so it accumulates annoying bugs. But, like OpenWrt, the DCC-EX project plans to keep supporting its software and hardware—in community fashion—for much longer.

The project is developed using its GitHub repository, though the main community gathering happens in Discord chat "for historical reasons, really". Discord allows the team to provide round-the-clock support to users, where they can often talk directly to the developers, which is not all that common in open source, Antoine said.

The EX-CommandStation, which is a GPLv3-licensed DCC command station similar to the commercial products, was the first project, but now there are seven sub-projects. Each of those interoperate with the others, creating an ecosystem of cooperating projects. They came about because someone thought "what if I could do this in software and it could to talk to that". For example, a friend of his has created EX-Turntable for a railway turntable that integrates with DCC, which allows locomotives (and other rolling stock) to be turned around in a small space.

As more people and projects come on board, the growth in features "seems to be accelerating as people get excited about what's possible". There are 15-20 volunteer developers, from all over the world, who have various hardware and software backgrounds. Some of those people are 70 or more years old, including the lead developer for the project. "Age is no barrier and never has been in model railroading", he said; it is interesting to see older people who have never programmed in their lives get started with doing so via DCC-EX.

EX-CommandStation

The Arduino is an 8-bit microcontroller with "a bunch of peripherals" that is generally programmed in C++. Most of the EX-CommandStation team uses the PlatformIO IDE for VSCode, but there is a simpler Arduino IDE; the team ensures that the code will build with the Arduino IDE in order to keep it accessible to those who may not be able to use the more complex tool.

The EX-CommandStation has around 25,000 lines of code. It originally targeted the Arduino UNO, which has 2KB of RAM, but they quickly ran out of memory, so they moved to the MEGA2560 with its spacious 8KB. It "gives you a great deal of discipline as a software developer" to fit the program's variables and such into that small space. Older developers have something of an advantage in that regard, since many of them grew up working on systems with similar RAM sizes.

When you build out the hardware for the EX-CommandStation, which usually means acquiring an Arduino, a motor shield to drive the signal to the trains, and a WiFi shield, it comes to less than 80 Australian dollars. If you buy directly from China, and are prepared to wait a while for it to arrive, it can be less than half that. That results in a system that is "far more capable" than most of the DCC controllers that cost anything less than $1000.

Most people use the command station with WiFi throttles. They use an open WiFi protocol that was developed by WiThrottle; there are apps for both iOS and Android available so a regular cellphone can serve as a throttle. Most of the apps are gratis, though there are a few paid apps on iOS; the most functional app is a fully open-source Android app. A single command station can support up to four WiFi throttles simultaneously.

One of the more interesting features of EX-CommandStation is its support for the EX-RAIL scripting language for automation and animation. It will, for example, let you detect a train approaching a crossing and light up the crossing lights; "it's all state-machine driven and still fits in 8K", Antoine said.

Challenges

"Relying on open source sounds fantastic, but doesn't come without its issues". The Arduino platform and its libraries have been used by millions of people since 2005, so they are fairly mature at this point, but the same is not always true for third-party open-source libraries. There is a thing about embedded systems, he said, "people get very grumpy when they stop", especially if it is for some reason they do not understand. The project has had to reimplement some libraries from scratch to get the level of reliability needed, but there are also licensing incompatibilities at times that lead to a need for reimplementation.

It is fairly common for projects, especially in the embedded space, to get started and run for a while before being abandoned, perhaps forked, and possibly abandoned again. People are enthusiastic early on and then move on to other things. DCC-EX focuses on not creating abandon-ware itself; it strives to create code that will be supported for the long-term.

"No matter how clever you are", there comes a point where the project needs to be able to grow beyond what 8KB can support. While the feature set currently barely fits into that space, new users are getting excited about what the platform can do, so they want to use it for more complex jobs. People will ask if EX-CommandStation can support their huge layout with 100 switches and 500 signals; "the answer is: 'not in 8K'".

So the project needs to make a transition to a 32-bit platform, but the question is "which?". The 32-bit Arm-based processors have become "insanely cheap" and are small in size, but the ESP32 processors from Espressif are possibilities as well. The ESP32 processors come with WiFi, which reduces the need for additional hardware; ESP32 development boards, even just in quantities of one, are around $4. While the Espressif hardware is impressive, the software is less so and "their open-source support isn't as terrific", he said.

Looking ahead, though, the project has 25,000 lines of code "and we have a legacy problem", because that code runs on the Arduino core platform. DCC-EX does not really have the resources to rewrite its code, at least anytime soon; some of the 32-bit processors have support for the Arduino platform, but the quality varies greatly. In the meantime, Arduino has decided to move toward IoT applications and its 32-bit processor uses Mbed OS, which also requires a platform switch that the project is not able to do. The most promising prospect at this point is the STM32Fx family using STM32duino for Arduino core support.

Future

The last six months "seems to have been a bit of a watershed"; many more people have joined the team, with a wide variety of skill areas and technical itches to scratch. There is a YouTube video about the product and an active ecosystem of hardware being developed. Release 5.0 will be out soon and "contains a raft of new and fun features". He wrapped his talk up with: "And that's how model railroading and open source collide."

One audience member asked if there were efforts to add DCC capabilities to existing locomotives. The problem is the space you have to work with inside the locomotive, Antoine said; all of the parts need to be micro-miniaturized, which is harder—but not impossible—to do using the contract manufacturers in China. Unlike for the larger controller boards, the DCC-EX project lacks the expertise to be able to create what is needed so that clubs or individuals can simply submit files to manufacturers and get back fully populated DCC decoder boards for locomotives. The project has code for DCC decoding, but not hardware.

Another question was more of a comment that mentioned the MIT Tech Model Railroad Club, which was an extremely early example of "hacker culture". Antoine agreed, but noted that no one knew about it at the time "due to lack of internet", which was met with laughter. "The kinds of people attracted to that group are precisely the people in our community"; the ethos of the club persists in today's model railroading hobby. The history of that club and its philosophy are worth reading for those reasons, he said.

The final question wondered whether all of these innovations had "lit a fire" under the existing manufacturers. Antoine said that sadly some have instead "upped their attempts at further vendor lock-in". But one US vendor has come out with two throttles that speak the WiThrottle protocol, so they will talk to DCC-EX hardware, which is "a bit of a win" for the project.

As might be guessed, the talk was well-received among the group of open-source developers, makers, and many others from various "open" communities. Model trains tend to be a subject that many are engaged by, even if they are not inclined to get directly involved. "Colliding" model railroading with open, as Antoine did in his talk, was sure to be a hit at a conference like Everything Open.

[Thanks to LWN subscribers for supporting my travel to Melbourne for Everything Open.]

Index entries for this article
ConferenceEverything Open/2023


to post comments

DCC-EX: open-source model railroading

Posted Apr 6, 2023 13:56 UTC (Thu) by kpfleming (subscriber, #23250) [Link]

I'm a little confused by their quandary related to moving to a 32-bit platform. The official Arduino store includes a number of 32-bit boards (some with SAMD21, others with RP2040) which are well supported in the Arduino IDE and in PlatformIO. Adafruit also produces a wide variety of boards compatible with both dev environments and offering 32-bit CPUs (adding ESP32 and nRF52840 to the mix).


Copyright © 2023, Eklektix, Inc.
This article may be redistributed under the terms of the Creative Commons CC BY-SA 4.0 license
Comments and public postings are copyrighted by their creators.
Linux is a registered trademark of Linus Torvalds