MRRwA NmraDCC Library

  • Posted 20 January 2015

Look for the next article that details a DCC Monitor sketch using this library, and later on the 4-turnout function based decoder circuit and sketch.

There is a great NMRA library for the Arduino available at Model Railroading with Arduino called MRRwA NmraDCC written by Alex Shepherd.
It was recently updated by Geoff Bunza and his project details can be found here SMA-13.
He has an excellent example arduino sketch labeled "Decoder_17LED_4Function" that can be setup (via CV's) to control servos, on/off operation of a pin for lights or other items, and blinking of led's. The example can control upto 17 things from one arduino.


So what does this mean ?
With a low-cost $2-5 arduino pro mini, some code and some supporting circuitry you can control almost anything on your layout directly from your dcc controller.


The arduino can be placed anywhere on the layout and get power and signals from the track.
Need more power? simply run a pair of wires to the location from a central power supply and control that power with a relay or mosfet.

 

Some of the items you could control include

  • Turnouts/Points - servo based via servo library, and solenoid based via mosfet/transistor+cdu
  • Signals - led and bulb based (with proper current limiting resistors)
  • Lights - such as street lights, tunnels
  • Moving items - simulated cars, people walking, animals. this can be motors and/or servos
  • Sounds - remotely activated speakers with sound chips
  • DC Train/Alternate track - via high power mosfets you can drive one or two DC locomotives on a seperate track.
  • Anything electrical or motorized

 

My Work

Im currently experimenting with controlling turnouts and other high current items.
Also have gotten the ACK working so that CV reading works.

On the left is the arduino pro mini mounted on a proto board; the top left is the "listening" circuitry, the bottom left is the "ack" circuitry.
Top left cable is the track wires, center top is the cp2102 usb2serial cable for pc debugging/programming, top right is power input, bottom right is the 8 outputs.
The right image is a ULN2803 driver setup to control 4 turnouts.

 

More library details

The library is open source (GPL) which means you can modify it to do anything you want but dont worry by default it provides almost everything you need.
Some of the important supported features include

  • Single Address
  • Any Address
  • 2-digit and 4-digit addressing
  • Accessory decoder mode - accessory and signal states (Turnouts, signals)
  • Function decoder mode (f1-f28)
  • Motor Control (speed, direction)
  • Reset on write to CV8
  • Direct operations mode - cv read/write, direct byte and bit modes
  • Much more

 

The next article is going to be a basic dcc monitor to see the messages that are passing on the track. Arduino DCC Monitor
Its of great help in troubleshooting your custom code because it shows you the exact data passing thru, it can also be a building block for your own decoder.

 

Ordering Links

Here are some links to places you can buy the items on this page. Ebay is also another good place to source them.
Do note that it usually takes 3-4 weeks for delivery from Asia to North America.

Arduino Pro Mini 5v 16mhz - $2 -  Buy at Aliexpress.com
Arduino Pro Mini + CP2102 ubs2serial adapter $4 - Buy at aliexpress.com

As always, contact me if you would like to order any of the parts you see here from me.