How do you control functions on your layout other than your trains?
Poll a group of model railroaders and you’ll get all kinds of answers, ranging from manual turnout throws to DCC and stationary decoders, to proprietary boards, to custom, hard wired systems.
Layout control is what brings most of us to the Arduino world. Inexpensive micro servos make great turnout motors; adding buttons and position indicating LEDs to a control panel with the whole thing run by an Uno or Mega is a lot easier than the hard-wired control panels people used to build.
But what if you want to automate a turnout, based on block occupancy or the state of an adjacent turnout, to prevent trains from running into it out of position? How about one-button setting of complex routes? Or what if you want automatic block signals based on block occupancy? What if you want your fast clock to actually cause animations to run or lighting to change?
All of these things and more are possible with a layout control system with embedded intelligence.
But I want Centralized control: a CTC system or JRMI.
Fine. Embedded intelligence enhances the reach of a central control system by offering more functions the central system can invoke. At the same time, embedded intelligence can handle some mundane processing loads that the central system isn’t otherwise required to handle. With the right communications protocols, intelligent nodes make layout communications processes more efficient by combining centralized (‘command and control’) and decentralized (‘peer to peer’) messaging.
Among other things, this allows layout processes to respond to each other instead of forcing a central processor to calculate and issue multiple commands. So, for example, you can have automatic safety processes that prevent a signal from showing CLEAR or APPROACH if the turnout the signal guards is out of position, no matter what the central control says it wants. Or a crossing is always activated appropriately without the central system having to worry about it at all, and without having to use a dedicated, single purpose system to do it.
This is the start of a series devoted to the Arduino-based scalable layout control system I am creating for my layout. My control system has evolved from a lot of custom, ad-hoc components to off-the-shelf parts and some basic software building blocks that I use over and over again. This system and methodology would well on most layouts and can scale to even the largest club layouts.
The basic building block of the system is the Layout Control Node.
Layout Control Nodes
An Arduino board equipped with a wireless communications device constitutes a basic Layout Control Node. Each LCN generally handles some or all of the tasks needed for its physical location on the layout—block occupancy detection, polarity relays, turnouts, signals and layout lighting and effects. In addition to general purpose nodes, some LCNs might be specialized—such as for my turntable or the ambient lighting system—and handle a narrower range of tasks.
Pins & Peripherals
I’m sure some readers are already thinking they would need MEGA 2560 boards to have enough pins to do the tasks described; many beginners immediately resort to the Mega for a project because it has a wealth of pins compared to other boards. Sure, there are situations where the Mega is the board of choice—such as where you need to monitor a lot of buttons, switches and/or sensors—but most of the time you are better off with a smaller micro-controller board.
Instead of relying on (and being limited by) board pins for everything, I use peripheral devices to provide both digital and PWM ports, using board pins to control the peripherals.
Why am I going to that trouble? Because it is a Plug & Play way to eliminate limitations and extend capabilities of an Arduino.
Current Handling Capacity
The primary limitation of Arduino boards is obscured by pin count and hidden from view: current handling capacity.
For most Arduino boards based on Atmel controllers, pins can handle no more than 40 mA each, and the total current handling capacity for all pins is 200 mA. The Mega has these same limitations in spite of the extra pins.
That’s not much. For example, a typical LED draws 20 – 30mA, if you attach more than 10 LEDS to 10 pins on any board you will exceed the current handling capacity of the board!
Some external devices— most relays, motors and other inductive loads, for example—cannot be attached directly to an Arduino because they draw more current than the board can handle.
So the best way to deploy Arduinos on a model railroad layout is to use peripherals to provide the IO pins you need for power-hungry layout devices (lights, servos, etc.) and use your micro-controller pins to control the external IO devices. This greatly expands the power handing and control capabilities of the micro-controller.
Many Hands Make Light Work
It may seem counter-intuitive, but in addition to making each Arduino more capable, I am using more of them. The point of adding more robust ports to each board is to ensure the board has the resources it needs to do a reasonable assortment of tasks, NOT to cram every possible layout task into a single Arduino.
While you can program an Arduino to do amazing things, it’s still true that a micro-controller can only do one thing at a time. Multitasking is possible through time slicing, but the more you ask it to do the less responsive it will be.
The alternative is to spread the work load across many micro-controllers and give them the ability to coordinate their activity. Multiple micro-controllers mean real multi-tasking and better responsiveness if the work loads are balanced and communications robust.
Each Layout Control Node has the following capabilities, if required peripheral devices are present:
- Communicate wirelessly with other LCNs; exchange block, turnout and signal status information in real time with specific designated “partner” LCN’s and/or the Master LCN.
- Monitor up to 6 block occupancy sensors.
- Monitor control panel buttons and switches.
- Control up to 16 PWM devices, such as servos for turnouts, animations or special lighting effects.
- Control as many digital outputs as needed for signals, layout lighting, relays and other devices within physical range of the node – up to 160 digital outputs per LCN.
- Run embedded rules for signals based on block occupancy / turnout status.
- Respond to control panel button presses / switch changes according to embedded rules.
- Respond to fast clock signals according to embedded rules.
- Accept and implement centralized command overrides.
You’ll notice that the specifications for an LCN are entirely agnostic on the issue of locomotive control. The Layout Control System could directly interact with locomotive control if you wish it (through JMRI and/or DCC++, for example). But, from a design and requirements standpoint, Layout Control and Locomotive Control are entirely independent of each other. Accordingly, this system is intended to work with any train control system, including DCC, PWM DC or plain vanilla DC.
In the next post, I’ll explain the hardware elements that I combine to create an LCN and talk about the electrical infrastructure needed for Arduino-based layout control.
A Small Tease
I have yet to create any control panels for the L&NC, but that doesn’t mean I don’t have full control. Right now to issue a command to the system I type it in Serial Monitor. Not as convenient as formal control panels, but quite adequate for the layout in its partially constructed state.
In the photo below, a minimum basic LCN is serving as the Master LCN and gives me full access to the entire network of LCNs installed on the layout: