ESP32 Command Station

Atani Dec 10, 2017

  1. Atani

    Atani TrainBoard Member

    1,460
    1,697
    36
    The DCC++ESP32 Base Station code has been published here: https://github.com/atanisoft/DCCppESP32. This is not a fork of my DCC++/ESP8266 code base but instead a rewrite, mostly from the ground up. This code requires only an ESP32 and a compatible motor shield for the basic functionality. If you have an OLED or LCD screen additional functionality can be enabled.

    I am working on the wiki pages for this still but the basics of setting this up are documented in the README already. The only piece that is not covered is how to use the ESP32 with an Arduino Motor Shield when the ESP32 has the Arduino board layout (ESPduino32 as example). For that setup jumpers may be required to connect A0/A1 to usable pins (on my board they are wired to GPIO0 and GPIO2 which are not usable when WiFi is active)
     
  2. NormHal

    NormHal TrainBoard Member

    138
    126
    12
    Hi Mike, firstly I must again thank guys like you for sharing your creative efforts!:notworthy:

    I have been trying out your previous efforts with the ESP8266 and an Arduino, so am very interested in your version which makes the Arduino redundant. Whilst I have some ESP32 devices somewhere on the sea or in the air, we have to wait sometimes in excess of two months for stuff to clear our local customs - a real pain:-( . I've got at least a month to go:-(

    I managed to compile your latest code, albeit with some very minor "bugs" when I enabled LCD - I'd be happy to share the corrected infoscreen.cpp file if you wish:)

    A question for you. Do you think it would be possible to "port" your code to an ESP8266 12E? I have a few and was wondering if it would be worth the effort? Additionally, one capability I would like to achieve is an "S88" support feature. Yes, I know S88 is noise prone, but I do feel it's an efficient method to support multiple sensors.

    I'd appreciate your comments:)

    Again, thanks for your latest (and past) postings - you really do add to this hobby of ours:)

    Best,
    Norm
     
    Scott Eric Catalano and Atani like this.
  3. Atani

    Atani TrainBoard Member

    1,460
    1,697
    36
    Please submit a bug report on github for tracking it, if you can submit a pull request it would make fixing it even faster likely :) I haven't tested the LCD in a while so it is very likely broken slightly. I will hook it up and test it out after you send the details.

    If you want to use an ESP8266-12E you in theory could but you would be limited to just one motor shield and only PROGRAMMING or OPERATIONS signal. The SignalGenerator code would also need to be heavily adjusted as the current code requires all four hardware timers to generate the two DCC signals. The ESP8266-12E only has one hardware timer so an alternative approach would be required where you use a boolean flag to say "first" or "second" call when flipping the direction pin state *AND* picking up the next bit to send. The current code uses two timers, one for direction pin flip and one for picking the next bit to send. It might work but as I don't have an ESP2866-12E to test with I don't know how much work it would take exactly.

    I don't know much about S88 unfortunately, I have seen the term before but unsure what exactly it is used for.

    I am also considering how to support outputs, the ESP32 has only a handful of pins available for outputs (0-33, some are already in use though) and only a few additional pins that are input only (34 and above, these are mainly ADC1 pins). I am thinking I2C is an acceptable approach but to support that some sort of mapping mechanism would be needed to map the output/sensor ID to an I2C address/pin.
     
    Cymen and Scott Eric Catalano like this.
  4. esfeld

    esfeld TrainBoard Member

    442
    382
    17
    Hi Mike

    I am thrilled that you have pursued this route and look forward to further involvement. I am embarrassed to say that I have never had success with Platformio from previous projects (something to do with my desktop setup). Is there any chance that you could publish the code for Arduino IDE compilation? Thanks
    Steve F
     
    Scott Eric Catalano likes this.
  5. Atani

    Atani TrainBoard Member

    1,460
    1,697
    36
    It should compile fine with the Arduino IDE provided you have configured it for ESP32 development (see: https://github.com/espressif/arduino-esp32 for instructions on that). Aside from that you will need to install the necessary libraries for the project, you can find a list of these here: https://github.com/atanisoft/DCCppESP32/blob/master/platformio.ini#L16. A couple of these are built-in libraries from the arduino-esp32 code: SPI, ESPmDNS, Preferences, Wire.

    I have added this to the backlog for documentation: https://github.com/atanisoft/DCCppESP32/issues/1

    Also what issue did you face with PlatformIO? I haven't seen any so far, perhaps we can discuss on PM if you prefer not to share details on here.
     
  6. NormHal

    NormHal TrainBoard Member

    138
    126
    12
    Thanks so much for your immediate response Mike!

    Seems like the ESP-12E option will be too complicated for my limited C/C++ knowledge:-(

    S88 is a system originally developed by Marklin, which continually polls up to 31 devices, each having 16 inputs (a total of 496 sensors). Each device is "daisy-chained" to the next. A poll sequence involves (at max) 31 x 16 = 496:)) clock pulses to serially stream in the state of each sensor device's inputs. I say "max" because fewer devices would need a (configurable) number of devices to clock in.

    The implementation is fairly simple. A Clock line:), a Data line-), a Load line (to move the 16 input states of each device into its shift register), and a(n optional) Reset line (which I have found redundant). Sequence of events is thus, pulse the "Load" line to load (up to 31) shift registers, pulse the Clock line (up to) 496 times, reading the serial data line after each clock, and writing each 8 received bits as a byte into an incrementing array pointer. After 496 clocks, the array becomes a reflection of the state of 496 sensors. The cycle is repeated continuously. Power to the devices is provided through a 5V and Gnd pair. So with 5 wires, or 3 data lines, one has access to 496 sensors. I have experimented with a system clocking in over 2000 sensors quite successfully. Being a (continuously) polled system, the chance of "missing" a sensor event is greatly reduced.

    Some negatives of the system include:-
    1. The design requires each device to be serially connected to the next - a single daisy chain. Recent innovations offer 3 parallel chains which can clock in 3 streams at the same time.
    2. Electrical Noise. I believe this can be reduced with better termination and drive line capacities, but remains a known quirk:-(
    Positives:-
    1. It's a continuously polled system. The array within the Base Station is likely to be a very accurate reflection of the state of all sensors.
    2. The resources needed. Very few pins. For three "Sensor Chains", one would need Clock, Load, and 3 Data inputs 5 in total plus power.
    3. The sensor devices are easy to construct. A single Pic does the job.

    Again, thanks for the work you've done. I wish I could get my hands on those ESP32 puppies to try it all out. Alas, methinks it'll only be in the new year:-(

    Best,
    Norm
     
    Scott Eric Catalano and esfeld like this.
  7. Atani

    Atani TrainBoard Member

    1,460
    1,697
    36
    This sounds quite interesting and in theory could be done with the base station easily I think. I don't have an S88 device to test with but I can use an Arduino as an S88 sensor of sorts, I found a few pages that had examples for this.

    I have put this in the backlog here: https://github.com/atanisoft/DCCppESP32/issues/2. I don't have a timeline for it yet but will see what I can come up with. It would be good to support less than the 496 sensor inputs if possible as well.
     
    Scott Eric Catalano likes this.
  8. esfeld

    esfeld TrainBoard Member

    442
    382
    17
    Mike
    My Arduino IDE is all set up for ESP 32 as I have done several other projects .... where in DCCpp-Master is the code? My problems with Platformio go way back to working with Steve Lowrey on his throttles if you'd like to discuss I am at esfeld@cyberdude.com. Thanks
     
    Scott Eric Catalano likes this.
  9. Atani

    Atani TrainBoard Member

    1,460
    1,697
    36
    The code is in the "src" directory (here: https://github.com/atanisoft/DCCppESP32/tree/master/src). You will need to generate the index_html.h file though, it is based on the data/index.html file gzip compressed and passed through bin2c (in PlatformIO IDE this is a custom build step implemented here: https://github.com/atanisoft/DCCppESP32/blob/master/build_index_header.py). If you have a problem generating this file I can email a copy of it to you.
     
    Scott Eric Catalano and esfeld like this.
  10. NormHal

    NormHal TrainBoard Member

    138
    126
    12
    Hi Steve, we chat again:)
    As a result of Mike's work on the ESP8266, and now the '32 I got interested in PlatformIO. I firstly installed it on my Windows 10 system. A disaster. I ended up have to reinstall everything after doing a "System Refresh". This was because everything got stuck in treacle - waiting 5 minutes for PlatformIO to start is no joke:-( After the "Refresh" and laboriously installing all my other apps, and then again installing Atom and then PlatformIO, I still got "strange things" happening - slow performance, dependency issues, and couldn't compile.

    I got so frustrated that I resorted to installing a clean version of uBuntu Linux 16.04 on a new hard disk, and hey presto! PlatformIO (after Atom) works like a treat. Fast, sorts out all the dependencies and quite frankly is superb! I then tried to install VirtualBox on my Windows system, with uBuntu 16.04 as a guest. Atom and the associated PlatfomIO also works great - fast and trouble free.

    IMHO therefore, if you're committed to Windows 10, PlatformIO seems shaky. If you're open to switching to Linux (uBuntu Mate is my preference), PlatformIO is the way to go...

    In a nutshell, I'm sold on Linux and PlatformIO, and sold off Windows 10 - again.
    I'd be interested to hear what you are using Mike? Linux or Windows?

    Best,
    Norm
     
    Scott Eric Catalano and esfeld like this.
  11. NormHal

    NormHal TrainBoard Member

    138
    126
    12
    Hi Mike, I haven't posted any "bug reports' to Github before, so please bear with me. The "bugs" are trivial - you had implemented the OLED display in addition to the LCD option in your previous ESP8266 code. A few instances using "INFO_SCREEN_LCD" were not updated, so choosing the LCD option resulted in some errors. I'll do my best to post the "bug" report:)
    Best,
    Norm
     
    Scott Eric Catalano and Atani like this.
  12. Atani

    Atani TrainBoard Member

    1,460
    1,697
    36
    No worries :) Having a bug report here is a great start and with the details below I could reproduce it easily.

    You are right! I hooked up an LCD to my ESP32 and encountered the same. I will push an update soon. There are a few other updates that should be done for two line LCDs as well. Mainly disable the websocket client count as it is not possible to display it on the LCD at the same time as the IP address. Similarly I had planned to display motor shield status on the last line of the OLED screen but that won't work on the two line LCDs either.

    I need to find a four line LCD and then I can adjust for that support as well. For the two line LCDs the second line could rotate through as: IP, WebSocket, Motor Shield. But that will require some additional code (no ETA yet)
     
    Scott Eric Catalano and esfeld like this.
  13. NormHal

    NormHal TrainBoard Member

    138
    126
    12
    Whew Mike, you responded too fast... Now I still don't know how to post a bug report:-( Let me hunt some more:)
     
    Scott Eric Catalano and Atani like this.
  14. Atani

    Atani TrainBoard Member

    1,460
    1,697
    36
    Scott Eric Catalano likes this.
  15. NormHal

    NormHal TrainBoard Member

    138
    126
    12
    Just BTW Mike, the simplicity of the I2C connected LCD displays IMHO warrants a preferred default - 4 Rows and 20 columns. The more available space to display stuff the better. Choose less, you get less:) There's very little price difference between a 16x2 and a 20x4 display these days...

    Best,
    Norm
     
    Scott Eric Catalano likes this.
  16. Atani

    Atani TrainBoard Member

    1,460
    1,697
    36
    Very true! I have a 20x4 on order and should have it in a couple weeks. In the meantime I will be working with my existing 16x2 LCDs and come up with a rotation scheme for it.
     
    Scott Eric Catalano likes this.
  17. NormHal

    NormHal TrainBoard Member

    138
    126
    12
    Hi again Mike,

    I thought I'd give getting your code to compile with Arduino IDE a bash... I managed to get (I hope) all the required libraries set up and then came up against the Index.html step you mentioned to Steve. I did the following...
    - 7zipped index.html to index.html.gz
    - bin2c'ed index.html.gz to index_html.h
    - placed it in the DCCppESP32 sketch folder
    - recompiled

    Error from the compilation :-

    Arduino: 1.8.5 (Windows 10), Board: "ESP32 Dev Module, QIO, 80MHz, 4MB (32Mb), 921600, None"
    sketch\WebServer.cpp: In lambda function:
    WebServer.cpp:39: error: 'indexHtmlGz' was not declared in this scope
    AsyncWebServerResponse *response = request->beginResponse_P(200, "text/html", indexHtmlGz, indexHtmlGz_size);
    ^
    WebServer.cpp:39: error: 'indexHtmlGz_size' was not declared in this scope
    AsyncWebServerResponse *response = request->beginResponse_P(200, "text/html", indexHtmlGz, indexHtmlGz_size);
    ^
    'indexHtmlGz' was not declared in this scope
    This report would have more information with
    "Show verbose output during compilation"
    option enabled in File -> Preferences.

    Basically, I confess I'm working in automation mode - not really knowing what I'm doing, so forgive me if there's something totally obvious...

    Any thoughts?:)
    Norm
     
  18. Atani

    Atani TrainBoard Member

    1,460
    1,697
    36
    Open index_html.h and make sure the declaration of the size and hex array are as follows:
    Code:
    const size_t indexHtmlGz_size = 6847;
    const uint8_t indexHtmlGz[] PROGMEM = {
    ...
    };
    Using bin2c will generate a name based on the input parameters so it may not be generating the correct variable names. Also note the inclusion of "PROGMEM" before the =.
     
  19. NormHal

    NormHal TrainBoard Member

    138
    126
    12
    Somethings not quite right:-(
    here are the first few lines of index_html.h...

    /* Generated by bin2c, do not edit manually */
    /* Contents of file index.html.gz */
    const long int index_html_gz_size = 6783;
    const unsigned char index_html_gz[6783] = {
    0x1F, 0x8B, 0x08, 0x08, 0x14, 0xA9, 0x2D, 0x5A, 0x04, 0x00, 0x69, 0x6E, 0x64, 0x65, 0x78, 0x2E,
    0x68, 0x74, 0x6D, 0x6C, 0x00, 0xED, 0x1D, 0x69, 0x73, 0xDB, 0x44, 0xF4, 0x73, 0xF3, 0x2B, 0x84, ......

    Norm
     
  20. Atani

    Atani TrainBoard Member

    1,460
    1,697
    36
    Change these two lines to be:
    Code:
    const long int indexHtmlGz_size = 6783;
    const unsigned char indexHtmlGZ[6783] PROGMEM = {
    Ignore their comment about not editing manually, you will need to in this case.
     

Share This Page