ESP32 Command Station

Atani Dec 10, 2017

  1. Atani

    Atani TrainBoard Member

    1,460
    1,697
    36
    You don't need the 10k pot for this setup.. you just need to tell the base station that you are using that type of motor shield and it will handle the rest. There are pre-defined enums for 5A and 10A for the BTS boards.

    If you pull the latest code from GitHub, 1.0.7 is the version. The oled screen will rotate through a number of runtime values, including usage of the motor shields.

    The reason the dead short did not trigger shutdown is due to the BTS having an absolute Max of 43A! The default motor shield is set for the Arduino ones which have a Max of 2A. Due to these differences the esp32 could not detect the short. If you set the motor shield type and connect the current sense pins to the esp32 it should detect at 5A or 10A. If lower values are needed they can be added easily or current values adjusted in MotorBoard.cpp

    I am planning a new release for later this month with a number of bug fixes and new features (s88-n sensor support)

    Sent from my ONEPLUS A5010 using Tapatalk
     
    Scott Eric Catalano and Goofy like this.
  2. Atani

    Atani TrainBoard Member

    1,460
    1,697
    36
    Also you don't need to guess the values.. you pass in the absolute values as milliamps and the code converts that to the esp32 adc values.

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

    Atani TrainBoard Member

    1,460
    1,697
    36
    I should give an example on using the BTS motor boards, from my phone it is hard to put one one so here is one from the PC...
    Config.h:
    Code:
    // MAIN TRACK MOTORBOARD NAME
    #define MOTORBOARD_NAME_MAIN "MAIN"
    // MAIN TRACK NOTORBOARD ENABLED PIN
    #define MOTORBOARD_ENABLE_PIN_MAIN 25
    // MAIN TRACK MOTORBOARD CURRENT SENSE ADC PIN
    #define MOTORBOARD_CURRENT_SENSE_MAIN ADC1_CHANNEL_0
    // MAIN TRACK MOTORBOARD MOTOR_BOARD_TYPE
    #define MOTORBOARD_TYPE_MAIN MOTOR_BOARD_TYPE::BTS7960B_5A
    
    This tells the base station to configure a 5A BTS7960B for MAIN.

    Since you mentioned you have a 4.5A supply, you can adjust the base station to trigger at 4A rather than 5A by changing this line: https://github.com/atanisoft/DCCppESP32/blob/master/src/MotorBoard.cpp#L109, replace the 5000 with 4000.

    Adding support for other levels can be done in this same place by adding new enum constants here: https://github.com/atanisoft/DCCppESP32/blob/master/src/MotorBoard.h#L28 and adding respective case statements in the above location.
     
    Scott Eric Catalano likes this.
  4. Shdwdrgn

    Shdwdrgn TrainBoard Member

    251
    182
    13
    Hmm that's a great idea, I actually have a new headlight waiting for installation on my motorcycle. Does that work with the square wave across the tracks or do I need a diode bridge to feed straight DCC to the light?
     
    Scott Eric Catalano likes this.
  5. Jimbo20

    Jimbo20 TrainBoard Member

    274
    178
    11
    You might be risking it using an expensive bulb, as the voltage will be a little higher than its rated voltage, a car or motorcycle would normally peak at about 14.5 volts, when its engine is running.

    You do not need to rectify the track output when putting a resistive load (such as a light bulb) on it.

    Jim
     
    Scott Eric Catalano likes this.
  6. Shdwdrgn

    Shdwdrgn TrainBoard Member

    251
    182
    13
    Oops, didn't see the replies from Atani... looks like you've been busy on the code so I need to pull an updated version. Thanks for the info, I'll get the updates made tonight and see how it works. But how do you know what value of resistor to use on the current sense line? Was this all based off a straight 10K resistor?
     
    Scott Eric Catalano likes this.
  7. Atani

    Atani TrainBoard Member

    1,460
    1,697
    36
    No resistor needed on current sense. It is used on Dave's booster as a means to generate an analog compare value for the cut-off.

    With DCCppESP32 the cut-off is calculated based on the motor board max milliamps and the esp32 analog pin range (0-4095). The motor board will feed a voltage to the esp32 that is proportional to the current usage. So we just need to calculate the value once and compare periodically to check for a short.

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

    Shdwdrgn TrainBoard Member

    251
    182
    13
    @Atani - I understand the BTS7960B sends a proportional voltage, but I thought that voltage was calibrated for an arduino which takes 0-5v, while the ESP32 ADC only takes a maximum of 1V. Also I thought the comments on his web page said the resistor is to create a voltage divider so that the proper voltage is given to the ADC pin? And yeah, I forgot that this board takes up to 43A so of course it didn't trip from my 'wimpy' little 4.5A power supply. :)

    @Jimbo20 - hmm good call. I probably have an old headlight laying around somewhere though, I'll see what I can find. If nothing else I could put two of them in series.
     
    Scott Eric Catalano likes this.
  9. Atani

    Atani TrainBoard Member

    1,460
    1,697
    36
    I would need to double check the spec sheet for the BTS chip. But even if it sends more than 1.1V to the esp for "max" that would be for 43A. We are triggering on a fraction of that so a fraction of the voltage. I have also tested on my esp32 boards and the adc treats 5v the same as 3v or even lower. Anything over the max voltage appeared to read as max value on adc, 4095.

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

    Shdwdrgn TrainBoard Member

    251
    182
    13
    OK I'll remove the existing resistor and try it with a direct connection tonight after updating the code. Thanks once more!
     
    Scott Eric Catalano likes this.
  11. Shdwdrgn

    Shdwdrgn TrainBoard Member

    251
    182
    13
    @Atani - I think something is wrong. For Main I set the enable pin to 25 and the signal pin to 26 (I think the signal pin has replaced the PWM pin?) which should match what I had before. I changed the board type to BTS7960B_5A and adjusted the cutoff to 4000, then removed the divider resistor I was using before. What I'm *not* certain of is the ADC pins. It looks like I should be using ADC1_CHANNEL_0 for SVN (for sensing on Main) on this board?

    The ESP boots like before and responds to connect and track power signals from the web page, showing power to the track is "on" on the OLED, however both main and prog keep flashing "Fault (0.00A)" and there is no measurable power being sent to the tracks. It seems like there shouldn't be a fault at a zero reading, since the loco I have on the track won't pull anything until track power is applied? Any thoughts? Am I missing something?
     
    Scott Eric Catalano likes this.
  12. Atani

    Atani TrainBoard Member

    1,460
    1,697
    36
    Which esp32 board do you have again? I will setup a test environment this weekend and can do some checking into it.

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

    Shdwdrgn TrainBoard Member

    251
    182
    13
    Sorry, it's the one marked as Lolin Wemos, has the ESP32 and the small OLED display.
     
    Scott Eric Catalano likes this.
  14. Atani

    Atani TrainBoard Member

    1,460
    1,697
    36
    Ok I just got that board today and will do some testing with the BTS soon. I want to expand the wiki a bit to give more details on what is known working etc.

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

    Shdwdrgn TrainBoard Member

    251
    182
    13
    It's a really handy board with the built-in USB and display, I actually ordered another one to set up a temp/humidity monitor for the greenhouse. I have some bare breadboards and female headers coming so I can plug my other circuitry right onto this board and keep things nice & compact.
     
    Scott Eric Catalano and Atani like this.
  16. Shdwdrgn

    Shdwdrgn TrainBoard Member

    251
    182
    13
    I'm trying to look through the code and noticed a lot of references to log_i(), but I can't seem to find it as a defined function and google is coming up short. The name seems to suggest that perhaps a log file is kept somewhere? Is this true? If so, where would I find it as that may help with troubleshooting?

    Busy busy week at work and a train club meeting tonight, hopefully tomorrow I'll have more time to look into this though. Also just to confirm what appears to be a very simple setup... from the Lolin board I only have four wires. A common ground shared with the H-bridge, an enable line which also supplies power to the H-bridge logic, a PWM line which feeds a transistor inverter supplying the opposing 0/1 logic to the two sides of the H-bridge, and an ADC line which connects directly to the two current sense outputs of the motor driver chip. The Lolin board does have a 5V output, probably from the USB port, I might try using that to drive the motor board logic instead of the 3.3v signal from the enable line, but otherwise I believe the hardware connections are correct.
     
    Scott Eric Catalano likes this.
  17. Atani

    Atani TrainBoard Member

    1,460
    1,697
    36
    The log_i and similarly named functions are part of arduino-esp32. They generate content on the serial console only.

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

    Atani TrainBoard Member

    1,460
    1,697
    36
    The BTS chips need 5v power. You can connect it to the esp32 5v pin but be warned that it may pull too much power and the esp32 may reset.

    The connections sound correct I believe. Do you have a picture or schematic that you are using as reference?

    I am working on some info for the wiki and will have some schematics and pictures to help people get this setup easily and quickly.

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

    Shdwdrgn TrainBoard Member

    251
    182
    13
    Ah cool, I can work with serial output, just need to set up a laptop next to my test track.

    I've been using the schematic near the top of this page as a reference: http://trainelectronics.com/DCC_Arduino/DCC_Booster/index.htm
    I'm not using any of the power circuitry as show in the upper-left, and the line he shows coming from the optocoupler I have replaced with the Enable pin from the ESP. I just have a small breadboard between the ESP and the motor driver that holds the transistor and two resistors.
     
    Scott Eric Catalano likes this.
  20. Atani

    Atani TrainBoard Member

    1,460
    1,697
    36
    There is no PWM pin with DCC++ESP32 in the traditional sense, same can be said though for DCC++ on the Arduino. The ENABLE pin is connected to the PWM input on the motor shields and is only HIGH/LOW with no modulation. The Direction pin is used to generate the square wave used for the DCC signal.

    Your pin selection is logical for the ESP32-Lolin-OLED board and should work as you expect. I have put further details below that should help you get further on testing this, I plan on testing this as well this weekend and updating the Wiki page with recommendations on pin assignments and Config.h values based on the board type. As I am sure you have found, the ESP32-Loline-OLED board requires SDA/SCL to be provided in Config.h as the standard SDA/SCL definitions are incorrect for this board variant (https://github.com/espressif/arduino-esp32/issues/930) which is a D-Duino-32 clone.

    ok after re-reading the BTS7960 and ESP32 details here are the connections that I believe will work.

    5V connects to BTS7960 pin 1
    GND connects to BTS7960 pin 2
    MOTORBOARD_CURRENT_SENSE_MAIN (36) connects to BTS7960 pins 3 & 4
    MOTORBOARD_ENABLE_PIN_MAIN (25) connects to BTS7960 pins 5 & 6
    DCC_SIGNAL_PIN_OPERATIONS (19) connects to BTS7960 pin 7
    DCC_SIGNAL_PIN_OPERATIONS (19) connects to the 2N2222/resistor circuit to provide inverted logic to BTS7960 pin 8.

    The setup I am planning on using for BTS7960 pin 7 & 8 will be different than the 2N2222/resistor approach, I am planning on using a SN74LS04 instead. The connections are as follows:
    DCC_SIGNAL_PIN_OPERATIONS (19) connects to SN74LS04 pin 1 & BTS7960 pin 7.
    SL74LS04 pin 2 connects to BTS7960 pin 8.

    I am also considering setting up a PCB and sending it to OshPark using the SN74LS04 as an adapter of sorts to connect the BTS7960 to the base station more easily.

    I would highly recommend against using the ENABLE pin to power the BTS7960 as that will very likely draw too much current and cause erratic behavior on the ESP32 side, including reboot.
     
    Scott Eric Catalano likes this.

Share This Page