The Challenge
The idea for this Arduino based project came about when I was at my local the MERG area group meeting. One of the people in the room was asking about a way to use a DCC system to run DC trains, not by using address 0, but by having a DCC address for section of track.
The most obvious solution appeared to be to merely mount a DCC decoder on the baseboard and take the motor wires to the track. This had one big drawback, short circuit protection on the output of the decoder.
I took this as a challenge and went away thinking about how I could solve this using an Arduino and some of the simple module that are available via every bodies favourite internet auction site.
The Idea
I knew the person in question was using the MERG DCC system, one of the things about this system is how the handsets connect to the command station. They use CBUS, the MERG layout control bus. This bus is the same technology you find in all recent cars for connecting the electrical equipment together. This means there are off the shelf modules that can interface to it.
My idea was, connect an Arduino to the CBUS and capture the messages between the handset and DCC command station.
Then the Arduino can power the tracks and drive DC locos when it sees requests for particular DCC addresses.
CBUS Interface
Since the MERG CBUS uses the standard automotive CANBUS interface I could use one of the chips designed to interface with CANBUS. The MCP2515 provides a CAN interface and connects via the SPI bus, which is supported by the Arduino.
Breakout boards for the MCP2515 are available very cheaply and the also contain all the extra circuitry required. They can be directly attached to an Arduino and the other end attaches to the MERG CBUS.
No soldering or other components required.
Track Connections
With the CBUS interface resolved the next step was to think about how the Arduino could drive the trains. The 5 volt logic outputs of the Arduino do not have the ability to drive a motor, some form of interface was required.
A device known as an H-bridge is used extensively to control motors from logic circuits, in fact every DCC decoder you buy has an H-bridge to connect to the motor.
It works by having two inputs, to a set of 4 transistors. If one input is taken to a logic low and the other to a logic high the motor will run in one direction. Reverse the two inputs and the motor runs the other way.
H Bridge
The other thing you can do with an H Bridge it to pulse one of the inputs on and off, this gives you control of the speed of your motor using the principle known as PWM or pulse width modulation. Keep it on for 50% of the time and off for 50% and the motor runs at half speed. Vary the ratio of the on and off and you change the speed.
Again a module is available that can be directly connected to the Arduino that gives 2 H Bridges that can be run at 12 volts and can drive our trains.
This allows us to drive two sections of track using 4 connections to the Arduino.
Software
I will not go into all the details of the software, if anybody would like to look at it then it is available on the internet in my Github account by clicking on this link.
I did have a good starting point, a library by another MERG member that had most of the support I needed to read the CBUS and decode the messages between the throttle and the command station. A few bugs needed to be fixed and the code written to drive the H bridges. Otherwise is was fairly simple. I allocated addresses 9000 and 9001 to the two outputs of the H bridge. Selecting these addresses on the DCC throttle would then drive the tracks connected to the H bridge, speed and direction on the handset working exactly as they would for a DCC controlled train.
No Solder Prototype
All this was prototyped without even soldering a single component, in fact the only solder joint was to solder the track feeds to the track. The prototype doesn't look pretty, but it proves the concept.
It may not look pretty but it works and it was produced very quickly.