Jump to content
 

DCC Function Decoder for Arduino and ATtiny


Recommended Posts

DCC Function Decoder for Arduino and ATtiny

 

In previous posts on Arduino DCC Decoders I have been using the word 'function decoder', which has led to some confusion. The decoders posted so far are what I should have called accessory decoders.

An accessory decoder listens to a DCC accessory address and switches an output or drives a servo. One Arduino DCC decoder can be configured to listen to max 16 DCC addresses.

A function decoder listens to one address (a locomotive address, or as the NMRA calls it, a multi-function decoder) and it switches locomotive functions, which are called F1, F2, etc. on command stations or handheld controllers.

 

Now that this is cleared up ... here it is ... an Arduino and ATtiny DCC Function Decoder.

 

And, if you like it small enough to fit in an HO wagon (with a diode bridge and a capacitor as a power supply), this code also works with the 22x18 mm ATtiny boards that can be had for under $1,50 here.

 

Of course the DCC signal needs to be fed to the Arduino / ATtiny. For that I use this opto coupler circuit. If it needs to be smaller to fit inside a wagon, it is also possible to use a Zener diode and a resistor.

 

Configuration is easy. In line 1 of the code state the loc address you want it to listen to. In the lines that follow, define the output pins for F0, F1, F2 ... up to F12. Not all need to be defined, just the ones that you want to use. On the Arduino outputs 3-19 (14-19 are A0-A5) are available. On the Attiny P0, P1, P3, P4, P5.

 

int decoderAddress = 1830; // This is the decoder address, change into the number you want.

#define F0_pin 13 // Define the output pin for every Function number in use. 13 has on board LED.

#define F1_pin 0 // Available pin numbers: 3-19

#define F2_pin 0

...

#define F12_pin 0

 

 

Click here to go the blog post on the Arduino and ATtiny DCC Function Decoder that has the download link.

 

 

23514010eu.jpg

Link to post
Share on other sites

New versions of Arduino and ATtiny DCC Function- and Accessory Decoders are available.

DCC Function Decoder
The possibility to use the direction of travel of the loc (forward or reverse) to switch two outputs has been added. This makes it possible to switch head and tail lights depending on the loc direction.

DCC Accessory Decoder
A mode has been added to switch signals using two pins. The outputs are inverse, if pin1 is HIGH, then pin 2 is LOW. Four modes are available now:
mode 1 - Continuous output. OFF at startup.
mode 2 - One shot, with a timer. OFF at startup.
mode 3 - Flasher with 2 outputs that alternate based on 2 timers in ms. OFF at startup.
mode 4 - Signal with 2 outputs that always are inverse. At startup one of them is ON.

IMPORTANT:
The output logic has been changed with respect to the previous versions. In the new versions, the Arduino output pin is LOW when accessory or function is switched ON, and vice versa.

If you need it the other way around ... it is not difficult to edit this in the code, just do a 'find' for all 'digitalWrite' instructions and change them.

The download link is available on the software page. The download contains all Aduino decoder versions, S88-, sniffer- and sound software.

Link to the blog with a download link to the software package
 

Link to post
Share on other sites

  • 4 months later...

Hello Rudy,

 

Brilliant work!

 

The only thing I am missing in your explanation is where the 5V for the ATtiny comes from. Can you clarify this, please?

 

Also I am very curious if you have actually used this as a decoder since building it and how it worked in a actual wagon instead of your test rig.

 

This could actually be just what I need to add light to my N-gauge coaches.
Obviously that would be easy enough to do without a function decoder by taking the power directly from the track and using a bridge-rectifier and a few bits and pieces to make it work, but I would like to be able to turn the lights in the coaches on and off when I please. So the lights can be turned off when the coaches are not in use but waiting at the platform or when they are stabled in the carriage sidings. Also this would open up possibilities on things like flickering fluorescent tubes, toilet lights, guard compartment only lit on tail end of train (including tail lamp) and much more!
 

Now all I need to do is measure up a coach and see if it will actually fit...

Link to post
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...