ESP32 Command Station

Atani Dec 10, 2017

  1. Guywire

    Guywire New Member

    8
    1
    2
    I actually got it working! Really long delay sometimes though with the dcc commands, like 10+ seconds to change speed. Cool project.
     
    Atani likes this.
  2. Atani

    Atani TrainBoard Member

    1,331
    1,022
    27
    Which version are you running that you are seeing a long delay?
     
  3. Guywire

    Guywire New Member

    8
    1
    2
    I don't see any version number in the web app and the file just says ESP32CommandStation-master.zip. I downloaded it from github yesterday, so I'd guess it's the latest one.

    Anyway, it could be any number of things as my assembly might have multiple loose wires and wrong components.
     
  4. Atani

    Atani TrainBoard Member

    1,331
    1,022
    27
    Was it a master snapshot or was it a release?

    Possibly or it could be a real bug :)
     
  5. Guywire

    Guywire New Member

    8
    1
    2
    It was the master from here https://github.com/atanisoft/ESP32CommandStation/archive/master.zip

    When I get things all soldered up we'll see if it's better. And it looks like I won't get the correct sensing resistors until sometime in January. The current usage readings are all over the place right now on the status section.

     
  6. Atani

    Atani TrainBoard Member

    1,331
    1,022
    27
    Make sure to have the GND pins connected otherwise there is likely going to be very inconsistent readings.

    As for the version, it sounds like you have v1.5.0-beta2 (or what it would be).
     
  7. AndyH

    AndyH TrainBoard Member

    77
    9
    5
    Trying to compile using a command prompt command, and running into an error - can't find gzip programme. Where have I gone wrong? How do I fix? Thanks.

    Also, I presume that I get to edit what I want included in the build and the appropriate output pins through the compiler programme? Previously I edited this directly in the coding in VS Code.
     
  8. Atani

    Atani TrainBoard Member

    1,331
    1,022
    27
    You can download gzip from http://gnuwin32.sourceforge.net/packages/gzip.htm (I'd use the zip file) and extract it to C:\bin or the "\bin" directory on whichever drive has the ESP32 Command Station code on it.

    To some extent yes, you will be able to do this via "idf.py menuconfig". There aren't many free GPIO pins on the ESP32 though so don't count on outputs or sensors being usable, in fact these are very likely to be dropped entirely from v1.5.0 with exception of S88 sensors.
     
  9. AndyH

    AndyH TrainBoard Member

    77
    9
    5
    Proposed pinouts are:
    Scl - 35
    SDA - 32
    main enable - 25
    Main dcc - 19
    Main current sense - 33
    Prog enable - 23
    Prog dcc - 18
    Prog current sense - 34
    Hc12 tx - 27
    Hc12 rx - 14
    LED - 22

    I had to change a free from standard as o recall as I didn't have them on my esp32 board.

    This leaves 26, 13, 21 and 4 free. I seem to recall that 0, 2, 5, 12 and 15 are blocked for some reason.

    Also, do you need the msd card for this version? I have a second board that doesn't have one.

    Sent from my SM-N976B using Tapatalk
     
  10. Atani

    Atani TrainBoard Member

    1,331
    1,022
    27
    Pin 35 is input only and won't work for SCL, I'd suggest use 21 and 23 (defaults) if you can.

    I'd suggest use 36 and 39 for current sense, these may be labeled as SVN (39) and SVP (36) on your board. Which h-bridge(s) are you planning to use?

    pin 14 is used by SD, I'd suggest move this up to 35 where you have SCL currently. HC12 is experimentally supported at this point and may be dropped in the future.

    I'd recommend using an SD card over the SPIFFS partition since it is faster and will not cause unnecessary writes to the built-in flash. Keep in mind that some pins are reserved for SD and are used during startup (and potentially runtime): 2, 13, 14, 15. I'll be adding these pins to the validation logic to ensure they are not used by other modules.

    These are bootstrap pins and have built-in pull-up or pull-down resistors on them. Some of these can be used for specific purposes (SD, TWAI/CAN, etc) but generally should be avoided for general usage.
     
  11. AndyH

    AndyH TrainBoard Member

    77
    9
    5
    I've got 21, but no 23.

    I've not got 36 or 39. I have VP, VN, Rst, 34, 35, 32, 33, 25, 26, 27, 14, 12, 13, 15 down left hand side, and 3.3v, 21, TX, RX, 22, 19, 23, 18, 5, 2, GND, 0, 4 and 5v. Will 33/34 work? Any other suggestions?

    Looking at my schematic, could I swap HC12 TX to 32 and RX to 35 (physically next to each other) and SCL/SDA to 26/27 (again physically next to each other)?

    I'm using an L298N for the programming track (yes, I know about the resistor for current sense) and a BTS7960B for main. I have either a 19v power supply or a 16v (all c. 3.4A max). I'd sooner use the 19v if I can because I have two of them, and only one 16v.

    OK, I can move HC12 RX to 35, and then SCL to 26?

    OK, guess I'll try and find a second SD card board for a second station.

    Cool. I'll leave these clear.
     
  12. Atani

    Atani TrainBoard Member

    1,331
    1,022
    27
    VP = 36, VN = 39. It also seems you might have missed pin 23 as you said earlier you don't have it.

    Be *VERY* careful with the BTS7960. Due to the high amperage support I do not generally recommend this h-bridge since the short cut-off built into it is not going to be tripped until it is too late. The CS is configurable to trip around 5A or 10A when using the BTS7960.

    For the L298 current sense you can use a 0R15 1/2W (or larger) resistor to GND and connect to this circuit as the input using R1 = 1K, R2 = 10k, VCC = 3.3v. This is based on the arduino motor shield.

    The 19v supply would be ok for some scales but in most cases it will be too high. The BTS7960 should put out around 1.5v lower than the supply to the track.

    That should be fine. Keep in mind pins 34-39 are input only and should be treated as 3v3 logic only. For your I2C needs that means using a 2k2 pull-up to 3v3 on SDA/SCL and powering the devices via 3v3. If you have a 5v only device you will need to use a mosfet to switch voltage levels on SDA/SCL with pull-ups on both sides (4k7 on the 5v side)

    I've had the best luck with the TTGO T1 boards, they have a 3D metal antenna and SD card slot built in. These are around $5 US through various online stores. This is also the base module I've used for my CS PCB and a few other OpenLCB/LCC PCBs.

    For reference, this is the breakdown of pins for SD:
    • 2 - MISO
    • 13 - CS
    • 14 - CLK
    • 15 - MOSI
     
  13. AndyH

    AndyH TrainBoard Member

    77
    9
    5
    So I did. I seemingly lied. I do have it. I'll use defaults then.


    How do you mean be very careful? What should I do or not do? I am only looking to use the BTS7960 because of the higher amperage, i.e. running multiple trains. I.e. using it effectively as a booster, but as the main output rather than an add on booster. Am I doing something stupid here? Is there an alternative that will run multiple locos without a booster? What's the risk, and how can I mitigate it?

    I was unaware of the circuit. I presume that Vin would be from the current sense pin. My previous understanding was that you cut the last leg on the L298, you put your 0R15 resistor in between the leg and the hole it originally had on the circuit, and then take a feed from between the leg and the resistor. Is this not correct?

    I run OO, some of which are modified ringfield using CD motors. I can use the chip to reduce the peak output of the motor, or use diodes on the motor side to drop the voltage to these locos - I'm already doing a lot of work on them as they are old requiring hard wiring of the chip and additional weight to properly run.

    Thanks. I'll take a look at what I have on the I2C board. I'll also be re-checking the pins that I have vs the recommended pinouts. Do you happen to have a list of them? I'm only looking for HC12, LCD, main and prog tracks and LEDs. Everything else is superfluous to my needs at the minute.

    Thanks. I couldn't get hold of a T1 in the UK, and am stuck using a T8. I can get Lilygo TTGO T1s from AliExpress for £4 plus £5 p&p - 3 for £16.70.I'll see how the T8 goes, and then see what I want to do for the second CS.
     
  14. AndyH

    AndyH TrainBoard Member

    77
    9
    5
    I've just thought about this. The H bridges are 5v logic. If 34-39 are 3.3v logic, won't the current sense outs need some sort of circuit in the middle to drop the voltage?

    And does the 3.3v pinout on the ESP32 give a 3.3v output if you are using a 5v input voltage on it?

    Thanks
     
  15. Atani

    Atani TrainBoard Member

    1,331
    1,022
    27
    The T8 should work well, it has a PSRAM chip on it using pins 16 and 17. Schematic: https://github.com/LilyGO/TTGO-T8-ESP32/blob/master/t8_v1.7.1.pdf

    Do not use pin 35 as it is used as part of a battery voltage sense connection (refer to the schematic page 1 right side middle box)

    The BTS7960 built-in short cut-out is not going to be triggered until it goes above ~43A current draw. There is a reason few commercial booster goes above around 10A.

    That depends on how many trains and what sort of decoders they are. Sound decoders can consume more current than non-sound.

    Mostly correct, the line from the leg/R is a voltage divider and should be put into the LM358 op-amp circuit to boost the analog signal to be in the right range for the CS to detect it.

    The default pins in the config will work for most usages:
    • OPS EN: 25
    • OPS SIGNAL: 19
    • OPS SENSE: 36
    • PROG EN: 23
    • PROG SIGNAL: 18
    • PROG SENSE: 39
    Recommended pins for other peripherals:
    • TWAI (CAN) RX: 4
    • TWAI (CAN) TX: 5
    • StatusLED: 22 (NOTE: I've tested with five APA106 LEDs, support for a shift register or I2C expander with LEDs is planned for the future)
    • StatusDisplay SDA: 21
    • StatusDisplay SCL: 22 (NOTE: change this to 23 when using the StatusLED module)
    Note that HC12 does not have a set of default pins assigned to it, I'd suggest using one of the 34-39 pins for RX and any other lower pin for TX.

    This is part of the reason why the LM358 should be used. Most of the h-bridges will work at 3v3 but some will not. There are other options as well depending on your soldering skills (ie: INA119 + shunt resistor on power supply to h-bridge with output feeding into the ESP32, this is the plan I'm going with on the CS PCB).

    Feeding 5V to any pin on the ESP32 will likely result in a dead ESP32. The only pin that can accept 5V input is labeled as 5V and feeds into the 3v3 1A LDO.
     
  16. AndyH

    AndyH TrainBoard Member

    77
    9
    5
    I thought that the current sense provisions would enable you to cut off at either 5A or 10A, hence needing to get the current sensing right. Is there a better way to do this? Could I put a fast blow fuse inline between the CS and the track so that it won't exceed the 10A peak?

    Less than 10, mainly non-sound. I don't do sound, but my son likes it. He currently has the one, but I'm sure there will be others.

    So leg-resistor-old leg hole, with a feed from between the leg and the resistor going into the 358?

    Does the BTS7960 work at 3.3v? If not, should I replicate the LM358 circuit? My soldering skills are pretty good until it comes to surface mount. I can cope with LEDs (badly), but that's about it.

    Plan was to use the 16v input to power everything. I have a regulator set up to step the input down to 5v to power the board through the 5V input pin (unless it is being powered by the USB, for instance if using direct with JMRI - trying to set up a hard block system so I cannot power through the 5v in if USB is plugged in as I understand this is bad).

    Will this work?

    Unless if I'm reading the schematic right, I can power using the 5v into the battery input on it, and there is a hard isolation so that USB power will always override the battery input? So I can't ever screw it up if I use that power input?
     
  17. Atani

    Atani TrainBoard Member

    1,331
    1,022
    27
    The CS can only offer a software solution to a hardware issue. I'd recommend a PTC fuse of some sort on both of the output lines to the track that is at the maximum you feel comfortable with running.

    Likely you could start with a lower amperage h-bridge and grow into the BTS7960 if/when you need it.

    I believe yes.

    I can't say for certain but from memory it should be fine for the inputs to the BTS7960.

    JMRI will *NOT* talk to the CS via the USB port. The USB port is only for diagnostic output. I'd suggest avoiding using the USB port and external 5V supply simultaneously since you can't control the power routing between the two in a pre-made board.

    I haven't reviewed the schematic in depth as I don't have that board. In my usages of the T1 I only use USB when doing initial flashing and debug testing on my desk. On the layout the CS PCB is powered via a 15V supply which is passed through an LM2675-5 to bring it down to 5V which goes into the 5v pin on the ESP32. I have other designs which power the ESP32 from the OpenLCB connection (15v 500mA nominal) with a 5V 2A LDO and 3v3 1A LDO feeding to the ESP32 3v3 pin (https://github.com/atanisoft/esp32olcbio) and one for the ESP32-S2 which exposes 32 5V IO pins:
    pcb.png

    I've shifted almost entirely to SMT components in the latest design of the CS PCB (which is going to be redesigned over the next couple weeks):
    pcb-front.png
    This is using the LMD18200T for OPS, DRV8801 for PROG and OpenLCB. I'm working on a redesign of this unreleased PCB to fix a few shortcomings of the current design related to the LMD18200T (which is becoming very expensive to obtain). As part of the redesign there will be a few other changes coming to the PCB:
    • Swap LMD18200T for DRV8873 (10A limit compared to the 3A limit, but will be capped at 5A via hardware/software)
    • Swap the LM2675-5 for AP63205WU (see the ESP32 S2 IO image above, it is to the right of the top RJ5 between the capacitors and inductor, it's a TSOT-23-6 package)
    • Add 3v3 LDO to power the ESP32 instead of the 5V input.
    • Add jumper to power the ESP32 via OpenLCB connection (maybe!)
    • Swap to INA2180A2 for OPS/PROG current sense with ULR1R006FLFTR as shunt.
    • Redesign the PCB as 4 layer instead of 2 layer. This does increase costs but the benefits outweigh the costs.
    • Remove the UART1 header
    • Rename one of the I2C headers to OLED/LCD and extend to six pins (n/c and OLED RESET)
    • Adjust PCB size to fit SnapTrak rails (~80mm max height, current PCB is 100mm)
    • probably a few more tweaks that I've not tracked yet...
     
  18. AndyH

    AndyH TrainBoard Member

    77
    9
    5
    Done

    How do you talk to JMRI then, in particular, using it with Decoder Pro to set up decoders? I haven't progressed past the original model of an arduino mega and a USB hard wire connection to JMRI (so am a few years out of date on the hardware front). Sorry that we're going into basics.
     
  19. Atani

    Atani TrainBoard Member

    1,331
    1,022
    27
    Via WiFi. There is no need to have a direct physical connection *UNLESS* you are using OpenLCB/LCC (and even then it is somewhat optional).
     
    AndyH likes this.
  20. AndyH

    AndyH TrainBoard Member

    77
    9
    5
    Thanks for your help. I'm sure I will be back soon...
     

Share This Page