Updated DCC++ Code and ESP8266 Wifi Code

DaveT58 Apr 28, 2019

  1. DaveT58

    DaveT58 TrainBoard Member

    18
    2
    2
    Hi All

    I have been working for a while on an update to Greggs Arduino code for DCC++, the main things I have looked at is:

    1. On the Arduino Mega, to be able to use any of the four serial ports (Serial/Serial1/Serial2/Serial3) for communication to JMRI (or similar program). I have used a USB/RS232 converter, a WEMOS Arduino MEGA with onboard ESP8266 and a WEMOS ESP8266 Pro Mini WIFI board and all these work ok. The ESP8266 Pro mini has an issue where it just stops communicating and you cannot even ping the board.
    2. For the UNO and Mega there is a third option to select a motor driver PWM board, I'm using the 43A PWM board IBT-2
    3. A few other tidy ups in the code.

    I have had this on test for a few days and no issues at all with JMRI in Ethernet configuration with the ESP8266 connecting to the Arduino.

    The other file attached is the Arduino ISP code for the ESP8266 to sit between the Arduino and the JMRI, just need to configure the SSID, Password, IP address, router etc and its good to go. To test the config you have to uncomment the print.serial lines of code in the Setup() then you can see the ESP8266 connecting to the WiFi network to make sure it works by using the Arduino monitor. Then best to recomment the lines so not to throw garbage data to the Arduino.

    To program the ESP8266 in the Arduino ISP you have to load the ESP board definitions into the Arduino ISP configuration, plenty of info on the www for that process. You will also need to download the "ESP8266" WiFi library for the ESP8266 compiling as well.

    Sorry its not in GIT, still trying to get my head around that one.

    Any comments are gratefully received and I hope this is of some use to others out there.

    Kind regards

    DaveT
    Kuala LUmpur
     

    Attached Files:

    EFA Train Guy likes this.
  2. AndyH

    AndyH TrainBoard Member

    77
    9
    6
    Marvelous. I presume that you upload the main programme to the Arduino, and then the secondary ESP8266 to the ESP board? How are you connecting the ESP to the Arduino? I have an ESP01 board, and am using a motor shield. Thanks.
     
  3. EFA Train Guy

    EFA Train Guy TrainBoard Member

    12
    0
    4
    Dave,

    I have a WEMOS Arduino MEGA with onboard ESP8266.

    I have not played with it but if you have already used, can you send me detailed instructions on programming both the ESP and the Arduino with switches.

    Do I need to use Python?

    Thanks,


    Erich
    Chicagoland
     
  4. EFA Train Guy

    EFA Train Guy TrainBoard Member

    12
    0
    4

    Dave,
    I have a WEMOS Arduino MEGA with onboard ESP8266.

    I have not played with it but if you have already used, can you send me detailed instructions on programming both the ESP and the Arduino with switches.

    Do I need to use Python?

    Thanks,


    Erich
    Chicagoland
     
  5. Jack Regan

    Jack Regan TrainBoard Member

    22
    12
    2
    Dave, thanks for getting this done. Trying to put it to work and ran into an issue I have never seen before. I uploaded the ESP8266 sketch and connect to the network. That's fantastic. But trying to upload the Mega sketch I get an error I have not encountered before. Double checked everything and only dip switches 3 and 4 are on. The error is
    avrdude: verification error, first mismatch at byte 0x0d6c
    0xa8 != 0xe8
    Comes at the end of uploading. Would you have a suggestion?
    Thanks
     
    EFA Train Guy likes this.
  6. EFA Train Guy

    EFA Train Guy TrainBoard Member

    12
    0
    4

    Dave,

    I have the wemos mega with 8266 and have been working at figuring out how to use the esp to connect to engine driver on my android

    I thought your updates might be the answer but i do not think you have it set up to be a web server?

    I found ESP_DCC_controller-master which looks like it is a web server?

    If it is can i add it to your dccpp and do you think that might work?

    Regards,

    Erich
     
  7. KC Smith

    KC Smith TrainBoard Member

    109
    111
    12

    Jack,

    I'm in the process of trying a Wemos Mega Wifi & ESP8266 with DCC++EX 2.1.1 and Dave's ESP8266+DCC sketch.

    I loaded the DCC++EX Mega with the new Base Installer 2.0 with no problem, dips set 1,2,3,4 on & the rest off.

    I haven't been successful as yet loading Dave's ESP8266 with dips set 5, 6, 7 on.
    I need to find and load the ESP8266WiFi library.

    Which ESP8266WiFi Libray did you end up using?

    regards
    K
     
    Last edited: Jun 18, 2020
  8. FlightRisk

    FlightRisk TrainBoard Member

    548
    237
    14
    Hi Dave,

    It looks like you started with Gregg's old sketch. We have had sketches for both the Arduino and the ESP8266 for a couple of years now. Did you look at that code first? Merging this in would have to be manual since we now have a commManager to handle multiple inputs and outputs. You will see commInterfaceSerial, commInterfaceESP, commInterfaceEthernet, etc. These then register to the commManager.

    We also have a ESP8266 sketch written by Atani that we were modifying to be more generic. There would be an API so that the ESP8266 would just handle networking and DCC++EX would talk to it via the same <iDCC...> API we have now. The code for train control and the code for networking shouldn't be mixed. This isn't difficult to do, and I would still like this as an option for people, but we are moving in a different direction. No flashing ESP boards. Also no jumpers, no using an IDE to have to learn and upload code with (except people who want to).

    Keeping in mind our users and the users we would like to have onboard, every step in complexity is a non-starter for them. Remember that a large majority use or will use just an Uno and are not programmers. That said, we can try to move people to the Mega. There will be features (like multiple com ports and more IO pins and price) that hopefully will get more and more people onto a Mega. Still, we feel that it is difficult enough for a non techie having to upload a sketch to a hardware board. Adding a different sketch that has to be loaded onto another board got voted down. So the plan is to use the existing AT command setup that already comes flashed in the chip. JMRI uses Websockets and so can we. And that is what we are writing now. In the meantime, could you look here and compare it to your code and see what input you could give us as to how to incorporate what you are doing with where DCC++ EX is today?

    Here is the main repository menu:

    https://github.com/DCC-EX

    You will see Gregg's version under BaseStation-Classic. Our current version is under BaseStation-EX. That is the version that has the DCCpp_ESP sketch and all the changes from the last few years in the DCCpp_EX folder. The folder names and some file names are different based on Gregg's original intent and to make the repository compatible with both PlatformIO (our development environment) and the Arduino IDE. The new version we are working on is a library called CommandStation. The operating code for the CS is in CommandStation-DCC. Soon that will just merge into BaseStation-EX (or maybe CommandStationEX) as the next release.

    And we can help you with Git and GitHub! We are writing up a "contributing" doc that will have how to use Git and what our coding standards are.

    Also, the developers congregate on this Discord and have non-stop chats about our development efforts all day long. It is the best place to contribute and to share information about DCC++EX:

    https://discord.gg/y2sB4Fp

    Please join us!
     
    EFA Train Guy likes this.
  9. FlightRisk

    FlightRisk TrainBoard Member

    548
    237
    14
    Hi again Dave. I went through your code. We had the ESP8266 support and multiple motor board support. We can use serial1 on the Mega for wifi over serial (look at our config.h). It looks like we just need to go over everything you did and see what other tweaks you made and see what we can pull in.

    You have an option to select any port for the Mega to be used for the serial connection. We assume in our setup serial for the USB connection and serial1 if you set wifi_over_serial. We can configure that to allow both to be configurable instead of just the network serial1.

    We support the IBT_2 (options 2 and 3 in config.h) but should see if anything else in your implementation is different for that motorboard and if your implementation of the ESP8266 is different that the one in DCC++EX. I hope to work with you. I can introduce you to the team if you want to join our Discord. Thanks for your work and for posting!
     

Share This Page