Last Updated:27/04/2024

Project 6 - ESP32 DCC Accessory Decoder

Projects >> Project 6 - ESP32 DCC Accessory Decoder

ESP32 DCC Accessory Decoder


On my layout, The Isle of Mudd (IOM), my Accessory decoders tend to control sequences of items so for my lift bridge the decoder first sets the signals to red, closes the gates, then raises the bridge. I could do this using a number of decoder addresses in the conventional way but I want to press a single button and the Arduino then takes control of the sequence.

I started to look into using an ESP32 instead of an Arduino as not only are they very powerful, small and cheap, but the added advantages of I2S, bluetooth and built in WiFi meant that there was a lot of extended possibilities. Also with RTOS it meant that I could create multiple tasks for functions and allow the ESP32 to look after all the timings


DO NOT CONNECT YOUR ESP32 DIRECTLY TO THE TRACK

All my decoders are built using the circuit at https://www.digitaltown.co.uk/79DCCDecoderCircuit.php

The components are very cheap and can be built up in minutes on a bread board. For my finished project I have soldered the components onto vero board and have the ESP32 sat on some headers.

The circuit soldered on Vero Board.

The blue wires connect to the track/or my DCC test bed.
The headers to the right of the board connect to some neopixels, a servo and a serial UART MP3 player

ESP32 DCC accessory Decoder Circuit

This is the board with the ESP32 plaugged in, the DCC signal comes in on pin 2 in my circuit.

ESP32 DCC accessory Decoder


ESP32 DCC Accessory Decoder Code

When it came to using the ESP32 as an Accessory decoder I started by trying the NMRADcc library, but although it compiled and loaded it just didn't work no matter what I tried, although I am assured that it does work with the ESP32.

I took a look at the NMRA DCC specifications and decided to write my own Accessory Decoder sketch for the ESP32.

It has been tested with DCC++, DCC++ EX and my NCE PowerCab, Sprog 3 and Ecos (thanks to Dave Parr)

The code is split into two files.

DecoderFunction.ino handles translating the DCC signal into something useable.

ESP32AccessoryDecoder.ino is the main sketch, it's very simple to use as explained in the video tutorial and has a function called DCCPacketRead() that is ready for your code to be added in.

 

UPDATE: 27/04/24

Improved error handling added V11



Version 11 Code :

The code has been updated a few times since the video.

Latest version is v11 that has better error detection

Code is dowloaded as a zip file.

Click to Download code ESP32DecoderV11


Additional Resource Links

https://www.digitaltown.co.uk/79DCCDecoderCircuit.php

DCC++ and DCC++ EX

DCC Accessory Decoder, sounds and lights Arduino UNO 12/10/2021

Arduino C++ tutorials

Lesson 7: delay() v's millis(), controlling timing of programs

Arduino C++ Serial UART MP3 Tutorial

NeoPixels18/10/2021

Comments


This site has been designed to be child friendly, this means that comments cannot be added to videos or directly to the site.
To add a comment or ask a question please email the address in this image: and use Project 6 - ESP32 DCC Accessory Decoder as a reference.