ESP32 Command Station

Atani Dec 10, 2017

  1. Atani

    Atani TrainBoard Member

    1,466
    1,736
    37
    Not sure on the WiFi.h piece but that looks less critical. You will need to generate the index html header file. In platformio ide this is done automatically via the included Python script. For Arduino ide it needs to be done manually. If you know python you could use the script as a basis for creating the necessary file. If not let me know and I can post it

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

    Shdwdrgn TrainBoard Member

    251
    182
    13
    I did copy index.html from the data folder, gzipped it, then ran it through bin2c with this:
    # bin2c index.html.gz index_html.h data

    I think I read somewhere here that 'data' was the correct array name, however my array size is coming out to 6944 which doesn't match what was said above. So if it's easier, could you either send me the correct index_html.h or post it as part of the git source?

    By the way, removing libraries/WiFi/ did get rid of that other error, hopefully the rest will compile once I have that other file.
     
    Scott Eric Catalano likes this.
  3. Atani

    Atani TrainBoard Member

    1,466
    1,736
    37
    Data is not the right array name. It should be declared as shown above, size is not critical as long as your size is put in the file correctly.

    Be sure to put PROGMEM on the declaration line as well for the array.

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

    Atani TrainBoard Member

    1,466
    1,736
    37
    The array name should be indexHtmlGz

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

    Shdwdrgn TrainBoard Member

    251
    182
    13
    All right, progress! For archival reference here's what I've done...

    # cd DCCppESP32-master/DCCppESP32/
    # cp ../data/index.html .
    # gzip index.html
    # bin2c index.html.gz index_html.h indexHtmlGz

    Now in the newly-created index_html.h, remove the first line "const char indexHtmlGz[6944] = {" while noting the number in the square brackets (in my case this was 6944). Replace the first line with these two lines, substituting the array size that your file has:

    const size_t indexHtmlGz_size = 6944;
    const uint8_t indexHtmlGz[] PROGMEM = {


    Save the file and load the project in the arduino IDE.

    Finally able to fully compile the code by creating a new VM with the latest Debian build, now I just have to figure out how to move the compiled code back to my desktop so I can flash it to the new lolin32.
     
  6. Shdwdrgn

    Shdwdrgn TrainBoard Member

    251
    182
    13
    Worked out the issues and am able to flash the code to my lolin32, now of course there's more questions...

    First off, in Config.h there appears to be the ability to define a static IP address, which I have configured as such:
    #define IP_ADDRESS {10, 27, 0, 2}
    Unfortunately it is still using DHCP to obtain an address each time I restart, and I cannot find any reference to IP_ADDRESS elsewhere in the code. I'm guessing that bit of code hasn't been finished yet?

    Next, the OLED display on the lolin32 boards. I have confirmed via SD1306DrawingDemo_I2C that the proper address is (0x3C, 5, 4), however these values are not working under DCC++. Again in Config.h I have set the following:
    #define INFO_SCREEN_OLED true
    #define OLED_CHIPSET SH1306
    #define INFO_SCREEN_OLED_I2C_ADDRESS 0x3C
    #define SDA 5
    #define SCL 4
    #define INFO_SCREEN_OLED_VERTICAL_FLIP false

    Note that the default values for SDA and SCL were 21 and 22, so I redefined them to the correct values. Within InfoScreen.cpp the return code for Wire.endTransmission() is 2 (received NACK on transmit of address). It looks like in the 1306 test code there are no calls to the Wire function, but in InfoScreen.cpp it is used extensively. I'm not familiar enough with the display libraries to know what *should* be happening here, though, I can only say that nothing is being sent to the display.
     
    Scott Eric Catalano likes this.
  7. Atani

    Atani TrainBoard Member

    1,466
    1,736
    37
    Correct, static IP is not currently supported. I haven't found a clean way to implement it on the ESP32, I saw some possible options on it but haven't gotten to implementing them yet. This should be tracked via an issue on github for implementing this feature. When this gets implemented there will be more than one parameter here, we will need gateway, subnet, and optionally DNS.

    It sounds like you have the wrong ESP32 board type definition. I checked and I could not find any suitable board definition that has SDA/SCL on pins 5,4. An actual LOLIN32 board does in fact have SDA/SCL on 21/22 like almost all other boards. If enough information can be found on the board that you have a new board variant can be added to the arduino-esp32 repository and then your overrides can be removed.

    Note that your overrides in Config.h will not work for everything. As you found Wire does not work correctly with your overrides, it does not include Config.h (nor should it). Other libraries will behave similarly.

    I will add custom names for SDA/SCL so you will not be remapping the PIN names coming from Arduino-ESP32 board definition (pins_arduino.h). I have pushed this to github a few mins ago. Please try it out, this should also resolve the Wire issue in InfoScreen.cpp that you noted. That code is a shortcut method for detecting if a device with the specified ID is on the I2C bus, it was failing since the Wire library defaults SDA/SCL as part pins_arduino.h. In https://github.com/atanisoft/DCCppESP32/commit/daf1cb0390b4dd889b4bca68a3b8758ddfc1ca3e I added overrides to workaround this issue.
     
    Scott Eric Catalano likes this.
  8. Atani

    Atani TrainBoard Member

    1,466
    1,736
    37
    Looks like you are not the first to hit this issue of incorrectly mapped SDA/SCL pins... https://github.com/espressif/arduino-esp32/issues/930

    There is no official board variant for that yet but this may work for you as another solution.
     
    Scott Eric Catalano likes this.
  9. Atani

    Atani TrainBoard Member

    1,466
    1,736
    37
    This is now implemented in 1.0.6: https://github.com/atanisoft/DCCppESP32/commit/bfadab56cae41b30edef7027f1861c03e5011d22. While the support for static IP is not 100% necessary for all usages it does appear to speed up the WiFi connection process some. One thing I have noticed with the ESP32 is the WiFi library can be unstable at times and refuse to connect to the AP without a restart of the ESP (the base station code should handle this after around a minute of trying to connect).
     
    Scott Eric Catalano likes this.
  10. Shdwdrgn

    Shdwdrgn TrainBoard Member

    251
    182
    13
    Well you've been busy this morning!!! I recompiled the new code, everything looks great from here. Static IP is working and I have a display now. Next step for me is figuring out how to send DCC commands and digging into how the H-bridge is supposed to be connected to everything. Can you recommend any decoder software that I could install on the ESP8266-12 I have on my loco which would be compatible with this base station (I don't have any DCC-enabled locos)?

    Regarding SDA/SCL, I think the problem is that there is a bare lolin32, and then there's the module that has the OLED. While both boards are of similar size, I think they're wired up very differently and don't even have the same pinouts to the headers. So the lolin32 we see in the arduino IDE is in fact the bare board without the display. Probably doesn't hurt to have custom definitions for the pins anyway, for easier support of future boards or custom setups.

    [EDIT] I just remembered reading about the web page output... loaded it up on the raspberry pi and that is working fine as well, so now I just need to physically hook up the track.
     
    Scott Eric Catalano likes this.
  11. Atani

    Atani TrainBoard Member

    1,466
    1,736
    37
    Set your board type as d-duino-32. That is what this board really is from what I can find. I am waiting for one to arrive on the very slow boat from China.

    And yes today has been productive. I don't know of any decoder software/support for any esp8266 boards.

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

    Simon Mitchell TrainBoard Member

    113
    105
    7
    I’ve attempted a WiFi decoder here http://www.trainboard.com/highball/index.php?threads/dcc-wi-fi-receiver-trackside-or-onboard.99820/

    Note that I am taking the command inputs TO the DCC++ base station, rather than the DCC format outputs, which are only transmitted to the track, and therefore not available over WiFi. The DCC protocol just sents a bucket load of signals and hopes that some get through, so would be very noisy in the WiFi space, hence my approach of grabbing the command inputs.

    I’m travelling at present, but intend to use this ESP32 project as the responding base station, do a little java chat server on my RPI3, and point everything at that chat server. This will mean I can simplify my code to avoid replicating the DCC++ base station confirmations.

    Cheers
     
  13. Goofy

    Goofy New Member

    3
    3
    1
    Hello all. First post here on TrainBoard, and all (pls be gentle :) )

    I Just love this DCC++ESP32 thing..
    Installed python, atom, PlatformIO ... Downloaded code, compiled and finally uploaded to my ESP32-Wroom-DEV-board.
    Works just fine on first try.. Very impressing. And quite some code standard from what I've seen.

    But I do have some Issues:
    1: The pin for Main Track Current-sense is "ADC1_CHANNEL_2" however, this "pin" is not accessible on the Wroom-DEV-board,
    I simply change the config to use ADC1_CHANNEL_7 instead. Is this ok?

    2: I can not send any instructions like "< 0 >" or "< 1 >" over the Serial Terminal... Nothing happens. I can use the web-page, and even things like "http://192.168.0.151/powerStatus" works just fine. What am I doing wrong?

    Final question: Sending instructions to BaseStation over WiFi, how? Web sockets? Anything that gets me in the right direction is highly appreciated.

    Many thanks in advance /

    <code>
    Unable to initialize InfoScreen, switching to Serial
    DCC++ESP: v1.0.7
    IP:pending
    [WiFiInterface.cpp:52] begin(): Connecting to WiFi: Heisenberg
    [D][WiFiGeneric.cpp:265] _eventCallback(): Event: 2 - STA_START
    [WiFiInterface.cpp:54] begin(): Waiting for WiFi to connect
    [D][WiFiGeneric.cpp:265] _eventCallback(): Event: 7 - STA_GOT_IP
    [D][WiFiGeneric.cpp:265] _eventCallback(): Event: 7 - STA_GOT_IP
    192.168.0.151
    [MotorBoard.cpp:40] GenericMotorBoard(): [MAIN] Configuring motor board [ADC1 Channel: 7, currentLimit: 1960, enablePin: 25]
    [MotorBoard.cpp:40] GenericMotorBoard(): [PROG] Configuring motor board [ADC1 Channel: 6, currentLimit: 1960, enablePin: 23]
    [V][DCCppProtocol.cpp:246] registerCommand(): Registering interface command t
    [V][DCCppProtocol.cpp:246] registerCommand(): Registering interface command f

    </code>
     
    Scott Eric Catalano likes this.
  14. Atani

    Atani TrainBoard Member

    1,466
    1,736
    37
    Welcome!

    Thanks! I have tried to simplify the code where possible, it is not perfect but it is a lot easier to follow in most areas. I am glad that you had no issues with setting everything up. Make sure the platformio.ini file lists the correct esp32 board, you can find the name via platformio home inside the ide via the boards tab.

    That is fine. It just needs to be one of the ADC1 pins. ADC2 pins conflict with WiFi and are not usable for that reason. Also are you sure this pin is not exposed on your board? It is often named SVP or SVN (those are alternative names for the two ADC1 pins used by default)

    The serial console is only for diagnostics. It is not an input source for commands. Sorry. You can control everything via JMRI or the web interface.

    The web interface uses a couple approaches, it is using standard http protocols for most of the base station tabs. For the throttle and the console on the base station tab, websockets are used.

    I need to add a method for sending arbitrary commands to the base station to the web interface, that is on the Todo list.


    Sent from my ONEPLUS A5010 using Tapatalk
     
  15. Goofy

    Goofy New Member

    3
    3
    1
    Thanks!

    Not sure at all. But from the schematics it looks like SVP and SVN are ADC1_0 and ADC1_3, ADC1_2 is on GPIO38 on the esp-32 chip.

    https://dl.espressif.com/doc/esp-id...e/peripherals/adc.html#_CPPv214adc1_channel_t
    This is the board I'm currently using : https://cdn.instructables.com/ORIG/FQM/7X6B/J7GGGD9O/FQM7X6BJ7GGGD9O.png

    Has anyone got Main Track Current-sense to actually work? (using ADC1_2) I think this is a really important feature of the design. I do not want to BBQ any dcc-loco-decoders :D

    Ahh, Thanks for the heads up. I wasn't really going to use it anyway, just wanted to test my understanding of the API..


    Nice!
     
    Scott Eric Catalano likes this.
  16. Atani

    Atani TrainBoard Member

    1,466
    1,736
    37
    I don't see gpio 38 exposed on that board. I do see 36 and 39 which are the default pins used in the config as ADC1_0 and ADC1_3. I don't have a board with ADC1_2 exposed but it should work the same as any other ADC1 pin.




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

    Goofy New Member

    3
    3
    1
    Correct, that is because the Wroom32 Module itself is like so: (no boards using this esp-32 module can ever make use of ADC1_2)
    http://www.pighixxx.com/test/portfolio-items/new-esp32-wroom32-module/#prettyPhoto[gallery1379]/0/

    Well, this is a bit confusing. I think the default pins used in the config actually is ADC1_2 and ADC1_6

    here : https://github.com/atanisoft/DCCppE...f7239236af93d33e05b0b54feda8/src/Config.h#L40
     
    Scott Eric Catalano likes this.
  18. Atani

    Atani TrainBoard Member

    1,466
    1,736
    37
    I will need to check the board I am using, but it is likely an oversight.

    Defaults should be ADC1_0 and ADC1_3.

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

    Shdwdrgn TrainBoard Member

    251
    182
    13
    I finally received my BTS7960B bridge last night, got it hooked up and appear to have a signal on the tracks, but I got stuck on how to adjust the current sense input. On trainelectronics.com they recommend using a 10k pot to dial in the cutoff point. It seems like there are a couple of things I would still need -- a way to see what value is being read by the current sense pin on the esp32 (did I read somewhere Atani was considering adding that to the OLED display?), and a way to create a known load across the tracks. For the moment I'm using a 16V 4.5A power supply. If I simply short out the tracks the display on my volt/amp meter (the red/blue module) flickers quite a bit but neither the BTS7960B or the ESP32 ever seem to cut power.

    With the current power supply I'd like to have it cut off above 4.0A. Is there a way I can create a variable load without ordering some monstrous resistors? The only thing I can think of is trying to rig up a bunch of diode bridges and large DC motors, but I don't have any motors that very much current.

    And what about on the base station side? Is there a quick line of code I can add to show the raw value from the ADC? Maybe if I can get a good reading for some known current loads I can extrapolate forward to guestimate a cutoff around 4.0A. Also I thought there was a value stored somewhere in DCC++ that sets the cutoff value but I can't seem to find it anywhere.
     
    Scott Eric Catalano likes this.
  20. Jimbo20

    Jimbo20 TrainBoard Member

    274
    178
    11
    Can you lay your hands on a few car light bulbs? a 21Watt 12V bulb would draw about 1.75 Amps at 12V, possibly a little more on 16V.
     
    Scott Eric Catalano likes this.

Share This Page