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

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 )
>> Posts index
Navigation
Journals/Blogs
Recent Blog posts:
Comments
Perhaps I found it
Geoff,
I found .ino files in the examples folders. They aren't quite the ones you described, but I think they're it. Now its a question of the suitability of a Pro Micro instead of a mini.
Craig
@Craig re: Arduino Micro
Hi Craig,
Geoff Bunza's Blog Index https://model-railroad-hobbyist.com/node/42392
More Scale Model Animation videos at https://www.youtube.com/user/DrGeoffB
Home Page: https://www.scalemodelanimation.com/
$5 ardino
I guess I am about as dumb as a box of rocks, worst in the box. Can you set this up without a computer,? I have a lot of servos, had planned on using IR switches and relays to do the work that I planned, IR switch kick a turn out and relay to pwr different track, then the next and so changing about 6 or 8 tracks in and 6 or 8 tracks out. 50 years ago did the same with 4 tracks with reed switch's ( burglar alarm ) my mind is fuzzy, I like the Arduino switch and especially the $5 dollar
ardinuo
dc only
Program Arduino
Short answer is no you need a computer to run the software (IDE) that programs the Arduino.
For the long answer, you may have resouces in your area that can help. Find if you are near a makerspace or hackerspace, someone there should be able to help. They likely have a computer that you can use and it may already have the IDE loaded and the cables necessary to connect from the computer to Arduino.
I definitely recommend reading: http://model-railroad-hobbyist.com/magazine/mrh2016-12-dec/arduino, and the associated bonus extras. I would not worry about reading all the projects, but the pages 1-16 give a good background.
The directory of makerspaces is at: http://spaces.makerspace.com/directory, and you can get to the directory of hackerspaces at: https://wiki.hackerspaces.org/List_of_Hackerspaces. The two places are very similar, I really think the only reason for makerspaces, besides being sponsored by make magazine, is the negative connotation of the word hacker. There are also other options, look around for an Arduino "class" at a local community college, also try your local model railroad club likely someone there is already using Arduinos.
The problem with these options is when you need to debug you'll need the computer connected to the Arduino and hooked up to the circuits. So I would look at getting an old laptop, I have a windows XP that works fine with the IDE. You might even find one at an electronics recycler in your area, and if you are lucky they might even give it to you. Or maybe goodwill or salvation army, the laptop does not need to be very powerful, just will be slow in booting.
Please note thatSMA20 New Low Cost 17 Channel DCC Decoders & Dual Motor,LED, & Servo Control Updated: 6 Fntns/Pin & New Featureshttp://model-railroad-hobbyist.com/node/24316is the current and up to date entry for these decoders
Really very helpful post
Hello Geoff.
Returning to OO gauge after many years, (retired now so have time for it) I was keen to exploit all the new facilities afforded by modern software, DCC, arduino microprocessors et al when building my new railway layout. I've used arduino nanos in recent years for many other automation projects and was (like other contributors here) wondering how I might use the arduino processors with the NMRA control standard and my new Hornby Railmaster system which is a revalation. If I tell you that my last railway was a three rail Dublo system as a lad then you can imagine the huge leaps in understanding I've been exposed to recently. Sorry for long intro but felt the need to declare my background interests. I found your 17 function project a month ago and have already built my first decoder. This is a most useful development and I thank you for sharing this project; I realise it is a few years old now but its new for me!
I have already developed an IR remote and "nano" controlled stepper motored turntable which works well but was independent of my Railamster DCC system. Well not anymore. I've updated the turntable program to monitor outputs from your 17 function decoder and the turnatble can be controlled by either or both the Railmaster DCC software or the IR remote. Why both? well the Railmaster sotware lets you automate the railway by creating programs (simple macro recording) to make locomotives move from any position on the layout to any other, switch points and set signals and now, thanks to your decoder, move the turntable.
A big thanks from me Geoff, you've moved my tech understanding forward a huge leap.
All the best
@BucksBiker
Hi Bucks (name?),
Geoff Bunza's Blog Index https://model-railroad-hobbyist.com/node/42392
More Scale Model Animation videos at https://www.youtube.com/user/DrGeoffB
Home Page: https://www.scalemodelanimation.com/
New projects
Thanks Geoff. l started to look at your other contributions and there's a lot to take in.
You might be interested in the PCA9685 16-Channel 12-bit PWM Servo Motor Driver I2C Module For Arduino from Banggood (£2.44). I've just taken delivery of a few of these and am experimenting with them. Huge potential actually. I'm planning a second 17 function decode to use with these boards. You can control up to 1024 servos (over the top I know) but as I say, potentially usefull for railway accessory animation. Far less and simpler (for me to understand) code required too. I can produce C++ code (I gues I'm an average or below average coder) but found it difficult to unpick your code for the servo control versions of the decoder. You most probably know of this device but if not I can recommend it. It took me just 30 minutes to have a servo connected up in test mode to the PCA9685 and the Arduino Pro Mini.
Enjoy. All the best
Paul
@Paul. RE: PCA9685
Hi Paul,
Yes, there are a couple of I2C “extender” chips that people are using. In my own work, I have not found need of them. Pro minis have dropped below $2 each and having all the control logic in a single processor just isn’t a modeling requirement, let alone the complexity and bandwidth load it brings. I’m glad you bring your experiences here because other modelers might have precisely the same needs as you present — thanks!
Geoff Bunza's Blog Index https://model-railroad-hobbyist.com/node/42392
More Scale Model Animation videos at https://www.youtube.com/user/DrGeoffB
Home Page: https://www.scalemodelanimation.com/
Re PCA9685
Hello Geoff
I absolutely understand your viewpoint regarding the Pro Minis having all the logic needed at low cost. I guess it's my 40 years of flying RC aircraft that blinds me to reality when I see that so many of my servos can be controlled from one board! I also like the idea of controlling the twelve servos I need for my three planned level crossing using simple code I can understand while retaining the 17 functions. Sorry Geoff, no critisism intended. I did say I was a below average coder. However, it does pose a question which I hope you haven't had to ansewer before (if so please provide the link).
With regard to the code for your basic 17 function decoder, one comment states "You MUST call the NmraDcc.process() method frequently from the Arduino loop() function for correct library operation".
Literally how often should this call be executed as I was hoping to add some code for the PCA9685 to the loop?
Also, probably a silly question but regarding the notifyDccFunc void, how does it get called? it doesn't appear in the loop void. Is it implicitly called by the NMRADCC library code? These questions will for sure expose my inexperience but hopefully you can find a moment to humour me with this.
Again, I apologise if you've been thorugh this with other members.
Kind regards
Paul