SMA12 - 17 Channel Configurable Multifunction $5 DCC Decoder For Servos

geoffb's picture

One of my earlier entries:  SMA10 – Build a 17-Function DCC Decoder for about $5 ( http://model-railroad-hobbyist.com/node/19070 ) generated a considerable amount of interest regarding the possible enhancement for controlling Servomotors (Servos). This is my next version of a 17 Channel Multifunction DCC Decoder based on a low cost $2.56 Arduino Pro Mini. This version supports configuring each of the 17 function pins for On/Off (LED/TTL) Control, or Configurable Blinking Control, or Configurable Servo Control, or Configurable Pairs Blinking Control. Yes, that does mean it can support 17 servos, each with rate, start point, and end point setting via DCC CV’s, per pin, as well as new LED configurable functions. Read On. Additional doc found here: http://model-railroad-hobbyist.com/node/19775 There is another decoder version added herein. Look for "New Decoder Version to Control Lighting Groups" in Page 12 of the Comments: http://model-railroad-hobbyist.com/node/19446?page=11   The most recent Update can be found here: SMA20 New Low Cost 17 Channel DCC Decoders with PC Boards & Dual Motor, LED, & Servo Control    http://model-railroad-hobbyist.com/node/24316

Comments

geoffb's picture

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 ( http://model-railroad-hobbyist.com/node/19070 ) 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: http://model-railroad-hobbyist.com/magazine/mrh-2012-02-feb/points_of_light

The boards I use can be found here:  http://tinyurl.com/lkhpkmd     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):

/sites/model-railroad-hobbyist.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[i], HIGH);

     delay (tim_delay/10);

  }

  delay( tim_delay);

  for (int i=1; i<= numleds; i++) {

     digitalWrite(ledpins[i], 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:

http://model-railroad-hobbyist.com/node/17244

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

 

 

servo shield

would the adafruit servo shield,which can control 16 servos work with the arduino pro mini???

 

Also Geoff what kind of relay(solid-state) would you recomend for an electro-frog.

 

Geoff maybe mrh needs to setup a seperate forum for DIY electronics/animation for DCC/DC.

 

geoffb's picture

@Getsmart / noname

Hi, 

The servo shield is electrically but not mechanically compatible with the Pro Mini.  If you want to use "shields" with an Arduino for assembly convenience, use the Arduino Uno board (bigger, more $$, but shield compatible) and the Uno uses exactly the same processor as the Pro Mini - the mega328P.

This means the sketch (software) provided herein should work just fine.

You can use a 4.5Volt DPDT DIP relay directly driven by an Arduno pin. Check Digikey or, Mouser, or Allelectronics for the relays. I had considered another option to pair a second relay control pin as another configurable function, but have no immediate need myself. Also am considering a 3 position servo control in the same thinking.

Best regards,

Geoff Bunza

 

Dave O's picture

Nice update Dr. Geoff ...

Still awaiting parts to be delivered, so that I can give this stuff a whirl.  Really, it is wonderful to have folks such as yourself and the others who have posted these types of "projects" around to help minimize the "risk of failure" by those of us who want to give it a go.  Thanks again, for posting.

Thanks for this Geoff

Geoff:

I just want to say thanks for this!

I have multiple projects where I want to use servos planned.  I have begun to work on the first one using the Zimo MX82E controller.  But this cut the price way down. I placed quite a few orders last night!

This is forcing me to use my very rusty EE and programming background - a good motivator.

Thanks again.

Tom

Babbo_Enzo's picture

It will nice if 8 pins are

It will nice if 8 pins are devoted to input like fascia switches , and the other 8 pins are for servo.... and ...

- how to drive 8 frog switch ???

- how to report turnout position?

Well ... maybe to much!

Thanks anyway for your motivation! Great source and article!

 

geoffb's picture

@Dave, Tom and Enzo

Hi Guys,

You are most welcome.

Have fun.

Best Regards,

Geoff Bunza

geoffb's picture

Opening the Floodgates for Suggestions

Hi Enzo,

It will nice if 8 pins are devoted to input like fascia switches , and the other 8 pins are for servo.... and ...

- how to drive 8 frog switch ???

- how to report turnout position?

These are completely appropriate suggestions/requests. First, a couple of comments:

I am considering building (reprogramming) a version of the decoder, such that when the sevo has traveled to one end or the othe, a second set of pins corresponding to each servo would indicate 0 or 1 (Ground or +5Volts) and these could be used for signaling, or to drive a LED indicator, or to drive a small dual-inline-package (DIP) relay like: http://www.allelectronics.com/make-a-store/item/rly-625/5-vdc-dpdt-dip-r...

This would enable  you to use the servo to throw a turnout, power the frog, and indicate the position of throw. Obviously it would use anther pin (of the 17 available) per servo, so it would be limited to controlling 8 servos.

Likewise, a fascia switch could be used to control turnout position, but it would also use another pin per servo (now 3 per servo) so a total of 5 servos could be supported. But it would seem to me that the fascia switch would substitute for DCC control, so only the endpoints and throw rates would use the DCC interface.

Are these versions useful to modelers?

Now for opening the floodgates! I would like to ask what people might like to see for alternative feature sets? Since some of these are not what I would use these for (animation being in my foremost thinking), let me know via this forum, what might be worthwhile, and as time and interest permits, I might be able to make these available for modeler use! You are prompted to think beyond turnout control, but please realize that I don't want to spend all my modeling time doing updates for these. For example, how would you envision DCC control of a 3 position semaphore? 3 DCC functions?

I would also like to encourage others who have found new uses for these, and/or developed new functions for these to share their results and work too! In fact, I very much hope this will spur more modelers on of all interests to try these out. I have no vested interest in this, I just love to see people get enthusiastic in what they do.

Best regards,

Geoff Bunza

 

 

Better Mouse trap..and they will come knocking at your door

You could have them connected to your fascia and handle more than 8 inputs then send out a communication signal (radio/whatever) to multiple receivers which each could control 16 servos/relays/ir-dots/crossings/semaphores/dancing bears leaving foot prints in the mud/light-dark detectors/sound/lights/smoke/camera/action/bombs bursting in air/a rockets launch red glare/flags a waving/ air  flow/water flow/lighting effects/turnout control/toilets flushing/turntables turning/cows isa mooing/freshly learned fishermen fishing/frying pans frying by the camp fire/

<noun> <verb>/ <noun> <verb> <object noun>/ if <this> then<verb>/do while<condition> <action verbs>/         ......etc. 

Have you seen what those Europeans have been doing with their animations.  Where as we in North America have been procrastinating, they are procreating, We have had our heads in a box, so lets think outside the box.

Geoff and the others  along the way have given us a means by which we can build our own programmable stationary decoders (mobile not yet, footprint is too big) with multiple connectivity across the layout and each with multiple functionalities.  The possibilities are enormous.   Mobile maybe yet still to come.

Jumping Gee Wilercures Batman.

 

Dave O's picture

Turnout Control with servos ...

... is something that I could see myself doing.  Initially, the plan is to just manually operate them from the fascia, but having a controller perform the actual operation opens up some interesting possibilities.


>> Posts index


Journals/Blogs

Recent Blog posts: