ESP32 DCC++ questions

Peter Buelow Dec 20, 2017

  1. Peter Buelow

    Peter Buelow TrainBoard Member

    17
    16
    2
    Hi @Atani, I have some questions. I am just getting started, and was going to use the Mega, but this will be much better I think. But, I have a few questions.

    • Does the ESP32 board need level shifting to talk to the Arduino Motor Board? I know the motor board is 5v tolerant, but your WiKi implies it's 3v3 tolerant as well. Thoughts? I can do either way, but without the level shifter would be nicer.
    • There is a really nice commands wiki page on the original DCC++ that made it easy to start to write my own controller. I see you link that original doc, so I assume the commands and command structures are the same. However, I don't see any docs that say to connect to port # X to send those commands to. Or, is there some special thing to do to send the controller a command? I will be looking into the code after work, but I'm curious about this now as I start to think about how to make this all work.
    This is pretty cool. I have started to write an Android Things front end to DCC++ so I can attach a small RPi display to the side of my setup which will allow for both remote management and automated control of all aspects of my setup. Trains, sensors, turnouts, house lights, street lamps, etc (not all DCC, some are just GPIO). The ESP32 allowing network control via WiFi takes a huge setup problem out of my environment. Thanks.
     
    Goofy and Scott Eric Catalano like this.
  2. Atani

    Atani TrainBoard Member

    1,460
    1,697
    36
    I have not found a need for a level shifter with the ESP32. I was concerned on the current sense inputs primarily but did not see any issues with it so far.

    Yes, the original commands work, there are a few minor differences though:
    1) The command character must be followed by a space, ie: <t 1 123 0 1> and *NOT* <t1 123 0 1>.
    2) The "p", "c", "a" commands have slightly different responses as the power districts (or outputs) are named, ie: sending <0> will respond with: <p0 MAIN><p0 PROG>. <1> => <p1 MAIN><p1 PROG>... <c> => <p1 MAIN><a MAIN 0><p1 PROG><a PROG 0>. <c MAIN> => <a MAIN 0>
    3) Over current conditions will result in only that power district being shutdown and <p2 NAME> being sent. It will automatically switch back to ON once cleared.

    I will have a new wiki page soon that will cover the base command set (currently linked wiki) and the modifications done to the commands with this version of the base station.

    The port is the same that JMRI would use, 2560 and is declared in Config.h as DCCPP_CLIENT_PORT.
     
    Goofy and Scott Eric Catalano like this.
  3. Peter Buelow

    Peter Buelow TrainBoard Member

    17
    16
    2
    Awesome, thank you. I was using the space anyway. I'm just learning about JMRI, so some of this is still greek. I like the other changes. Is that the full list of things you changed, or did you fix anything else?
     
    Scott Eric Catalano likes this.
  4. Atani

    Atani TrainBoard Member

    1,460
    1,697
    36
    There are likely a few other changes and I am aware of one issue that will need to be resolved this weekend for JMRI, sending <s> does not respond with <iDCC...>, I don't remember now why that got dropped but it should still be there.

    Also you should pick up JMRI 4.11.1 (or later) as this will properly handle the updated protocol bits described above for named power districts. 4.11.1 is only available via nightly builds currently but should be generally available soon.
     
    Scott Eric Catalano likes this.
  5. Peter Buelow

    Peter Buelow TrainBoard Member

    17
    16
    2
    Thank you. My needs are simpler than a full implementation. I don't expect to need a lot of what it provides, but maybe over time? For now, I'll just hack at it to get my small setup running. Thank you.

    Would this work with the 8266 as well? I am looking at my backlog of boards, and I realize I don't have any ESP32, but a bunch of 8266 boards. The Adafruit Huzzah series is nice.
     
    Last edited: Dec 21, 2017
    Scott Eric Catalano likes this.
  6. Atani

    Atani TrainBoard Member

    1,460
    1,697
    36
    No my new code does not work on the esp8266, but my older base station code that uses an Arduino board the esp8266 will work. I am exploring the option of an esp8266 approach but it is still in planning phases.

    Sent from my ONEPLUS A5010 using Tapatalk
     
    Scott Eric Catalano likes this.
  7. Peter Buelow

    Peter Buelow TrainBoard Member

    17
    16
    2
    OK, cool. Thanks for all the quick answers. Amazon has the OLED board in your github pics so I got one of them to work with. Not a big deal.

    As a side question, what glues this to the the ESP32? I haven't looked yet, so I would assume it's how you use the network, but I'd be curious to know if it would be terribly difficult to tailor to support a Photon as an example.
     
    Scott Eric Catalano likes this.
  8. Atani

    Atani TrainBoard Member

    1,460
    1,697
    36
    I don't have one of the oled esp32 boards myself. I have the other boards that I put up though. That said, I am not sure what you mean by the photon. Is that some sort of oled screen? If so you should be able to connect it to the i2c bus and put it's address in and it might just work. For the built in oled, run an i2c scan to find it's address and put that in Config.h for oled and it should work, hopefully.

    Sent from my ONEPLUS A5010 using Tapatalk
     
    Scott Eric Catalano likes this.
  9. Peter Buelow

    Peter Buelow TrainBoard Member

    17
    16
    2
    No, it's another one of the WiFi IoT boards, based on a big processor like like the ESP32, has WiFi built in, but has a very mature programming SDK and it makes it very easy to manage your device in the cloud. My new favorite WiFi micro controller just because their SDK is the best IMHO, it's cheap, and requires less overall effort to do anything special. You can find it at http://particle.io. Very nice overall.

    I don't care much about the OLED, but it's on the board I got, so I get it for free. I'm more interested in the WiFi and maintenance, so for that, I say thank you. Whether I can port it to the Photon easily may be something I take on or I may not.
     
    Last edited: Dec 21, 2017
    Mariano and Scott Eric Catalano like this.
  10. Atani

    Atani TrainBoard Member

    1,460
    1,697
    36
    based on a very quick look at the Particle IO website this looks like it might work. You would need to replace the Signal Generator code that uses the ESP32 hardware timers with the SparkIntervalTimer library which can provide a microsecond timer with isr callback. However, using this library will disable the ability to use analogWrite, servos and possibly other APIs.
     
    Scott Eric Catalano likes this.
  11. Peter Buelow

    Peter Buelow TrainBoard Member

    17
    16
    2
    Interesting, I just got Atom with PlatformIO going and built the image for the ESP. I still haven't looked at the code much yet. Too much going on.

    What do you do with analogWrite? As I understand it, not all of the Analog lines are reserved for that timer library, or I could write my own timer I suppose to directly manage this. I assume the servos for the same reason. But what other API's?
     
    Last edited: Dec 21, 2017
    Scott Eric Catalano likes this.
  12. Atani

    Atani TrainBoard Member

    1,460
    1,697
    36
    Nothing uses analogWrite today but if a library uses it then it could be a problem.

    For DCC++ the analog pins are used only for inputs as current sense/programming ack.

    Also just got the code to compile for the esp8266 with a single dcc signal generator. I will be testing that out as another option for those that just need an ultra basic base station to generate a dcc signal for boosters. There won't be a programming track by default. It could be setup as a standalone programmer though as a different option.



    Sent from my ONEPLUS A5010 using Tapatalk
     
    Scott Eric Catalano likes this.
  13. Peter Buelow

    Peter Buelow TrainBoard Member

    17
    16
    2
    Cool. What does the programming track do for you anyway? I guess I couldn't catch up with that idea. I assume it's just an idle track used to write programming data to store in the cabs/signals/turnouts/etc. Then you move those to the in use track. But I suspect that's probably wrong or at least not completely accurate.
     
    Scott Eric Catalano likes this.
  14. Atani

    Atani TrainBoard Member

    1,460
    1,697
    36
    The programming track is used exclusively for configuring dcc decoders either in locomotives or stationary decoders.

    Sent from my ONEPLUS A5010 using Tapatalk
     
    Scott Eric Catalano likes this.
  15. Peter Buelow

    Peter Buelow TrainBoard Member

    17
    16
    2
    Got it up and running. I'm not moving a train yet, but I can use the board + the motor control now. Question though, for the Lolin board you have pictures of, did you have any troubles with the OLED? I can't get it working. Not sure why. It's an address/interface problem, but I can't find any useful documentation other than it is at 0x3c, 5, 6, which isn't working for me. Not a critical problem, but curious to know if you had to do anything special for that board.

    Thanks for the efforts. This is pretty cool so far. Some day next week when life calms down again, I plan to put together some track with an early prototype of my control SW or one of the free one's for a phone to see if it all works.
     
    Scott Eric Catalano likes this.
  16. Atani

    Atani TrainBoard Member

    1,460
    1,697
    36
    I don't have that board in hand unfortunately. But it should work if you can get the right i2c address. Use the i2c scan sample to get the right address as a first step. Second step use the 1306 drive, if that fails switch to the 1106 driver. I have seen both used but I believe the 1306 is more common on those boards.

    Sent from my ONEPLUS A5010 using Tapatalk
     
    Scott Eric Catalano likes this.
  17. Peter Buelow

    Peter Buelow TrainBoard Member

    17
    16
    2
    I looked for a scan example at the esp8266 oled driver github, but I'm pretty sure I'm looking for the wrong thing. I don't see a scan example there. Do you have the URL? Thanks
     
    Scott Eric Catalano likes this.
  18. Atani

    Atani TrainBoard Member

    1,460
    1,697
    36
    Scott Eric Catalano likes this.
  19. Peter Buelow

    Peter Buelow TrainBoard Member

    17
    16
    2
    Getting there. Trying to program a loco now. Still having some issues, though I may go back and try the original pins in a moment. I do get the following from the just released JMRI Decoder Pro. This prints over and over again. However, the motor board isn't currently powered. When it is, JMRI won't show it as powered when I click On, and the responses all include the Unrecognized reply, though console output on the ESP32 seems to think it is. I'm using pins 15 and 13 for the programming track.

    Status Cmd
    Unregonized reply: s
    vals: s
    Power Status: ON
    Current: / 1024
    Power Status: ON
    Current: / 1024
    Comm Type Reply Type: 1 Port: 172.24.1.137

    Clicking "On" results in the following

    Track Power ON Cmd
    Unregonized reply: 1
    vals: 1
    Power Status: ON
    Power Status: ON

    [MotorBoard.cpp:121] powerOnAll(): Enabling DCC Signal for all boards
    [MotorBoard.cpp:40] powerOn(): [MAIN] Enabling DCC Signal
    [MotorBoard.cpp:40] powerOn(): [PROG] Enabling DCC Signal
    ON

    Yet, the little on button is still off.

    I tried to decode something, using the DCC++ drop down. It's not finding anything. I think power is on to the track, I see a net 0 voltage across them, but maybe I'm going this wrong?

    Thoughts? I have a neat little Kato Metra engine I would like to move around the track.
     
    Scott Eric Catalano likes this.
  20. Atani

    Atani TrainBoard Member

    1,460
    1,697
    36
    Use the network connection option and not serial for jmri. The serial line does not have all outputs and has a lot that jmri will not understand as it is diagnostic output mostly.

    In jmri you should be able to switch it to network connection in the config. It may even be able to find the board automatically since mDNS is advertising the dcc++ port for jmri.

    Sent from my ONEPLUS A5010 using Tapatalk
     
    Scott Eric Catalano likes this.

Share This Page