Building the Decoder -- Hardware
The hardware for this decoder includes little more than before: a $2.59 Arduino Pro Mini Board, a 6N137 optocoupler, a LM78L05 voltage regulator, miscellaneous resistors and capacitors, and some header pins to connect to the servos. The BIG change is the program and library modified for the job, which I make available for modeler use. I strongly suggest that you read the prior article ( https://forum.mrhmag.com/post/sma10-%E2%80%93-build-a-17function-dcc-decoder-for-about-5-12197796 ) for complete details. The Pro Mini and other parts are mounted on a piece of perf board.
Perf Board
An updated diagram is included below. Again, these are available from many different sources—electronics distributors, surplus dealers, ebay, Radio shack, and Fry’s Electronics. Assembly is pretty straightforward if you’ve ever soldered a small set of components before. You could also use a solderless breadboard (like Radio Shack 276-003) to assemble a decoder. The example decoder pictured above has 17 optional LEDs connected to each “Function Output” pin. On the Arduino Pro Mini these are labeled 3-13 and A0-A5 and they directly correspond to standard DCC Decoder Functions F0 through F16. Next to each mounted LED is a three pin header for individual Servo attachment. The Servos I use are low cost 9G Servo Motors that are very commonly used in the RC hobby. They are available in many hobby stroes, and can be ordered direct from Chinese manufacturers through ebay at a steep discount. Note: while cheap servos are available, their noticeable characteristic is a great variability from servo to servo, including swing measure, noise, and current draw.
9G ServoMotor
The Servo needs three connections per servo: a ground, or common (black), +5 Volt power (Red), and a control signal (often White). The control signal is directly connected to the Arduino Pro Mini Pins labeled 3-13 and A0-A5. Ground connects to the Pro Mini GND connection. The power supply, realistically, should be separate from the DCC bus (rails). You will need a +5 Volt supply to power the Servos. This new supply can also power decoder logic, so this will minimize the load on the DCC lines. Each Servo can have a peak current draw of about 140ma, so 17 can draw 2.4 Amps! If you operate fewer, you’ll need less power.
The materials were all hand soldered. You don’t need to mount any of the LEDs on the board. I did it as a test and demo. As before the LEDs I used need only about .1-.2ma for a bright indication. The LEDs you use may need a lower dropping resistor than 10K Ohms. If you control a Servo with a particular function pin, I recommend that you remove the LED at that pin. Regardless, you should cut off the surface mount LED Pin 13 indicator or its dropping resistor on the Pro Mini Board, as it is both redundant and may interfere with the function assigned to that pin. Capacitor C8 (270pf) is important for increased noise immunity. Make sure you place C8 as close to the 6N137 as possible.
Partial Bill of Materials:
Arduino Pro Mini atmega328 5V 16M ( from EBay: http://tinyurl.com/kexh66b ) $2.59
(This price varies. I've seen it as low as $2.25. Search Ebay for "Pro Mini." Price often includes free shipping.
Digikey example parts ( http://www.digikey.com):
160-1791-ND OPTOCOUPLER HS LOGIC OUT 8-DIP 0.73
LM78L05ACZXCT-ND IC REG LDO 5V 0.1A TO92-3 0.44
493-5914-1-ND CAP ALUM 220UF 25V 20% RADIAL 0.38
DF005M-ND RECTIFIER BRIDGE 50V 1.5A 4-DIP 0.45
1N5819FSCT-ND DIODE SCHOTTKY 40V 1A DO41 0.50
P5149-ND CAP ALUM 22UF 25V 20% RADIAL 0.20
445-8421-ND CAP CER 0.1UF 25V 10% RADIAL 0.29
BC1018CT-ND CAP CER 270PF 50V 5% RADIAL 0.35
CF14JT10K0CT-ND RES 10K OHM 1/4W 5% CARBON FILM 0.10
CF14JT5K10CT-ND RES 5.1K OHM 1/4W 5% CARBON FILM 0.10
1N5819-TPCT-ND DIODE SCHOTTKY 40V 1A DO41 0.39
LEDs: try looking for some at Surplusgizmos.com like Part Number LBT30W2C-CUA-C 3mm LED 20ma Bright White 15,000 MCD 0.30 or at Allelectronics.com like CAT# LED-83 3mm diameter T-1 LED. Ultrabright white 0.95
I usually buy white LEDs and then color them with Clear Tamiya paint to suit the situation.Learn more about using LEDs here: https://forum.mrhmag.com/magazine-feedback-was-ezines-891776
The boards I use can be found here: decoderpcbs.zip
They're cheap, double sided with plated through holes.
Construction Comments Addendum
1. Use only the library I provided in the Zip file, previous editions will not work.
2. The green LEDs used as Function indicators are especially bright even with very low current. With a 10K dropping resistor normal LEDs you might have may not light up. Try using a lower value resistor -- closer to 1K for more normal LEDs. (I get these from surplusgizmos.com listed as 3mm green LED).
3. To get the LEDs to fit side by side on .1inch centers, I used a sanding disk mounted in a moto tool to sand the sides down just a bit in parallel with the LED pins. They are plugged into an IC socket cut and soldered to the board-- it keeps them in somewhat neat order.
17 Channel Configurable Multifunction DCC Decoder Schematic (A4-A6 connections omitted)
Building the Decoder: Big Changes Inside - New Decoder Code
The Arduino Pro Mini needs to be loaded with the decoder program which you can download from here (updated November 26, 2016):
http://mrhpub.com/files/users/geoffbfiles/new-dual-multifunction-decoderv5_4.zip
There are two folders in the zip file: NmraDcc and SoftwareServo
If you have set up and installed the Arduino development code from http://arduino.cc/en/Main/Software (Read on for details)
Then copy both folders to \My Documents\Arduino\libraries on yourcomputer. Then look for Eamples in NmraDcc and you will find Dec_15Serv_2LED_6Ftn,Dec_13Serv_4LED_6Ftn, Dec_10Serv_7LED_6Ftn, and Dec_17LED_1Ftn.
Respectively representing pre defined decoders with 15 Servos F0-F14 and 2 LED F15-F16, 13 Servos F0-F12 and 4 LEDs F13-F16, 10 Servos F0-F9 and 7 LEDs F10-F16, and last 17 LEDs F0-F16 like the original decoder I presented. Servos are controlled from end to end of their throw by the respective Function (On/Off), each end of the Servo throw is controlled by the Start and Stop CV for the Function, and the rate of travel can be set as well—per Function.
Open one of the sketches (programs), set your decoder address, and you are good to go! Once you have loaded the Pro Mini, remove the “//” in the line: “//#define DECODER_LOADED” so it looks like below:
/ ******** UNLESS YOU WANT ALL CV'S RESET UPON EVERY POWER UP
// ******** AFTER THE INITIAL DECODER LOAD REMOVE THE "//" IN THE FOOLOWING LINE!!
#define DECODER_LOADED
And then RELOAD the Pro Mini. This will set up all the default CV’s and then permit you to modify them with your DCC controller of choice. You can even reset the short address in CV 1.
In the first 3 decoders, you can set the function you want per Function Output Pin. Starting at CV30 each function (F0-F16) can be set like this:
Function 0
30 Configuration for the Function: 0=On/Off, 1 =Blink, 2=Servo Control, 3=Double LED Blink
31 Rate Blink=Blinking Rate (higher=faster) , Servo=Move Rate (higher=faster)
32 Start Position for Function=0 (for servos about 26 or so)
33 End Position for Function=1 (for servos about 140 or so)
34 Current Position or Value (For Servos make this the same as Start Position)
Function 1
35 Configuration for the Function: 0=On/Off, 1 =Blink, 2=Servo Control, 3=Double LED Blink
36 Rate Blink=Blinking Rate (higher=faster) , Servo=Move Rate (higher=faster)
...
The Double Blink Function Configuration 3) will alternately blink the designated pin and the pin immediately following (as for a crossing gate). Do NOT set the following pin to a Servo configuration. Special programming was added so starting up many servos would not cause a major current surge for the power supply.
If you change a configuration CV it is recommended that you either reset the Pro Mini or power cycle it after you make all your changes.
You can set CV120 to 120 (decimal) and power cycle (off/on) the decoder and it will reset to ALL CV values in the original load list. You can also edit the CV “Factory Reset” list yourself. It looks like:
VPair FactoryDefaultCVs [] =
{
{CV_MULTIFUNCTION_PRIMARY_ADDRESS, This_Decoder_Address},
{CV_ACCESSORY_DECODER_ADDRESS_MSB, 0},
{CV_MULTIFUNCTION_EXTENDED_ADDRESS_MSB, 0},
{CV_MULTIFUNCTION_EXTENDED_ADDRESS_LSB, 0},
{CV_DECODER_MASTER_RESET, 0},
{30, 2}, //F0 Config 0=On/Off,1=Blink,2=Servo,3=Double LED Blink
{31, 1}, //F0 Rate Blink=Eate,PWM=Rate,Servo=Rate
{32, 28}, //F0 Start Position F0=0
{33, 140}, //F0 End Position F0=1
{34, 28}, //F0 Current Position
{35, 2}, //F1 Config 0=On/Off,1=Blink,2=Servo,3=Double LED Blink
{36, 1}, // Rate Blink=Eate,PWM=Rate,Servo=Rate
…
in your sketch. Change ONLY the value after the CV number in the list.
If you did everything right, you can control your decoder and turn on and off 17 functions at will. You will note that as the decoder powers on, it will run through a test cycle turning all functions on, then all functions off—and only once. If you don’t want this, you can simply delete the test in the code which are:
for (int i=1; i< = numleds; i++) {
digitalWrite(ledpins, HIGH);
delay (tim_delay/10);
}
delay( tim_delay);
for (int i=1; i< = numleds; i++) {
digitalWrite(ledpins, LOW);
delay (tim_delay/10);
}
delay( tim_delay);
You do not need to know to understand the program at all. Simply set the address and load it. You are always welcome to learn more, but it is completely usable as is.
You can get a step by step cookbook for loading the Pro Mini here:
https://forum.mrhmag.com/post/scale-model-animation-8-starting-projects-and-virtual-rooms-for-modeling-12196257
You will need a USB cable to load the program. You can get one here:
http://tinyurl.com/lydcv99
It can be used again and again for more decoders and future projects.
Once you get it assembled and programmed, hook it up to any DCC track bus and power supply, and away you go!
This video will give you another look at the decoder:
The original NmraDcc library was obtained from the “Model Railroading with Arduino” website ( http://mrrwa.org/) which is made available free for personal use under a GNU general public license. This was a version written by Alex Shepherd from 2012. Many thanks for Alex’s work.
Each of the decoder ‘loads”/sketches shown here are completely usable by themselves. With a little more work than just copying and editing you can build complex functions beyond what is presented here. Because this is an Arduino, a “Function” could also read a pin instead of outputting to it. The possibilities for your own special functions are endless!
Comments and appropriate suggestions are always encouraged.
Have Fun. Best regards,
Geoff Bunza