Geoff Bunza geoffb

My activities in Scale Model Animation often lead me to use DCC as a control method for sequencing. This could include building and street lights, even sparking welders and twinkling camp fires. Timing can be done with JMRI scripts (Like this:

) or with programmatic control (Like this:
). Control switches for such projects are a must. Using 4 or 6 function DCC decoders in this regard, can get costly, quickly. But with a little effort, and some low cost components one can build a DCC decoder supporting 17 independent functions for about $5.00, or less, depending what you have on hand.  This version has no CV’s, uses no DCC programming, can be set for any short address in CV1, and controls 17 Function Lines (which I am using to drive the green LEDs in the example below). Interested? Read on! (Latest Rev for this work can be found here: http://model-railroad-hobbyist.com/node/19446)

[attach:fileid=/sites/model-railroad-hobbyist.com/files/users/geoffb/decoder_lit%20small(1).JPG]

Geoff Bunza's Blog Index: https://mrhmag.com/blog/geoff-bunza
More Scale Model Animation videos at: https://www.youtube.com/user/DrGeoffB
Home page: http://www.scalemodelanimation.com

Reply 3
Geoff Bunza geoffb

Building the Decoder

This all starts with a $2.41 Arduino Pro Mini Board, a 6N137 optocoupler, a LM78L05 voltage regulator, miscellaneous resistors and capacitors, and a program and library modified for the job. The Pro Mini and other parts are mounted on a piece of perf board (available from many sources, even radio shack—google searches can be very helpful here). A diagram is included below as well as some key parts that have Digikey (http://www.digikey.com) numbers and prices for reference. 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 green LEDs each with a 10K (10,000) ohm resistor in series 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. Each pin can directly drive at least 40ma at 5 volts, more than enough for several LEDs each.

decoder1.JPG 

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. You should cut off the surface mount LED Pin 13 indicator in the Pro Mini Board or its dropping resistor as it is both redundant and may interfere with the function assigned to that pin. I found that the circuit with the fast 6N137 optocoupler was very sensitive to noise on the DCC lines. My friend Gordon Hoffman suggested adding Capacitor C8 (270pf) and it solved the problem reliably. Other published circuits that I tried were far less reliable. Make sure you place C8 as close to the 6N137 as possible. I soldered the small C8 cap onto the 6N137 pins directly.

Partial Bill of Materials:

Arduino Pro Mini atmega328 5V 16M    (  from EBay:   http://tinyurl.com/kexh66b )   $2.41

(This price varies. I've seen it as low as $2.25. Search Ebay for "Pro Mini." Price often includes free shipping. It should specify an Arduino Pro Mini 5 Volt 16M Atmega328)

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

Other Resistors & caps as needed

-a-small.jpg 

17 Function Decoder Schematic (A4-A6 connections omitted)

decoder.JPG 

der_rear.JPG 

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 DecoderNmraDcc_4

If you have set up and installed the Arduino development code from http://arduino.cc/en/Main/Software  (Read on for details)

Then copy the NmraDcc folder to \My Documents\Arduino\libraries on your computer and copy DecoderNmraDcc_4 to \My Documents\Arduino

Then open the DecoderNmraDcc_4.ino sketch (program), set your decoder address, and you are good to go!

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. While incomplete, it gave me a great start to build this decoder. Many thanks for Alex’s work.

This is partially what it looks like:

#include < NmraDcc.h>

// Working 14 Function DCC Decoder  DccAckPin not needed

int tim_delay = 500;

#define numleds  17

byte ledpins [] = {0,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19};

const int FunctionPin0 = 3;

const int FunctionPin1 = 4;

const int FunctionPin2 = 5;

const int FunctionPin3 = 6;

const int FunctionPin4 = 7;

const int FunctionPin5 = 8;

const int FunctionPin6 = 9;

const int FunctionPin7 = 10;

const int FunctionPin8 = 11;

const int FunctionPin9 = 12;

const int FunctionPin10 = 13;

const int FunctionPin11 = 14;     //A0

const int FunctionPin12 = 15;     //A1

const int FunctionPin13 = 16;     //A2

const int FunctionPin14 = 17;     //A3

const int FunctionPin15 = 18;     //A4

const int FunctionPin16 = 19;     //A5

NmraDcc  Dcc ;

DCC_MSG  Packet ;

#define This_Decoder_Address 17

extern uint8_t Decoder_Address = This_Decoder_Address;

struct CVPair

{

uint16_t  CV;

uint8_t   Value;

};

…and so on!

To set the decoder address, edit the line:

#define This_Decoder_Address 17

And change the “17” to whatever short DCC address you want the decoder to respond to.

While there are hooks in the code for CV and long address support, I haven’t verified or changed any of these additional hooks… yet!

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 away you go! If you did everything right you can set your control for the decoder address 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 torning 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 (Lines 59-68) 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);

This video will give you another look at the decoder:

While only implementing 17 on/off functions, it will eventually be possible to assign different working functions to each pin, from dimming, flashing, servo controlling, to most anything. The processor and memory in the Pro Mini is more capable than most but not all decoders on the market today. Getting the CV read/write capability working (next) should eventually lead to assigning complex functions to each pin—like “open the door, ramp up a light, and sound a sqeak in sequence” or “move to the next turntable track after rotating 180 degrees.” Because this is an Arduino, a “Function Key” could also read a pin instead of outputting to it. And these are the reasons why I started in on this project!

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 tiem in a somewhat neat line.
4. If you don't want to solder this circuit, it can successfully be built on a solderless breadboard (see Dave Bodnar's writeup for an example: http://www.trainelectronics.com/DCC_Arduino/   He also adds a servo control example which you may enjoy!

Comments and appropriate suggestions are always encouraged.

Have Fun!  [smile]
Best regards,
Geoff Bunza

Geoff Bunza's Blog Index: https://mrhmag.com/blog/geoff-bunza
More Scale Model Animation videos at: https://www.youtube.com/user/DrGeoffB
Home page: http://www.scalemodelanimation.com

Reply 0
pierre52

Itching to learn more

Thanks for posting Geoff. I would love to get into this but it looks like a pretty steep learning curve

Peter

The Redwood Sub

Reply 0
BruceNscale

Wonderful Post

Hi Geoff,

Great post. 

I knew it was possible to decode DCC signals..hadn't thought of using the optocoupler to handle the DCC voltages.

I normally use Picaxe for the electronics/animation on my layout.

ignature.jpg 

Happy Modeling, Bruce

Reply 0
Dave O

Gosh ...

... it is like you've opened the door to a whole 'nother world!  Thanks for posting this ... might have to give it a go!  

This would have made a wonderful article ... with some follow-up "projects" could be a bit of a series ....  

Reply 0
Geoff Bunza geoffb

The Learning Curve

Pierre,

There is a learning curve, but BE FEARLESS! ...Well, maybe a little bit fearless. I've helped a dozen or so local modellers start using these cheap little controllers-- anyone can do it. Once you get by the program "loading" and if you haven't soldered much that's the next. But it opens up a new world for you as a modeller. And in this forum there are lots of people who can help too!

Have a go at it! and have fun!

Best Regards,

Geoff

 

Geoff Bunza's Blog Index: https://mrhmag.com/blog/geoff-bunza
More Scale Model Animation videos at: https://www.youtube.com/user/DrGeoffB
Home page: http://www.scalemodelanimation.com

Reply 0
Geoff Bunza geoffb

Using your 'Axe

Bruce,

I do think the timer and interrupt capability on the PIC could handle the job, but you'll have to port the library that i used or write your own. This is why I use the Pro Mini-- it's cheap and there are many libraries already written, that gives a great starting point. I want to model and animate not write code-- I did enough of that professionally.

Best Regards,

Geoff

Geoff Bunza's Blog Index: https://mrhmag.com/blog/geoff-bunza
More Scale Model Animation videos at: https://www.youtube.com/user/DrGeoffB
Home page: http://www.scalemodelanimation.com

Reply 0
Geoff Bunza geoffb

New World Order for Dave

Dave,

This stuff opens up allot of possibilities for modelers in any scale, even beyond model railroading. Once you get the tools on your bench, I havee no doubt that you'll come up with ideas that never even crossed my mind!

By the way this will not be the last version you'll see of this. As I said in the post above, this is just the start for more interesting "decoders" and many more projects. Tune in later!

Have at it Dave!

Best regards,

Geoff

 

Geoff Bunza's Blog Index: https://mrhmag.com/blog/geoff-bunza
More Scale Model Animation videos at: https://www.youtube.com/user/DrGeoffB
Home page: http://www.scalemodelanimation.com

Reply 0
Michael Tondee

Turnout control?

I saw mention of servo control being possible at some point. I know your goal is animation but does this mean this decoder would eventually be suitable for turnout control?

Michael

Michael, A.R.S. W4HIJ

 Model Rail, electronics experimenter and "mad scientist" for over 50 years.

Member of  "The Amigos" and staunch disciple of the "Wizard of Monterey"

My Pike: The Blackwater Island Logging&Mining Co.

Reply 0
Geoff Bunza geoffb

Turnout control and more possibilities

Hi Michael,

My goal with this report was to build a platform-- a starting point -- on which I was confident that more could be built. The next step for me is to fix the CV reading/writing capability in the library-- which is incomplete in this area.

Why? Because I want to create CV pairs for each of the 17 pins in the demo. The first CV would define the "function" of the pin, for example 1- Simple on/off 2- Dim based on value of second CV, 3- Servo control end to end based of 2 other CV values, 4- Blink, 5- Ramp up ramp down (like rotating lights, 6-- more to come!

There is also a much more interesting feature I want-- trigger inputs-- think chuff cam on steroids! For example if a pin were to be switched low to ground (common) it could enable another function, or turn off another function. What I want this to do for me is to turn on/off sounds, and read sensors-- like distance sensors, proximity sensors, light sensors, etc. You might remember I have a great interest in animation. While these decoders can easily be attached to your track DCC system, I expect to have one or more DCC control buses (alternate tracks?) to control animation scenes. I you look at some of my other write ups and videos, you can see animations DCC controlled by a cheap Arduino Pro Mini "DCC Base stations" ( http://model-railroad-hobbyist.com/node/14762). These enhanced DCC decoders will be used there.

You may have to wait a bit for me to get this done and write it up, but you or others can take my work and build on it too. In fact, I'm hoping others join the fun!

Best Regards,

Geoff Bunza

 

Geoff Bunza's Blog Index: https://mrhmag.com/blog/geoff-bunza
More Scale Model Animation videos at: https://www.youtube.com/user/DrGeoffB
Home page: http://www.scalemodelanimation.com

Reply 0
pschmidt700

Geoff

This is an outstanding example of a tutorial. Thanks. In line with Michael's question, I take it that this module would have little issue to sink current for a turnout servo; I'm thinking it could adequately source it too? My Uno has the ability to do the latter.
Reply 0
Eugene Griffin EGRX

Thanks for introducing this decoder

Wow, its been awhile since I programmed a controller, great  idea and price.

Had a flashback when I looked at the specs to the early nineties and a 80C186EA based bored with 32KB eeprom and battery backed up static ram. However, it cost a lot more and had a footprint, literally.

My question and concern is should the DCC bus be used for an ever increasing load of fixed animations? Could there be a risk of fire if an , for example, 8 amp DCC booster is installed?

 

Eugene

 

Reply 0
atanisoft

I wonder if a version of this

I wonder if a version of this could be made smaller to fit inside N scale locos as an alternative to other decoders?

Reply 0
Geoff Bunza geoffb

DCC Bus Load

Hi Eugene,

Quote:

My question and concern is should the DCC bus be used for an ever increasing load of fixed animations? Could there be a risk of fire if an , for example, 8 amp DCC booster is installed?

This decoder loads the DCC bus just like any other decoder with a load. Put enough decoders on any DCC bus and eventually you run out of power. As from my comments above, I intend to run some of my animations and lighting on separate DCC lines apart from the track DCC, and I'll still need to keep track of power utilization.

Best Regards,

Geoff Bunza

 

 

Geoff Bunza's Blog Index: https://mrhmag.com/blog/geoff-bunza
More Scale Model Animation videos at: https://www.youtube.com/user/DrGeoffB
Home page: http://www.scalemodelanimation.com

Reply 0
Geoff Bunza geoffb

N Scale??

Hi,

Quote:

I wonder if a version of this could be made smaller to fit inside N scale locos as an alternative to other decoders?

This was never intended to be optimized for size-- low cost and many modifiable features were my goals. Nonetheless, a 17-function-only DCC decoder suitable for an N scale loco might be a challenge just based on the bulk of the wires and connections!! Might you have an application in mind that is not obvious to me? It could be interesting, but in my applications this is actually quite small enough, especially when you consider that all the LEDs would not be mounted on the board. Thought provoking, though. Thanks for sharing your idea.

Best regards,

Geoff Bunza

 

 

Geoff Bunza's Blog Index: https://mrhmag.com/blog/geoff-bunza
More Scale Model Animation videos at: https://www.youtube.com/user/DrGeoffB
Home page: http://www.scalemodelanimation.com

Reply 0
Geoff Bunza geoffb

@Paul -- Current Sourcing

Hi Paul,

Quote:

I take it that this module would have little issue to sink current for a turnout servo; I'm thinking it could adequately source it too? My Uno has the ability to do the latter.

A servo is usually looking for a current source, but the little Pro Mini has the same 328P chip most versions of the Uno have! So it will source and sink current on demand. The small servos present little load comparatively, so you can drive them directly off a naked pin on either the Pro Mini or the Uno and there are several libraries available to help with servo control. I hope to add a CV controlled option eventually to configure each pin. I'm hoping to make servo control such a feature-- lots to do, but fun to look forward to!

Best regards,

Geoff Bunza

 

 

 

Geoff Bunza's Blog Index: https://mrhmag.com/blog/geoff-bunza
More Scale Model Animation videos at: https://www.youtube.com/user/DrGeoffB
Home page: http://www.scalemodelanimation.com

Reply 0
Brent Ciccone Brentglen

Thanks for Posting this

Thanks for posting this. I did buy an Arduino starter kit but haven't done much with it. This should motivate me to learn more about it.

 

 

Brent Ciccone

Calgary

Reply 0
Bernd

Very Interesting

Geoff,

Very interesting write up Geoff. Following along and getting ideas for animations I'd like to try out. It's inspiring me to get get going on a layout.  But I'll wait till you have it all together and I have something that resembles a layout. Still thinking an animated rock crusher loading HOn30 cars and an animated coal mine operation loading HOn3 hoppers automatically.

Carry on.

Bernd

 

New York, Vermont & Northern Rwy. - Route of the Black Diamonds - NCSWIC

Reply 0
Geoff Bunza geoffb

@Brent-- Starting Up

Hi Brent,

If you get to some non-obvious roadblock... ask questions. Most of the basics are straightforward. You'll complicate things later when you start wanting to do more and more! 

And then you may find out.... it CAN be done!

Have fun!

Best regards,

Geoff

 


 

Geoff Bunza's Blog Index: https://mrhmag.com/blog/geoff-bunza
More Scale Model Animation videos at: https://www.youtube.com/user/DrGeoffB
Home page: http://www.scalemodelanimation.com

Reply 0
Geoff Bunza geoffb

@Bernd-- More to Come

Hi Bernd,

Interesting indeed... I model with HOn30 too, and am trying to work into a dual guage scene (animated of course!).

Best Regards,

Geoff

 

Geoff Bunza's Blog Index: https://mrhmag.com/blog/geoff-bunza
More Scale Model Animation videos at: https://www.youtube.com/user/DrGeoffB
Home page: http://www.scalemodelanimation.com

Reply 0
Michael Tondee

I'm good with the hardware end....

I'm a ham radio operator and have built many a circuit over the years including a 50 watt RF amplifier using 1205 size SMD's hand soldered to the board so I'm good with the hardware end. I also know my way around a PC pretty well but beyond that, the software and programming end of these little devices is greek to me. I built an antenna rotator positioning control box that was designed around a BASIC STAMP but the program to run it was pre-written and I merely had to load it into the stamp. Low cost DIY hardware does interest me though so I guess I should find the time to learn a little more about the programming end.

Michael

 

Michael, A.R.S. W4HIJ

 Model Rail, electronics experimenter and "mad scientist" for over 50 years.

Member of  "The Amigos" and staunch disciple of the "Wizard of Monterey"

My Pike: The Blackwater Island Logging&Mining Co.

Reply 0
Geoff Bunza geoffb

@Michael

Hi Michael,

In my clinics you would likely hear me say "As a modeler, don't first learn programming... learn how to copy and edit." As stated in the article above, there's all the code to implement this version as is, and references to get to started and how to load it, step by step. Any unintentional gaps or omissions I can cover with Q&A. With your experience this should be straightforward. You MIGHT want to learn more and go beyond that, but that's up to you alone. I've worked with modelers who have less experience than you to get up and running.

Sometimes, people suggest things that are really costly, and I don't want to try them because if they don't work I will loose too much. Even if one considers this a risky proposition, it's a low cost experiment, and you can take it as far or as little as you want. In my experience the return has been worth it-- you can see some of the results in my other blogs:

http://model-railroad-hobbyist.com/blog/geoff-bunza

and in these videos:

https://www.youtube.com/user/DrGeoffB

Have Fun! Best Regards,

Geoff Bunza

 

 

Geoff Bunza's Blog Index: https://mrhmag.com/blog/geoff-bunza
More Scale Model Animation videos at: https://www.youtube.com/user/DrGeoffB
Home page: http://www.scalemodelanimation.com

Reply 0
Michael Tondee

One suggestion....

from the hardware point of view would be a PCB.  Nothing wrong with point to point on a perf board but a PCB would make life easier when making more than one decoder. Where is Alan when we need him...LOL 

Michael

 

Michael, A.R.S. W4HIJ

 Model Rail, electronics experimenter and "mad scientist" for over 50 years.

Member of  "The Amigos" and staunch disciple of the "Wizard of Monterey"

My Pike: The Blackwater Island Logging&Mining Co.

Reply 0
LKandO

Busy

Quote:

Where is Alan when we need him...LOL

Busy making Photoshop files for Rob.

Seriously Geoff, if you want PCB and mask art isn't your thing then contact me.

Alan

All the details:  http://www.LKOrailroad.com        Just the highlights:  MRH blog

When I was a kid... no wait, I still do that. HO, 28x32, double deck, 1969, RailPro
nsparent.png 

Reply 0
Geoff Bunza geoffb

@Alan

Hi Alan,

The PCB should be very doable-- there really isn't much. One would have to pick the right components, sources, and footprints. I drew the schematic with the Eagle PCB tool, but didn't pay attention to packaging since I had no need for PCB's myself. If anyone wants the Eagle schematic file I'd be happy to post it. The LEDs and dropping resistors would need to be changed to solder pads (unless you wanted then as a diagnostic tool version).

There seems to be more interest in this than I had imagined. A PCB board might be warranted.

Thanks for the interest.

Best regards,

Geoff Bunza

 

Geoff Bunza's Blog Index: https://mrhmag.com/blog/geoff-bunza
More Scale Model Animation videos at: https://www.youtube.com/user/DrGeoffB
Home page: http://www.scalemodelanimation.com

Reply 0
Reply