DCC loco decoder that works with ESP32?

Shdwdrgn Apr 28, 2018

  1. Shdwdrgn

    Shdwdrgn TrainBoard Member

    181
    156
    8
    I know I asked about loco decoders just recently, and I know some folks threw out some ideas for me to try... And I can not for the life of me find which thread that discussion was in. :( So I'm sorry for asking again but does anyone know of a DCC loco decoder that will compile for the ESP32? I've been working with Geoff Bunza's code for accessory decoders and tried to use his example loco decoder but it appears that NmraDcc.h won't compile for the ESP32 (although there IS some code for the ESP8266). Specifically it seems to be missing some functions for reading and storing data using the EEPROM library and I don't know how to fix it. So if anyone knows of a loco decoder that WILL compile on the ESP32, I'd love to get your recommendation.
     
    Scott Eric Catalano likes this.
  2. Trusty

    Trusty TrainBoard Member

    32
    29
    2
    Hello. ESP32 have no EEPROM embedded, so saving data directly in the controller itself is not possible. The ESP32 normally runs its code from an external flash, however, and this can also be used to store values like you would normally do in an EEPROM. Esp-idf actually has an easy-to-use API for this: https://esp-idf.readthedocs.io/en/lates ... flash.html . The other way is to add an external EEPROM chip. This is cheap, and can be done very easily.
     
    Scott Eric Catalano likes this.
  3. Atani

    Atani TrainBoard Member

    471
    490
    10
    there is also an NVS based wrapper available as an EEPROM library but it does not implement every method that NmraDcc.h may use so you may have to add a few dummy methods to make it work.
     
    Scott Eric Catalano likes this.
  4. Shdwdrgn

    Shdwdrgn TrainBoard Member

    181
    156
    8
    There seems to only be two methods missing, I just have to get familiar with how eeprom access works on the esp8266 and then convert that logic to the esp32. I found the point in the code that was calling those methods so I can add in my own code with "#ifdef ESP32" blocks. Guess I'll have to go that route and see what I end up with.
     
    Scott Eric Catalano likes this.
  5. Shdwdrgn

    Shdwdrgn TrainBoard Member

    181
    156
    8
    In case anyone is interested, I just saw this pop up on reddit...

    https://www.aliexpress.com/store/pr...ess-Bluetooth-Module/2090076_32889146892.html

    This is a TTGO micro-ESP32 board measuring in at about 13x19mm (however it requires an external antenna). That should be plenty small enough to fit inside a narrow-gauge HO loco, and maybe even fit in N gauge. I'm not sure what the pin spacing is, but it's smaller than the wroom32, so I'm guessing around 1mm? Overall this should solve any space issues, but I haven't had a chance to get back to working on the code.
     
  6. Simon Mitchell

    Simon Mitchell TrainBoard Member

    100
    105
    6
  7. Shdwdrgn

    Shdwdrgn TrainBoard Member

    181
    156
    8
    @Simon Mitchell -- It's not feeble if it works. :) I scanned through the first page of your thread, will finish reading the other pages through the day. The first thing I see is that you are using the ESP8266. Great chip, lots of variants available. In my case I am starting with Geoff's decoder code, which *does* work on the 8266 chips, and I figured once I had DCC from the tracks working then I would add in wifi access later. I plan on having power on the tracks, but would prefer to receive the DCC++ commands over wifi instead (who can argue against redundancy?). I am trying to use the ESP32 chips, however, because eventually I want to add cameras onboard my locos and will need the extra processing power and I/O pins to perform this feat. So I figure I might as well start out with the ESP32 instead of upgrading all the locos at a later date. I do have an 0-4-0 with an ESP8266 mounted in the tender, but unfortunately that chip has stopped running code so I think it got zapped.

    Right off the bat you received some good suggestions for deciphering the DCC++ commands. I definitely need to bookmark that for when I get to that point. My initial start on having a wifi train involved writing all of the code from scratch, so I'm familiar with opening TCP ports over wifi to send and receive info. It's actually pretty easy to work with as long as you keep in mind to only use non-blocking code.

    Like you, I want a lot of features available to my locos. Lights, servo-controlled couplers, and so on. I also plan to add an IR sensor to the front and rear of the loco and see if I can't set up collision avoidance. A tach input of some sort would be great for getting accurate speed control and syncing the chuff-chuff sounds. And the ESP32 has two DAC channels which I'm hoping to set up for direct sound output (a simple .wav file can easily be stretched and compressed to sync with the loco speed, I just need to add on an SD card to store the files).

    Big plans, I just have to get through the first phase of getting some basic DCC code to compile for the ESP32, then I can throw together some test hardware and start expanding the code. I have a 4x4 test loop set up with three spurs, which I plan to use for various stages of adding code. Eventually I hope to be able to give each loco a task, schedule, and priority, and have it performed while avoiding other locos. Should be fun!
     
    Scott Eric Catalano and Mariano like this.

Share This Page