DCC++ESP32 Base Station

Atani Dec 10, 2017

Tags:
  1. ghruei

    ghruei New Member

    4
    0
    1
    Greetings,

    I initial setup a working dcc++ system using anarduino, but looking to switch to using an ESP32. So read through this thread and have setup up a dev ESP32 board with a deek-robot motorsheild currently on a breadboard. Compiled and uploaded the code with the motorshield set as ARDUINO_SHIELD and using the default pins in the config file.

    I then have it connected as follows:

    ESP to Motorshield
    PIN18 to DIRB
    PIN19 to DIRA
    PIN23 to PWMB
    PIN25 to PWMA
    PIN VP to A0
    PIN VN to A1
    gnd to gnd

    My problem is that while I can connect to the ESP32(Web interface and JRMI) and switch the power on and off to the motorshield I cannot get any throttle to work. (Just to note the leds for b channel never come on)

    Am I missing any extra jumpers on the motorshield? or is there something else I can check on the ESP as it appears to be functioning correctly.
    I have cut the VIN and the brakes.

    Any help appreciated as I cannot see what I have done wrong.

    Thanks
    Richard
     
  2. Atani

    Atani TrainBoard Member

    724
    551
    15
    It sounds like you don't have power going to the board, you will need to connect the 5V pin from the ESP32 to the shield, otherwise the connections sound correct.
     
  3. ghruei

    ghruei New Member

    4
    0
    1
    Thanks for the reply. I had actually only had the 3.3v from the ESP to the VIN. I have replaced this with the ESP VIN to the VIN of the motorshield.
    I now still have nothing happening on the main output but on the prog the loco starts running at a constant speed then the motorshield powers down possible due to pulling to much current on the prog track. Which means at least that works I suppose, though I do not know why the motor runs as it should not on the prog track and it does not detect the decoder.

    I have replaced the motor shield with another one and no difference. So I think next step is to check both motorshields back with arduino setup to ensure I have not damaged them somehow.
     
  4. Atani

    Atani TrainBoard Member

    724
    551
    15
    VIN is not correct and is likely why you are seeing issues. You will need to connect the 5V pin to the 5V pin on the shield. Without that the shield will not have power for the h bridge. If you power it with too high of voltage, which the VIN pin on the esp32 could provide, it will potentially destroy the h bridge.

    Sent from my ONEPLUS A5010 using Tapatalk
     
  5. ghruei

    ghruei New Member

    4
    0
    1
    Yep looks like I have successfully destroyed all the motorshields. I have tested them on my old arduino setup and while the loco can be detected and lights etc work, as soon as I try and power the motor it just starts running and then the arduino becomes unresponsive and the motor just keeps running. So I am going to order a couple more and try again.
     
  6. ghruei

    ghruei New Member

    4
    0
    1
    OK, back again. Still cannot get this to function. After blowing up a motorboard,esp32 and a decoder I know have a working motorboard,esp32 dev board and a working decoder. The motor board and decoder functions correctly with the old arduino setup.
    So setup everything again. Still nothing only can partly switch on the motor board (1 LED lights up for prog or main) and the loco motor just runs at full power. So I have changed the pins around and still the same result.

    Anybody with ideas how to test to see what is going. I am sure it is the ESP board not generating the output correctly but cannot see why.I am sure the motor board is connected correctly now.
     
  7. Atani

    Atani TrainBoard Member

    724
    551
    15
    If you only see one light then something is not setup right and that would explain the behavior on the track. So lets take a step back and go through the connections and make sure everything is 100% right before connecting it to the track.

    1) What pins are you connecting exactly between the esp32 and the motor shield?
    2) What do you have defined in Config_MotorBoard.h?

    The expected behavior is when you power everything up the motor shield should not have the track lights ON (unless you have enabled power-on at startup via Config settings). When you turn on track power you should see MAIN (A) lights come ON, PROG (B) should remain OFF. If you see otherwise then you likely have a pin configuration issue.
     
  8. Lormedy

    Lormedy New Member

    7
    1
    1
    Hi Mike, Hi NormHal,

    I read all posts, bought an ESP-VROOM-32 DEVKIT from DOIT, and download your last soft v1.2.3. Great job !
    But I found a bug when #include "Config_S88.h" was set in Config.h
    Here is the end of my boot log:

    [ConfigurationManager.cpp:127] load(): Loading /DCCppESP32/outputs.json
    [ConfigurationManager.cpp:127] load(): Loading /DCCppESP32/turnouts.json
    [ConfigurationManager.cpp:127] load(): Loading /DCCppESP32/sensors.json
    [ConfigurationManager.cpp:127] load(): Loading /DCCppESP32/roster.json

    Boot sequence get locked here and the 2 following lines are never displayed, neither s88.json.

    [ConfigurationManager.cpp:127] load(): Loading /DCCppESP32/consists.json
    [DCCppESP32.cpp:392] setup(): DCC++ESP32 READY!

    The issue is located in line 78 of S88Sensors.cpp:
    xTaskCreate(s88SensorTask, "S88SensorManager", DEFAULT_THREAD_STACKSIZE, NULL, DEFAULT_THREAD_PRIO, &_taskHandle);
    When I commented this line the boot sequence ends up normally.

    Next, I suggest to add in this file:
    log_i("Configuring S88 bus [S88_CLOCK_PIN: %d, S88_RESET_PIN: %d, S88_LOAD_PIN: %d, S88_DATA_PIN: TBD]",
    S88_CLOCK_PIN, S88_RESET_PIN, S88_LOAD_PIN);

    It is nice to display where pins are connected as a double check while debugging.

    Should I suggest you to take a look on my design to catch some ideas to improve your HTML display. F0-28 buttons take too much space and the tracks power status should also be on the main page to keep a fast control on any derailment. With Chrome, activate the translator and see http://lormedy.free.fr/CDT20.html
    Download the zip file and play with the buttons of my HTML panel to see how I drive trains with Arduino and DCCpp. The design is not perfect but you may find some ideas for your own display.

    Sometimes DCC orders are delayed between 5 to 9 seconds after moving the speed cursor on the screen (heap > 200000 on LCD). Works fine after reboot.
     
  9. Atani

    Atani TrainBoard Member

    724
    551
    15
    The problem with commenting this out is that the S88 bus is not actively being monitored since the task is not running.

    I'll take a look at this further though since there are a few performance issues which need to be addressed.

    I agree this should be there and I'll adjust the code to include displaying this and split off the data pin to when the bus is actually created.

    Very likely there is a task that is monopolizing the cpu cycles which is causing the issue you are seeing. I'm shifting focus for v1.2.5 (formerly v1.3.0) from LCC to performance issues as there are a few of them to be fixed in the current code. I'm hoping to have this version out soon.

    The UI looks good and I agree on some of the points in your feedback. However, track power on the main page is not really necessary as the CS has the option to enable track power on startup via config and this will become the default in the near future. The CS will also disable track power automatically when it detects a short on the track.

    The only problem I see with your UI proposal is the dependency on Node.js, this is unfortunately not supportable on the esp32 as a self-contained (mostly) service. I'm also looking at a few options to further self-contain the web interface so that the esp32 is able to serve up the dependencies of the html code (jquerymobile, etc) as part of a shift towards dynamic reconfiguration of the CS without recompilation (ie: starting a soft ap when no ssid is configured or it is unavailable, as well as changing the ssid at runtime)
     
    Lormedy likes this.
  10. Lormedy

    Lormedy New Member

    7
    1
    1
    As soon as line 78 is back in the code, it looks like data or code overlapping that leads to crash. Common variable names or bad data size must be investigated. I reduced the S88 bus size downto 16 bits instead of 512 but the issue was the same.

    This S88 bus also uses 4 pins and that's a lot. I have the idea to re-use the same 4 pins for a SPI bus to read a SD card. S88_RESET and SPI_SS can share the same pin without any conflict because S88_RESET is not active when the clock toggles. A 1k resistor in series in the S88_DATA path should avoid any conflict with the SD card reader. S88 bus is an asynchronous bus that can accept small delays while reading a SD card, time to select another loco. Adding a SD card will allow to run your software without any Internet connexion.

    My design will use 5 districts: 5 enable and 5 current monitoring. Your code was easy to expand to display 5 districts because your soft is well written. Thank you.

    I understand Node.js is a difficult step for beginner and I plan to modify it, maybe using Ajax. I like your self-contain software and ESP32 is the future after Arduino. Bluetooth LE should be developed as well.

    About ghruei issue : this happens when you try to drive a loco first without acquiring a loco. It looks like a DCC broacast sent with default address zero and maximun speed. All locos start running, out of control. As a result, I will use the sixth ADC input to add a big emergency stop button beside my trains. Many more buttons can be connected in parallel if you have a big railway network.
     
  11. Atani

    Atani TrainBoard Member

    724
    551
    15
    It is not variable names or data size that is causing this issue. The issue is there is a task monopolizing the cpu cycles of the esp32 which is preventing the startup to complete. I'll be investigating this further this week.

    It is not a good idea to reuse the pins for multiple purposes. The S88 bus will react negatively if the RESET pin is triggered at the incorrect time.

    I'm glad that you are able to do this with the code as written, I'd only suggest being very careful on the pin selection for current sense as any pin below 30 will not work for current sense.

    Node.js is not overly difficult but it has far too many dependencies to run natively on the esp32 while also running the CS code. The current html code leverages AJAX to dynamically pull data from the CS, there are a few issues in this approach today which I'm actively working on improving (mainly performance issues).

    I'd generally agree but in this case the description of the issue does not align with that assertion. The lights on the motor shield should both be ON if "MAIN" is ON and "PROG" should only be ON when it is actively in use. There is no situation where only one LED for each will be ON.
     
  12. Atani

    Atani TrainBoard Member

    724
    551
    15
    After this line, add this:
    Code:
    vTaskDelay(pdMS_TO_TICKS(50));
    
    When the S88 task is running on core 1 it will block the loopTask from executing as it doesn't yield to the scheduler.
     
    Lormedy likes this.
  13. Lormedy

    Lormedy New Member

    7
    1
    1
    After this line, add this:
    Code:
    vTaskDelay(pdMS_TO_TICKS(50));

    Sorry but nothing changes. The console displays :
    [ConfigurationManager.cpp:127] load(): Loading /DCCppESP32/outputs.json
    [ConfigurationManager.cpp:127] load(): Loading /DCCppESP32/turnouts.json
    [ConfigurationManager.cpp:127] load(): Loading /DCCppESP32/sensors.json
    [ConfigurationManager.cpp:127] load(): Loading /DCCppESP32/s88.json
    [ConfigurationManager.cpp:127] load(): Loading /DCCppESP32/roster.json
    And nothing else. I change the delay up to 1000 without success.
    2 CPU is nice but this adds a scheduler with new difficulties.
     
  14. Atani

    Atani TrainBoard Member

    724
    551
    15
    Ok, this was the only difference between S88 and normal Sensors, I'll do some more digging.
     
  15. Atani

    Atani TrainBoard Member

    724
    551
    15
    After testing this further (with the added vTaskDelay for s88), everything looks normal. The console is generally pretty quiet during normal operations with only a few lines printed normally.

    I'll be pushing an update to the development branch shortly that adjusts the logging a bit further since there are a few known issues with usage of log_i etc and there is a better alternative now available (from LCC).
     
  16. Lormedy

    Lormedy New Member

    7
    1
    1
    After doing your software modifications except the WiFi, ESP32 boot was perfect. Now I can see a S88 section on the screen where I set up the S88 16-input of my new home made PCB I must check out. You can see the design on my website. Data bits are at the right place on screen. Excellent job! All signals are perfect with a clock duty cycle of 50µs high and 25 µs low. Nonetheless I see 18 clock pulses for 16 data and the 2 last pulses are useless but!
    At start of the sequence, Clock rises high for 50µs then low for 180µs, Reset rises high for 50µs then low up to the next sequence and Load rises high for 256µs then low up to the next sequence. 25µs before Load falls low, Clock rises for 50µs thus up to 25µs after Load goes low, that's correct. But watching on a oscilloscope the first data is set high by the first Clock rise and fall to low with the second Clock rise that set the second data to high (if any) and so on...
    Conclusion: the first and the last Clock pulses are useless because Reset is high-level active and doesn't need any Clock rise.
    If you write a number of data bits greater than the number of bits allowed by the S88 bus, ESP32 reboot! Please make a test.
    About the display of 512 bits, it is difficult to identify where is the 459th bit on the screen. A space each 16 bits and a different background color each 4 or 8 bits would be welcome to identify a bit among others. Soft bless my eyes.
    Sensor ID Base display 1024, second S88 bus start at 1536, is it ok ? The third S88 bus is never displayed.
    Can you place S88 bus information on the third LCD line where is written "TRACK POWER ON/OFF", O or 1 would be sufficiant freeing 18 char on the LCD. Usefull when debugging.
    I made an ajustment on LCD display as only 20 characters are available and I display mA that I found more readable and supress parenthesis. A multiplier constant in config.h would be useful to ajust the current value according to our different current sensors.
    Clock parameter is 24 but the footer always displays 12 am/pm.
    I am waiting the next release because you already made too much modifications. Sofware seems more stable now, good news.
     
  17. Atani

    Atani TrainBoard Member

    724
    551
    15
    I'll setup a scope on this and see what I can come up with. This area has had some testing but it can always use more.

    I'll need to setup something to simulate this. We did test it previously and it was working so maybe it got broken.

    I'm in agreement here! In an older version of the html code it would render it as ON/OFF in groups of 16 (or 32?). I've got this on my TODO list to reintroduce, I'll try and have it in for v1.2.5 (next release).

    Yes, this is expected since it allocated up to 512 sensor indexes for the first bus. Currently the max sensors is not configurable but it could be.

    What S88 info would you be interested in having? It can be added to the InfoScreen code but I'd need to know a bit of what to display.

    The mA value is calculated at runtime based on the last analog read value scaled out to the max mA for the device divided by the max value for analog reads (4096). Very likely the max mA value for the setup you are using is not quite right for the calculations, what device(s) are you using?

    That sounds like a bug, I'll see if I can reproduce it.

    After v1.2.5 goes out there will be a few more changes as the LCC functionality expands, the biggest planned change will be a rework of the stored configuration from monolithic json files to split up so that updates are scoped a bit more narrowly. This will be critical in the LCC side when the traction spec is implemented (persistent loco state!). Aside from that piece the next area to be worked on will be WiFi stability, the arduino-esp32 WiFi library has a few issues which I've not found any workarounds for (yet) but I can work around them in the ESP-IDF code. Similarly the EspAsyncWebServer code can crash leaving the web interface dead without crashing the esp32.

    The biggest change in v1.2.5 is actually on the DCC side, the signal generation is moving from a hardware time to the RMT peripheral instead. This should yield a higher quality signal without a few of the drawbacks the hardware timer imposes.
     
    Lormedy likes this.
  18. Lormedy

    Lormedy New Member

    7
    1
    1
    try this :
    $('#clock').clock({"timeFormat":"\\ H:i:s"});
     
    Atani likes this.
  19. Atani

    Atani TrainBoard Member

    724
    551
    15
    Just tested with this and it seems to fix it. It is interesting that the format option was not working since that is shown in the guide as a supported option.
     
  20. Lormedy

    Lormedy New Member

    7
    1
    1
    S88 bus is working fine but timing could be improved. See my recorded diagram.

    At boot LCD display on the 4th lines is so fast that I can't read but I saw a S88 info flashing. What about displaying the 16 first bits read on the bus as 16 zero and one to help debugging a new module. If I write it on my side I must modify the file at each new release but I already made several modifications registred in a separate growing file.
    S88 bus is read permanently but on the screen we need to refresh the information to see the last values. An automatic refresh each second would be welcome but no more than 10 times per second if monitored by a Train Controller software. 1 second ==> 1 foot at 60mph (scale 1/87).

    I use a MAX 471 and calibration shows a multiplication by 8. Its output is 1V == 1A. I must add the multiplier constant in MotorBoard.h but it should be set in config.h . I added some 1k resistors in serie with most of the ESP32 pins to prevent damage with others elctronics powered with +5V.
     

Share This Page