ESP32 Command Station

Atani Dec 10, 2017

  1. Lormedy

    Lormedy TrainBoard Member

    17
    1
    4
    S88-diagram.png
    Please find a record of the S88 bus timing.
    Sensors 1, 3 and 16 are active here to help identifying bits. Reset occurs after data is loaded in registers. As a result the first bit read here belong to the previous sequence. New data are registered by the Clock rising when Load is already high and immediatly readable on the S88 bus. The first and last clock pulse shouldn't be on the diagram.
     
  2. Atani

    Atani TrainBoard Member

    1,466
    1,736
    37
    The timing currently in use was based on this https://www.opendcc.de/s88/s88_n/s88-timing_e.html. The initial clock pulse may not be necessary but it is in the diagram at the bottom of the page as part of the initial load/reset cycle. I'm happy to adjust it based on actual usage though. I can add an option to follow https://www.opendcc.de/s88/s88_n/s88-info_e.html instead of S88-n if needed.

    Based on this diagram the reset pulse is coming too soon, it should be coming after the clock pulse. The sequence is supposed to be LOAD HIGH, CLOCK pulse, RESET pulse, LOAD LOW, first bit, CLOCK pulse, etc...

    Does it read off-by-one in the display of data or does it sort itself out after the initial load? Also is this device adhering to S88 or S88-n? S88 is the older standard but it also shows the same clock pulse during load pulse.

    This is part of the init process, it is loading the config etc. Most of that is more for diagnostic info and not meaningful after init time.

    This can be done for sure. I'll put this on the TODO list.

    All tables in the status tab of the web interface need auto-refresh to be implemented, I haven't had a chance to implement it yet but it is on the TODO list.

    A 1k resistor on the ADC line should be fine, it will skew the readings slightly though. Something to try though, set ADC_CURRENT_ATTENUATION to ADC_ATTEN_DB_0 or ADC_ATTEN_DB_2_5 in Config_MotorBoard.h. This is a built in scaling factor on the ADC readings, the default is for full scale readings to support arduino motor shields which can feed over 3.9v when at "max".
     
    Lormedy likes this.
  3. Atani

    Atani TrainBoard Member

    1,466
    1,736
    37
    Looking at this again, you can adjust this some. The first sensor bus *CAN* start at 512 if you set S88_FIRST_SENSOR to 0 (zero) in Config_S88.h and you create your first S88 bus as ID 0 (zero). The comment above this define explains how the ID base is calculated (Bus ID * MAX SENSOR + FIRST_SENSOR). This was mainly done to shift all S88 sensors to a known starting point higher than the default sensor IDs (though, there are only so many pins on the esp32 to use for sensors it doesn't really make sense entirely to use the default sensor type)

    I missed the piece about the third bus not being displayed, did you create it with a unique pin definition? The CS checks for overlapping pins and will actively reject attempts to use a pin that is already in use, the web interface unfortunately does not display an error dialog when the CS rejects the request (it's now on the TODO list)
     
    Lormedy likes this.
  4. Lormedy

    Lormedy TrainBoard Member

    17
    1
    4
    You are right, the pin was rejected without any notice. I just try with another pin and it is ok. Nonetheless I only need 48 bits. Who needs 512 bits ? and 3 busses ?
    About current attenuator, I recommand to keep the maximum ADC_ATTEN_DB_11 and add a correction in software. It is safer for the ESP32 when the next module is powered with +5V.

    The Clock pulse should never occur when Reset is active. I disagree on one point of the opendcc drawing : Reset should be first before any Clock pulse in order to clear old information. Then the latest sensors informations are seen by the S88 module and few µs later comes the clock pulse with Load allready active. This clock rise latches all the data at the same time and bit 1 is output to the Data line. 16 data are shifted with 16 clock rises. And S88-N uses a RJ45 connector in place of the old 6-pin connector. RJ45 cables are much better against crosstalk with adjacent signals, ie DCC. Your soft is ok except the Reset pulse timing in the same time than the Clock pulse.
     
  5. ghruei

    ghruei TrainBoard Member

    33
    6
    2
    Ok, with my more basic issues and have gone over it all again. I have set the motorboard as below.
    MOTORBOARD_TYPE_PROG ARDUINO_SHIELD
    The pin configuration are the defaults
    #define MOTORBOARD_ENABLE_PIN_OPS 25
    #define MOTORBOARD_CURRENT_SENSE_OPS ADC1_CHANNEL_0
    #define MOTORBOARD_ENABLE_PIN_PROG 23
    #define MOTORBOARD_CURRENT_SENSE_PROG ADC1_CHANNEL_3
    #define DCC_SIGNAL_PIN_OPERATIONS 19
    #define DCC_SIGNAL_PIN_PROGRAMMING 18

    It all complies fine bar a few warnings about variables
    Then have the following linked:

    Motorboard to ESP
    5v to VIN
    GND to GND
    PWMA to D25
    PWMB to D23
    DIRA to D19
    DIRB to D18
    A1 to VN
    A0 to VP

    I fire it all up and the web interface loads ok. When switching power on the main, one led lights up, but other than that it unresponsive. When switching the prog on, it says fault.

    Using JRMI I can use the prog track ok both leds on the motorboard light up. It will correctly identify the decoder and I can program it. However when using the main I get no response or the motor just runs at full speed. I am confused why the web interface does not work on the prog track if the JRMI does I would assume the reponse would be identical and further why the main does not work correctly at all. Just to finish off attached are photos of the board setup.

    Hopefully this may give some clue what is going wrong.
     

    Attached Files:

  6. Lormedy

    Lormedy TrainBoard Member

    17
    1
    4
    Hi Ghruei,
    Your wiring seems ok. Then first you must select "Command Station" and "Locomotive Roster" and write a locomotive address. Second back to "Throttle" select "Acquire Locomotive" and select the locomotive previously declared. When you press "Confirm" DCC will be ON and will power your layout. Now by moving the speed cursor in the upper and left hand corner you can drive your locomotive under your control. The procedure is strict as software, may be too much.
     
  7. Atani

    Atani TrainBoard Member

    1,466
    1,736
    37
    You can also select a loco that is not in the roster by clicking the Acquire Locomotive button and clicking the "add" button on the dialog, it will then let you enter any locomotive number and use that.
     
    Lormedy likes this.
  8. Atani

    Atani TrainBoard Member

    1,466
    1,736
    37
    5v to VIN is not correct, you should connect 5v to 5v. The VIN pin may be connected to the h-bridge instead of the rest of the ICs on the motor shield (I haven't looked at the schematic in some time).

    Otherwise the pins look correct.
     
  9. Les B49

    Les B49 TrainBoard Member

    37
    3
    7
    Hi, Atani.

    Can you advise if I've done something stupid in my setup below, please?

    After a break of several months, I've returned to the ESP32 DCCpp route. Using the standard Arduino Motor Shield and a HiLetgo ESP-WROOM-32 ESP32, I've linked the two as shown below and compiled and uploaded your program.
    ESP32-----Arduino Shield
    GPIO25---3
    SVP-------A0
    GPIO18---12
    GPIO23---11
    SVN-------A1
    GPIO19---13
    GND-------GND
    5V---------5V

    The Motor Shield is wired directly into a DCC chip which is connected to the motor bogie of a Bachmann G scale tram. (No rails involved at this development stage!)

    When I power on the main track, my "loco" (with id of 3) immediately starts up (without entering on the Roster or directly acquiring it on the Throttle screen. Altering its throttle speed has no effect, nor does reverse or Emergency Stop.

    I notice on the Motor Shield only one of the two LEDs for the Main track is lit.

    (Note: the Shield was working fine with this same loco using standard DCC++ and an Arduino Mega 2560 yesterday - with both LEDs on the shield lighting.)

    Any thoughts please?

    Many thanks,
    Les
     
  10. Atani

    Atani TrainBoard Member

    1,466
    1,736
    37
    Without seeing what you put into Config_MotorBoard.h I can't say for certain that the pin assignments you have above are correct, but if we go off the default values in the file you have a mix of OPS and PROG on a few pins. Try this setup:

    ESP32 --- Motor Shield
    5V -> 5V
    GND -> GND
    SVP -> A0
    25 -> 3
    19 -> 12
    SVN -> A1
    23 -> 11
    18 -> 13

    I personally haven't had much luck with setting up the arduino motor shields except when using an Uno formfactor esp32 board. For other board types I've opted for other motor shield types with some success.
     
  11. Les B49

    Les B49 TrainBoard Member

    37
    3
    7
    Thanks for the speedy response.

    My original wiring was as per post 156. I've now tried the modified wiring you suggest (swapping the Pin 18 & 19 connections to the Arduino Motor Shield), but get the same effect - power is on immediately to the loco, only one of the two LEDs light when powering on either Main or Prog. No impact from trying to acquire my specific loco. (To be as "clean" as possible, I erased my old code copies, downloaded afresh from the Master GitHub repository, entered values for my WiFi connection and altered nothing else. Config_Motorboard.h is therefore as downloaded.)

    My problem seems pretty much the same as ghruei which you have been addressing recently. I note there you say Vin->5v is incorrect - it should be 5v->5v. On the schematic for my HiLetGo ESP32, there is only a single pin labelled VIN 5v. Is this perhaps my issue and if so, is there any way around this other than trying a different type of ESP32 and/or Motorboard?

    (As a drastic option what ESP32 & motherboard combination would you recommend that should work with minimal change to the code?)


    Thanks again.
    Les
     
  12. Jimbo20

    Jimbo20 TrainBoard Member

    274
    178
    11
    Hi Les,
    I too have taken a break from my model railway projects due to my house move, but I like to watch the forums to see whats going on!

    Looking at your issue, a thought comes to mind;

    Are you supplying 5 volts to the 5V pin on the motor shield and also a supply (eg 12V) to the VIN on the motor shield? I don't think it will work unless you do provide both pins with a voltage. This would normally be taken care of if the shield is plugged into an arduino because the arduino would supply the 5v pin on the shield via the regulator on the arduino
     
  13. Les B49

    Les B49 TrainBoard Member

    37
    3
    7
    Hello, Jimbo.

    Good to hear from you again after we've both had a break.

    Yes, the motherboard gets a supply (about 17v) from its own external adaptor. The 5v into the motorboard comes from the ESP32 chip, but as I said in the earlier post, on my particular ESP whilst the legend by the pin itself on the chip says just 5v, on the schematic sheet that came with it, it is labelled VIN 5v and I wondered whether Atani's comment in post 688 earlier might indicate this is the problem for me.

    This afternoon, just to check all of the non-esp32 hardware is still ok, I setup the motorboard with my Arduino Mega2560, and this still works fine, so it seems to me that the problem is specifically related to the HiLetGo ESP32 & Arduino motor shield combination.

    I just don't understand enough about the electronics involved in how the motherboard creates the embedded DCC signals within the power to the track to guess at where my pin connections may be wrong.
     
  14. Jimbo20

    Jimbo20 TrainBoard Member

    274
    178
    11
    My understanding of the esp32 5v VIN pin is as follows; The ESP32 chip internally runs on 3.3v. The 5v VIN pin is connected to a 3.3v regulator which powers the ESP32 chip. The 5v VIN pin is also connected to the USB connector, so if you connect a USB lead from a PC, 5 volts will appear on that pin (from the PC) so you don't need then to provide a separate 5v supply.

    So as I understand it, unlike the arduino the ESP does not have a 5 volt regulator, so whatever voltage is provided on the 5V Vin pin is reduced down to 3.3v for the ESP chip. If you plug in a USB lead from a PC or charger etc, then 5v (approx) will appear on that 5V VIN pin which you can feed to other items eg your Motorshield.

    I think Atani's comment was a misunderstanding in that he thought in that post 588 the 'VIN' pin was referring to the Motorshield's VIN pin (because he mentions the 'h-bridge') - which indeed could be a potential disaster if that pin was connected to a 5v esp board.

    So Les, I know you say that only one LED is on on the shield, will that LED switch on/off by powering on/off using commands?
    I'm sure the reason your bogie runs permanently is because you have dc appearing on the 'track' rather than a DCC signal/supply. This theory is backed up by the fact you only have one LED lit.
    I would advise that you disconnect your decoder and bogie until you can get both LEDs to light, to avoid any potential disasters with the tram hardware!
     
  15. Atani

    Atani TrainBoard Member

    1,466
    1,736
    37
    Yes, the VIN pin on the motor shield is connected to the h-bridge typically and should not be connected to the ESP32. In most cases the trace for this pin is cut as part of the arduino usage of the shields, on esp32 this should also likely be done.

    Yes, the VIN pin on the esp32 should be used only as voltage input and should not be used to power external devices, it would depend on the esp32 board likely as to weather or not it will have any power when the USB connector is used or not.

    Ideally you will have a dedicated 5V power supply that feeds both the esp32 VIN/5V pin and the motor shield 5V pin.
     
  16. Atani

    Atani TrainBoard Member

    1,466
    1,736
    37
    For the easiest compatibility with the arduino motor shields I've used an esp32 board with an uno layout, these can be found on aliexpress or similar sites for ~$5 USD. However, I'm working on shifting to a TTGO-T1 board with custom PCB with the L298 IC on the PCB with a few other features included. I'll be sharing the PCB for that in the near future, I still need to have it produced and tested before I share it.
     
    bocabob likes this.
  17. Jimbo20

    Jimbo20 TrainBoard Member

    274
    178
    11
    Just to clarify though, in the post 588 ghrue did not suggest that the Motor board VIN is connected to the ESP 5V pin, he had it the other way round, which could work - depending on how good the motor board's 5v regulator is.

     
    Atani likes this.
  18. Atani

    Atani TrainBoard Member

    1,466
    1,736
    37
    I wouldn't connect any higher than 7.5VDC to the VIN pin on the ESP32, it will depend on the circuit but 5VDC is likely safer.
     
  19. ghruei

    ghruei TrainBoard Member

    33
    6
    2
    Ok. Just to confirm I was taking the 5v from the ESP32 as I was powering it from the usb. So is it possible may be that under load this is insufficient for the motorboard. So now I am going to get a separate 5v supply for the motor board and just tie the motorboard and ESP32 GNDs together and see where we go from there. I did wonder why this PIN was marked as VIN on the ESP32 if you can use 5v from it. Makes sense it purely there as alternative power source for the ESP32.

    Further to note I think as mentioned earlier I have seen exactly the same issues mentioned in post 689. Which makes me feel a bit better as it suggest there is a common problem with the hardware setup.

    Anyway I going now to try this separate 5v supply route. See if I destroy anything else this time.
     
  20. Atani

    Atani TrainBoard Member

    1,466
    1,736
    37
    Yes, it is entirely possible the 5v pin can provide less than 5v when the esp32 is under full load (all GPIO set to HIGH).

    Yes, many boards will have either a pin labeled at 5v or VIN which can be used to power the board, they should not generally be used for other devices unless the board is powered by greater than 5v and has both a 3v3 and 5v regulator on board (most only have 3v3). If a board only has the 3v3 you can provide 5-7.5vDC to the VIN pin safely provided it is at least 500mA (wifi can use up to 300mA by itself when active). For powering multiple devices a standalone 5vDC power supply is advised.
     

Share This Page