SMA10 – Build a 17-Function DCC Decoder for about $5

geoffb's picture

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: http://youtu.be/RXpvp5mIXvU?list=PL4dHfZjHc9t-pvctGQzSuOXBLG1M42xbS) or with programmatic control (Like this: http://youtu.be/zlcdJKXj_YI?list=PL4dHfZjHc9t-pvctGQzSuOXBLG1M42xbS). 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 )

Comments

decoder for one loco

Dear Geoff,

Thank you for this great article. I do not have so much affinity with electronics, however, I would like to modify my locomotive to be DCC compliant. I have found plenty of tutorials, how to build in the decoder into the loco, however, I can not find the tutorial, how to build the decoder. You have built the 17 function decoder based on arduino. I probably need only one function for my loco.  Is rescaling your decoder into one function be sufficient? The decoder has to be small in order to fit it into the loco body.

Any hint will be highly appreciated.

 

best regards

Johny

...

Each feature in your locomotive would be a function - Motor, headlight, classification light, mars light, beacon light, cabin light...

With you experience, I'd recomend any of the $15 run of the mill decoders on the market unless you want sound.  You'll get the project finished this way!

---------------------------------------------------------------------------------------------------------

Benny's Index or Somewhere Chasing Rabbits

geoffb's picture

@Johnny re:decoder for one loco

Hi Johny,

You did not say what scale loco you were using, but generally, this decoder would be a hard fit for HO scale, and likely very difficult for N scale or smaller. But the bigger problem is that the decoder as described doesn't have much capability for motor control of the loco. It is possible to re-work the programming, but as Benny said in the preceding message, you can get a very compact, modern DCC decoder for 15-20 dollars that will afford many reasonable control features for loco control beyond this decoder. Another issue is that the voltage and current requirements for motor control are beyond the simple interface that one pin of the Pro Mini can handle. Again, there are ways of dealing with this that are beyond the scope of this simple design.

Have fun!  smiley

Best regards,

Geoff Bunza

Arduino Block detector

Hi Geoff,

 

Thanks ever so much for bringing these cards to the attention of us modelers, my interest is in the longer term for automation of sound and lighting etc,

But in the shorter term I am interested in detection using current sensor, IR Leds etc. I have a program that is based on a program written on another forum by a chap with the user name "Antogar" (Whom I owe many thanks for posting the sketch), my program is now very different from his original, but the key element I used s the sensor message block below and the "Loconet.h" library and this is because I could directly report back on loconet the status of the Arduino input pin.

The sketch uses all available pins on the UNO as input (both analog and digital) and it works very well, however it has a 255 address limitation, I am no guru in C, I am self taught in a rapid learning curve over the past 6 weeks,since reading your article!......thanks :)

I don't claim to understand how to interact with loconet, but I would like to see if you or another reader could take a look and see if you can work out where I am going wrong with the addressing. This portion of the code I did not write, it works in the original sketch so I have simply used it as a "module" in my own sketch to get the job done. Its the last bit I need to learn to turn around and say this sketch is full developed by me and thus I have the right to give it freely to the wider community for use at their leisure.

void sendALLsensors ()
{
  int tempaddr;   \\ used just for this module to as a place holder for the address
   for (i = 0; i<16; i++)
     {
        tempaddr = StartAdd + i;  \\ StartAdd is an int defined in the opening and is a hard coded board address
        IN1 = tempaddr;
        IN1 = IN1 >> 1;
        bitClear (IN1,7);
        bitSet (IN2,6);
        bitWrite (IN2,5, bitRead(tempaddr,0));  \\this is where I am assuming the address is written, I feel it             // should be broken into two parts a hi and lo  to make up the long address.
        bitWrite (IN2,4, !sensorValue[i]);
        sendTXtoLN (IN1, IN2);   
       }
 
  }

geoffb's picture

@Ghost re:Arduino Block detector problem

Hi Ghost (name?),

You have certainly crossed the "modeling" line into sketch/code development-- a daring adventure not for the faint of heart!

however it has a 255 address limitation

Since your address definitions are int declarations implying 16 bit addresses, and you see a 255 limitation, it is a good bet that somewhere you have used a byte or char variable with a 16 bit address variable (eg. byte = int). You may also have used a function that returns a byte or char variable type. What type declarations are used for IN1 and IN2?

Other than these guesses, you will need to zip up all your sketches, .h and libraries you use and post them, to really answer your question. Before you do that, look closely to see if you are mixing int's and byte's in the wrong way. This is a common problem anyone can have.

Have fun!  smiley

Best Regards,

Geoff Bunza

Hi Geoff, I think you might

Hi Geoff,

I think you might be onto it, cant believe I missed it.

In my opening "definitions section" of my sketch everything is int, except "IN1" and "IN2" which are byte.

I have changed these to be "int" and will test over the weekend. Thanks very much. I will post both my output sketch and the input sketch for Digitrax LocoNet when I am complete.

Thanks

Again.

Tyrie,

AKA Ghost

 

Hello I have been trying for

Hello

I have been trying for couple weeks to get program into Pro Mini and the software vprogram says program must end in(.ino) cannot  seem to find location to enter that in program.  What am I doing wrong?

Thanks

Gene

geoffb's picture

@Gene re:ino problem

Hi Gene,

The expected file name extension that the Arduino editor is looking for is one with ".ino" That is what it is trying to tell you. So, if you created your Sketch (program) in a text editor and it was named lights.txt in the editor, you can save the text file as lights.ino for the Arduino editor with no other changes. You could also just copy all the text and paste it into the Arduino editor in a blank/new window. When you save your work in the Arduino editor, it automatically adds the .ino suffix to whatever you name your work.

'Hope this helps. Have fun!  smiley

Best regards,

Geoff

Missing library

Hello Geoff,

very nice job. Just a small comment, I uploaded all the programs from the link mentioned above but it looks like there is a missing file "softwareServo.h" since I got the compilation error. Please any advice where is this file located.

Here is the log:

Arduino: 1.6.5 (Windows 7), Board: "Arduino/Genuino Uno"

AccessoryDecoder_10Servos_7LED_4Function.ino:10:28: fatal error: SoftwareServo.h: No such file or directory
compilation terminated.
Error compiling.

  This report would have more information with
  "Show verbose output during compilation"
  enabled in File > Preferences.

 

Thank you George

geoffb's picture

@George re:SoftwareServo Library

Hi George,

I suspect you forgot to copy the "SoftwareServo folder also contained in the zip download into the Arduino/libraries/ folder (usually found in My Document/ in MS Windoes machines). Here is the link to the zip file again, for your convenience:

http://model-railroad-hobbyist.com/sites/model-railroad-hobbyist.com/fil...

Please note you must use this version of the SoftwareServo library, as I have modified it to be able to support 17 servos simultaneously.

Have fun!  smiley

Best regards,

Geoff Bunza

 


>> Posts index


Journals/Blogs

Recent Blog posts: