# made an arduino based simple dcc decoder -- and it seems to work



## Severn (May 13, 2016)

If you poke around on the internet, you can find many DCC DYI projects. Some months back I looked at this one and bought all the parts from digikey, where they then sat in a box until a couple of days ago.






SMA10 – Build a 17-Function DCC Decoder for about $5 | Model Railroad Hobbyist magazine







model-railroad-hobbyist.com





But just as I was about to embark on that, I ran into this other DCC DYI project -- and I liked it a lot more because it seemed simpler. I had the parts also...









Fun with Arduino 29 DCC Accessory Decoder


Modern model railroads are digital controlled, using the Digital Command Control (DCC) protocol, whereby data is embedded in the AC voltage that is put on the track to drive the trains. DCC accesso…




rudysarduinoprojects.wordpress.com





Not being a real hardware guy, I failed the first go to make the circuit and it didn't work. In fact it killed the track signal on my little 3 ft test track. (connected to a DCC++ system I also built)

Reading through the comments on the page above I came upon this schematic, redid the wiring -- and low and behold it worked!









Software


Traincontroller Gold File including Graphics (October 2015) This is the download link for the TC Gold file, with the icons and backgrounds graphics. Please copy the yrrg file to the folder where yo…




rudysmodelrailway.wordpress.com





So the set up is a PC (laptop) with the DCC++ system on one USB port. The second port as the arduino development environment with the serial monitor running. I simply connect to the track in both cases with some alligator clips.

In the "middle" is JMRI -- and on the Arduino side the uploaded "DCC Monitor" example from the code.

The code is from the project but appears to me to be a copy of this one:









GitHub - MynaBay/DCC_Decoder: An Arduino library for creating NMRA DCC decoding devices.


An Arduino library for creating NMRA DCC decoding devices. - GitHub - MynaBay/DCC_Decoder: An Arduino library for creating NMRA DCC decoding devices.




github.com





(in fact if you google 'github dcc decoder software' or some variant, you'll hit a lot options which may or may not be applicable)

Anyway -- in the example is the DCC Monitor and so that was uploaded to the arduino ... 

Then the entire thing connected, the jmri power on to the track -- AND then if I hit say "F8" -- the DCC indeed appears to spit out the bit representation of the DCC packet. Very good!

(see this: https://dccwiki.com/Digital_packet)

Finally if you don't want to build anything, you can purchase some premade boards here possibly.



DCC Interface – Model Railroading with Arduino



So the question is why? well its just for tinkering around but in theory you could make your own accessory decoder or something of that nature and some have done so.


----------



## wvgca (Jan 21, 2013)

i did a mobile or loco based DCC decoder some years back .... based on the MERG ones .. cheap to make, i -think- under ten dollars ... no sound though ..


----------



## Severn (May 13, 2016)

Yeah you guessed it. Unfortunately my lack of HW skills hurts me here.


----------



## Severn (May 13, 2016)

Here's an update & work bench pic. Using DCC++, the home made DCC decoder, an old stewart engine stripped down. I was able to put in a quadrature encoder (a magnet, detectors on a pcb) which sends an interrupt to the arduino as it rotates. This goes into a different arduino metro mini at the moment than the DCC decoder one (pic below might help) -- that mini has the same motor shield as the DCC++ system and connects up the motor. It has two power channels and i only need one -- but it works ok for now in my frankenstein like experiments.

Anyway little hard to picture with text so see pic below but I have the track power -- really DCC going into an AC to DC chip (middle of pic, the red, yellow and black alligators) -- and this goes into the shield. The minis though are still on USB power (not on so not plugged in at the moment). With the whole kit and caboodle wired up I can capture DCC byte codes and through the second arduino's serial monitor make the motor go various speeds by way of a short program i wrote to enable the motor shields pwm at various levels -- by hand control today.

And so then with quad board I can get the RPM of the motor ... the main reason to do that is for some motor control using PID algorithms. This is an alternate approach to BEMF (back emf) to get engine rpm or rotations. Previously on a bench O-gauge motor I've implemented both a homebrew IR reader style RPM detector and the back emf. The IR should be more accurate -- it was on the bench although they were aligned nicely in the "middle" the motors rpms. They fell off a bit "on the ends" as best I could tell. I didn't really delve into it though. But, getting back to the project at hand...

In theory then I could combine them which is what I'm working on next.










From the digital scope at the top, the next thing on the left down is the DCC++ base. (track is above, behind). Below that is the homebrew DCC detector with the mini. Not much to see there, a chip and some resistors really that feed into the interrupts again on the arduno. The software converts that to DCC bit/byte codes essentially. The bachmann dc unit i use to power the track through the DCC++ is next. Over on the right then is second mini -- i had this wired separately to the shield but what you see is first "DCC decoder" mini wired up now in my ongoing attempt to put it together. Then the board with the blue connector next to that is the motor shield from pololu. Then the stripped down engine. The motor is the middle of the frame -- the ends are the brass weights for flywheels. You see the black and red clip ons on the left of it? -- that's to the quad encoder board. I bought that from pololu also. I had to cut the engine pylon slightly -- really i filed it the metal is soft for room -- took the whole bit apart, and put the drive shaft through the whole of pcb of the quadrature encoder. The mounting of the pcb is done at the moment with sticky tape. On that end the engines flywheel gets the magnets and the detectors are on the board. Well you can't make any of that out but it's there. I glued the magnet on to flywheel.

Eventually with luck the arduino and pwm boards will sit on top in a long row between the two engines pylons which are a bit hard to make out. Originally these pylons held a long pcb from stewarts which contained the minimal digital circuitry and leds for dc, theres also an 8 pin expander port for DCC conversion. The entire thing is 6+ inches in length but perhaps only near 3/4" wide. The shell will not go back on with these boards in that area as they are too large so this is experimental. In order to make the shell work i'd have to combine and miniaturize the various parts possibly with FPGA and that's well outside of my ability.

So this is for fun and learning only...


----------

