ESP32 DCC++ questions

Peter Buelow Dec 20, 2017

  1. Atani

    Atani TrainBoard Member

    1,469
    1,756
    37
    What pins are you using currently? The signal/direction pins can be configured in Config.h and the current sense pins must be pins 30 and above, the default pins used are 36 and 39. Some boards label these as SVP and SVN. These are configured in DCCppESP32.cpp where motor boards are created. This can probably be moved to Config.h as well for main/prog but other motor boards would be left to the setup method.

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

    Peter Buelow TrainBoard Member

    17
    16
    2
    Sorry, that was the serial output on the console, I'm using network from my laptop. JMRI connects just fine, and it looks like it sort of works, but it never really does anything. I can't scan for anything on the tracks, and I can't seem to add a loco.

    I just updated and it changed some of the sniffer log.

    Status Cmd
    Unregonized reply: s
    vals: s
    Base Station Status:
    Version: DCC++ BASE STATION FOR ESP32
    Build: V-1.0.4 / Dec 24 2017 14:50:00
    Power Status: ON
    Current: / 1024
    Power Status: ON
    Current: / 1024
    Comm Type Reply Type: 1 Port: 172.24.1.137

    Is what I get now. But, it still says it's on, but Decoder still thinks it's off.
     
    Last edited: Dec 24, 2017
    Scott Eric Catalano likes this.
  3. Atani

    Atani TrainBoard Member

    1,469
    1,756
    37
    What version of jmri are you using? I know it will not properly parse some outputs until 4.11.1 which is available via their nightly build servers for now. But the basics should still work even with some parse errors.

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

    Peter Buelow TrainBoard Member

    17
    16
    2
    Getting somehwere. I can see track current in real time. With the 4.11.1, it shows On correctly when I ask to turn it on. Next up, getting my Kato Metra Rail engine running. I tried the Identify command, but no luck. Read type from Decoder returns 255, which I think is just nothing found. I looked up the specific decoder, and found it was an ESU Loksound Select, so I tried programming that, but I never see Decoder Pro sending any actual programming to the ESP in the DCC traffic monitor window. I've tried both the programming and main channel. I think I'm missing a step somewhere. I never see all the commands going to the ESP32 that I feel like I should be sending for all the stuff I'm trying. Doing it directly using Send DCC++ command, I never see the command get to the ESP. What I see below is pretty much the only traffic that I see in both the DCC Traffic Window and the ESP32 console. I'm missing one or more steps I think. Any ideas? I'm using a 12v 2A brick right now, I have a 15v on order as a note.

    Code:
    10:45:33.940: [TX: s]  Status Cmd
    10:45:33.949: [RX: s]  Unregonized reply: s
        vals: s
    10:45:33.954: [RX: iDCC++ BASE STATION FOR ESP32: V-1.0.4 / Dec 24 2017 14:50:00]  Base Station Status:
        Version: 1.0.4
        Build: Dec 24 2017 14:50:00
    10:45:33.955: [RX: p1 MAIN]  Power Status:
        Name:MAIN    Status:ON
    10:45:33.960: [RX: a MAIN 22]  Current: 22 / 1024
    10:45:33.961: [RX: p1 PROG]  Power Status:
        Name:PROG    Status:ON
    10:45:33.963: [RX: a PROG 389]  Current: 389 / 1024
    10:45:33.966: [RX: N1: 172.24.1.137]  Comm Type Reply Type: 1 Port: 172.24.1.137
    Code:
    10:45:47.882: [TX: R 8 0 82]  Prog Read Cmd:
        CV: 8
        Callback Num: 0
        Callback Sub: 82
    10:45:47.882: [RX: R 8 0 82]  Unregonized reply: R 8 0 82
        vals: R   8   0   8 2
    10:45:52.760: [RX: r0|82|8 255]  Program Reply:
        Callback Num: 0
        Callback Sub: 82
        CV: 8
        Value: 255
    10:45:52.765: [TX: R 7 0 82]  Prog Read Cmd:
        CV: 7
        Callback Num: 0
        Callback Sub: 82
    10:45:52.768: [RX: R 7 0 82]  Unregonized reply: R 7 0 82
        vals: R   7   0   8 2
    10:45:57.674: [RX: r0|82|7 255]  Program Reply:
        Callback Num: 0
        Callback Sub: 82
        CV: 7
        Value: 255
     
    Scott Eric Catalano likes this.
  5. Atani

    Atani TrainBoard Member

    1,469
    1,756
    37
    Yeah something is not quite right. It looks like the motor board is maybe not connected correctly to the analog pins. The prog track uses current sense to receive the ack from the decoder.

    Which motor board are you using? From the output in jmri console there seems to be a lot of noise on the current sense pin for the programming track. With a usage of over 300 it will count that as a positive response from the decoder. With one of my sound locos on the prog track I usually don't go over 75 usage for the Arduino motor shield.

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

    Peter Buelow TrainBoard Member

    17
    16
    2
    I see that I'm not attached for ADC2/6, so that probably explains that value. I just ordered a couple of the other ESP32 boards you have pictured (the dev board, and the Uno board) which seem to have the pins I want exposed. Did you ever use the lolin board, and if so, what did you do for the ADC pins? Maybe I can still use this board? I also noticed I had pin typo in my Programming track motor direction pin. I'm going to see if that means much when my laptop finishes charging (too many cords on my table with the track and train).

    Note that for Identify, I get address 16383 back when I do identify, but I think that's still just nonsense return values. Also, does the track have polarization? Does the + and - have to be on one specific rail?

    Thanks for the help.
     
    Last edited: Dec 25, 2017
    Scott Eric Catalano likes this.
  7. Atani

    Atani TrainBoard Member

    1,469
    1,756
    37
    Connect current sense for motor a to the SVP pin (this is adc1 channel 0) and the current sense for motor b to SVN pin (adcq channel 3). That should work for that board.

    And that doesn't seem right for the oled address's usually the value is a two digit hex number, Max of 255.

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

    Peter Buelow TrainBoard Member

    17
    16
    2
    Thanks. What pins do those attach to on the motor board? I see an image you have which shows A0<->A2 and A1<->A3, but those are just jumpered. What pins do the two ADC pins connect to? I tried A0 and A1 on the motor board, but got consistent OVERLOAD errors. Do I need a resistor on those lines? Or are you using A2 and A3 as those have the resistors on them. A search for using the current sense on the board gives me indeterminate results on the resistor, but they all seem to imply using one.

    And the 16383 is what I get back when I send an Identify in Decoder Pro to the ESP32 trying to identify equipment on the line. It never identifies equipment, just throws errors. I'm more interested in getting my loco working now. Getting the OLED working isn't very exciting today. I won't use it in the long run anyway.
     
    Scott Eric Catalano likes this.
  9. Atani

    Atani TrainBoard Member

    1,469
    1,756
    37
    Connect SVP to A0 and SVN to A1. I have jumpers for A0 and A1 due to the uno board I am using has ADC2 connected to the A0 and A1 headers. If you use other boards the jumpers would not be needed, and same for this board once they fix the ADC2 and wifi issue.

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

    Shdwdrgn TrainBoard Member

    251
    182
    13
    Is there a way to run temporarily *without* current sensors? The motor controller board I have (L298N based) doesn't have that feature so I'm waiting on some separate current sensor boards (5A ACS712 chip) to arrive.
     
    Scott Eric Catalano likes this.
  11. Atani

    Atani TrainBoard Member

    1,469
    1,756
    37
    Connect the analog lines to gnd and it may work.

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

    Shdwdrgn TrainBoard Member

    251
    182
    13
    Is there a way to slow down the phase switching on the output? I'm using the transistor circuit per trainelectronics.com (which I've also used for driving an L293D chip). Based on the pinout of my lolin32 board I'm using 25 as the enable line, 26 as the direction line, and SVP as my analog (connected to ground at the moment). When I click the power button on the web interface I see pin 25 go high (about 3.2V), but pin 26 seems to always be at 1.6V and I'm not getting any useful voltage from the output of my L298N board. I'd like to see the phase shifting dropped down to about once per second so I can measure the outputs with a regular volt meter and make sure the outputs I'm expecting are what's actually measured. If there's no easy settings in the DCC++ code then I'll just write up something custom in the morning, but I thought it would be worth checking first.
     
    Scott Eric Catalano likes this.
  13. Jimbo20

    Jimbo20 TrainBoard Member

    274
    178
    11
    Scott Eric Catalano likes this.
  14. Atani

    Atani TrainBoard Member

    1,469
    1,756
    37
    This command is not implemented on the Esp32. There is no easy way to change the timing on the Esp32 at runtime with the current implementation. I will see if there is anything I can implement for that though

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

    Atani TrainBoard Member

    1,469
    1,756
    37
    You should be able to attach a scope to the direction pin and see it shift high/low at roughly 58us or 104us intervals. Let me check the pinout on the d-duino-32 board to see if there are any pull-down resistors on any pins. You should see the same 3.2v on direction pin high state as you do for enable. Enable does not change unless track power is turned off.

    Edit: Looked at the pinout and the d-duino-32 details and I don't see anything wrong with your pin choices, they look like the most logical. You might also try the SD1/CMD/SD0 pins for the direction pin.

    Sent from my ONEPLUS A5010 using Tapatalk
     
    Last edited: Jan 1, 2018
    Scott Eric Catalano likes this.
  16. Shdwdrgn

    Shdwdrgn TrainBoard Member

    251
    182
    13
    Yeah a scope *would* be handy for something like this... too bad I don't have one. :) All right I double-checked my wiring through the transistor circuit and compared it to another board where I have that same layout working, and everything looked fine there. I'll write up some quick code today so I can measure the pin outputs and manually check the function of the H-bridge. Since the L298N is a 5V chip I'm also kind of wondering if it might not be tripping from the 3.2V signal, but that should be easy enough to check as well.
     
    Scott Eric Catalano likes this.
  17. Atani

    Atani TrainBoard Member

    1,469
    1,756
    37
    I am using the Arduino motor shield, also based on the same chip, with no issues from the logic voltage being 3.3v. if you can power the IC with 5v make sure the logic outputs are scaled similarly for routing back to the esp32 (analog seems to work fine for 3.3v or 5v in my testing).

    I should also have my scope and a pile of l293 motor shields tomorrow. I will need to add current sense to these but that is a small piece to add to them.

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

    Shdwdrgn TrainBoard Member

    251
    182
    13
    I've used the L293D bare chips successfully with the voltage from an esp8266 to run the motor on a loco, so you should see no problems there. And yeah, if I use a 5v supply to test the H-bridge board it will be disconnected from the ESP pins. I was just going to run some manual jumper wires. From what I've read on it, I have removed all three jumpers, I have the EN line going to the first pin, split the DIR pin into both phases with the transistor and few those two wires to IN1 and IN2, and I made sure to tie a ground line from the ESP to the ground input on the H-bridge. I can't really see it needing anything else.

    While I'm hoping to just start testing the circuit with the L298N, I do have other boards comping from China. The independent current sensors I mentioned before, and a 5A H-bridge. I also discovered that BTS7960B board from trainelectronics.com yesterday which has its own built-in current sensor, wish I'd found that one first! Got it ordered but I'll have to make do until it arrives.

    Seriously, there should be a sticky at the top of this group that gives recommended hardware for people who want to jump right in. Or at least a compatibility list to give folks a starting point...

    Oh hey, one more question... Regarding the OLED display, will anything other than the initial four lines ever show? I was thinking it would be handy to know if a short is detected by the current sensor, maybe display "track power: SHORT" if that happens? Since the display is available, a visible queue for important circumstances like that would be nice to see. And it looks like the display has room for a fifth line, would it be possible to display the current draw there, or at least the analog value to know if anything is being detected by the sensor?
     
    Scott Eric Catalano likes this.
  19. Atani

    Atani TrainBoard Member

    1,469
    1,756
    37
    You can route the EN pin to the SIGNAL_ENABLE_PIN_XXXXX.. it will go HIGH when the shield should be enabled from the base station side.

    Are you using the circuit on trainelectronics.com to do this? You can find the schematic here: http://trainelectronics.com/DCC_Arduino/DCC_Booster/index.htm. The BTS7906B board uses the same logic to split DIR into HIGH/LOW flip-flop on two pins. I am planning on using an SN74LS04 to split the logic since I will have a couple boards and can use a single not gate chip for a couple motor boards.

    I have it on my wiki and there is support for 5A and 10A by default in the base station code. Refer to MotorBoard.h for the enum names. Additional amp limits can be added in MotorBoard.cpp in registerBoard.

    I agree! I am trying to document as much of this as I can on the DCC++ESP32 wiki pages, I will be expanding it to include wiring the bits together and options for circuits.

    Currently the display will only update if the overall track power is ON/OFF. I plan on changing that though. The fifth line is going to be used soon for a rotating display of the motor shield states (current draw included).

    If you want to see if the analog current draw is being read you can access the webpage and leave it on the base station status tab. Every 20sec the table will refresh. The refresh will only occur if one of the base station tabs is active at the time. If a short is detected it will display in the table as Fault, when the power is on but no short detected it will display as Normal, otherwise it is shown as Off.
     
    Scott Eric Catalano likes this.
  20. Shdwdrgn

    Shdwdrgn TrainBoard Member

    251
    182
    13
    OK it turns out to be a problem of lacking documentation for that L298N board. I'm using an 18V supply and I removed all three of the jumpers. Well the chip itself still needs a 5v supply fed in from the 5v pin on the three-pin terminal block. I'm using the 3.2v from the EN line, and now the output is working as expected. I wrote up some code to flip the direction every 5 seconds and verified that the transistor circuit is correctly providing my two opposite-polarity outputs, and once I added power the output from the board was flipping between + and - 18vdc. Re-loaded the DCC++ code and my meter reads about 2vac RMS. I actually expected it to be closer to 18V RMS but oh well it's a cheap meter. When I turn track power off again from the web interface, the output drops back to zero so it is most likely working now. Here's the schematic of how I hooked up the motor driver...
    [​IMG]

    By the way I noticed in one of the threads that you linked to a panel meter you're using... glad you mentioned it because I also have the same meters here and had planned on using them for the same purpose. I went ahead and soldered it into the input for the 18V supply yesterday so I can watch it as I get an actual loco running on the test track later on.

    For reference, here's the test code that I used to verify the transistor was working correctly. The variable DIRECTION_TIMER is in ms, so 1000 equals one full second.

    /****************************************/
    /* WARNING: DO NOT CONNECT TO TRACK! */
    /* This code is NOT compatible with DCC */
    /* equipment and could cause permanent */
    /* damage. It should only be used to */
    /* test output of unconnected H-bridge. */
    /****************************************/

    // Taken from DCCppESP32/Config.h
    // MAIN TRACK SIGNAL ENABLED PIN
    #define SIGNAL_ENABLE_PIN_MAIN 25
    // PROG TRACK SIGNAL ENABLED PIN
    #define SIGNAL_ENABLE_PIN_PROG 16
    // MAIN TRACK DIRECTION PIN
    #define DIRECTION_MOTOR_CHANNEL_PIN_MAIN 26
    // PROG TRACK DIRECTION PIN
    #define DIRECTION_MOTOR_CHANNEL_PIN_PROG 5

    #define DIRECTION_TIMER 1000
    boolean PHASE = false;
    unsigned long PHASE_timer = 0;

    void setup() {
    pinMode(SIGNAL_ENABLE_PIN_MAIN, OUTPUT);
    pinMode(SIGNAL_ENABLE_PIN_PROG, OUTPUT);
    pinMode(DIRECTION_MOTOR_CHANNEL_PIN_MAIN, OUTPUT);
    pinMode(DIRECTION_MOTOR_CHANNEL_PIN_PROG, OUTPUT);

    digitalWrite(SIGNAL_ENABLE_PIN_MAIN, HIGH);
    digitalWrite(SIGNAL_ENABLE_PIN_PROG, HIGH);
    digitalWrite(DIRECTION_MOTOR_CHANNEL_PIN_MAIN, PHASE);
    digitalWrite(DIRECTION_MOTOR_CHANNEL_PIN_PROG, PHASE);
    }

    void loop() {
    unsigned long NOW = millis();

    if (NOW >= PHASE_timer) {
    PHASE_timer = NOW + DIRECTION_TIMER;

    PHASE = !PHASE;
    digitalWrite(DIRECTION_MOTOR_CHANNEL_PIN_MAIN, PHASE);
    digitalWrite(DIRECTION_MOTOR_CHANNEL_PIN_PROG, PHASE);
    }
    }
     
    Scott Eric Catalano and Atani like this.

Share This Page