Arduino mega + wifi (wemos) and CommandStation-EX

roby02091987 Jan 6, 2021

  1. roby02091987

    roby02091987 TrainBoard Member

    Hi Guys,
    I already use CommandStation-EX with an arduino Mega connected (USB) with a raspberry pi 4 with jmri... but...
    I've got around this particular board, that is in fact and arduino mega with an integrated ESP8266 chip. I've always used it as a "pure" arduino mega, but i'd like to take a step further. I'd like to use it as a stand-alone dcc++ command station, that connects directly to engine driver via wifi, without a pc/raspberry inbetween.

    I've tried many solutions, but now i'm stuck ad this point:
    On the arduino mega i've installed the latest version of CommandStation-EX, that works flawlessly (connected to a pc/raspberrypi via usb).
    For the esp 8266... i don't know what to do. I've tried to write some sketches, i've tried to use some sketches that i've found here, but without results. I can't get the arduino mega to "talk" with the esp8266 chip.
    Can someone help me?

    Thanks in advance
  2. esfeld

    esfeld TrainBoard Member

    I have just recently succeeded in doing just that ..... i takes a bit of fiddling but can be done. Flashing the proper firmware SDK to the ESP is the hardest part. Start here: and familiarize yourself with the process. I have heard that the chip on the boards differ widely ... after much experimenting I found that ESP8266 SDK v 1.7.4 worked successfully for my boards. I also used DCC-EX to configure the Mega portion to enable WiFi through my router giving access to Engine Driver.
  3. roby02091987

    roby02091987 TrainBoard Member

    Thanks a lot for the answer! So it is possible!
    I've flashed the firmware form that link, and i got it to work, i can now access the esp8266 configuration via the web address I've also enabled the SLIP protocol for the communication through the serial port (serial 3).
    But... how did you do to make DCC-EX and ESP8266 to talk together? I'd use ESP8266 as an AP.
    Many thanks
  4. esfeld

    esfeld TrainBoard Member

    I was not able to configure DCC_EX in AP mode .. as DCCEX ( or the IP) never showed up in ED discovered servers. I configured DCC_EX config.h using my routers SSID and pwd which I believe puts it in station mode ... then, using ED to connect to the IP and port of the MEGA+WiFi R3 ATmega2560+ESP8266 .. I had a successful connection. I also had to jump SCL21->RX and SDA20->TX. Good luck
    IGNORE the attached file .. it jumped in from my clipboard :)

    Attached Files:

    Last edited: Jan 7, 2021
  5. roby02091987

    roby02091987 TrainBoard Member

    I've tried everything, but i get always this error from the serial monitor:
    ++ Wifi Setup NO AT ++
    I think that my arduino can't find the esp8266 chip... I've tried a lot of combinations:
    Esp8266 on serial0 or serial3
    various dip-switch combinations (BTW, which one do you use?)
    AP mode or STA mode or AP+STA mode
    But with zero results.
    Have you uploaded a particular sketch to the esp8266?
  6. esfeld

    esfeld TrainBoard Member

    I flashed ESP8266_NONOS_AT_Bin_v1.7.4 to the ESP section of the board (dip switch 1,2,3,4 off .. 5,6,7 on [8 stays off for everything]) and then in Arduino IDE uploaded DCC-EX (dip switch1,2,5,6,7 off .. 3,4 on) . Turn off power to board .. dip switch 1,2,3,4 on .. 5,6,7 off power on and check serial monitor. The boards are very finicky I think I must have done 50 iterations until I got it to work. I have another board that I am still trying to get to work using the same everything that worked on the first board to no avail ... I don't think it's a bad board 'cause I have successfully uploaded a WiFi scanner which should mean that the ESP chip is good .. but I can't seem to get it to work like the other board. Frustrating, I know but keep at it,
    David Clemson likes this.
  7. esfeld

    esfeld TrainBoard Member

    Roby, Have you had any luck?
  8. roby02091987

    roby02091987 TrainBoard Member

    No, i've tried many times, but without luck :(
  9. KC Smith

    KC Smith TrainBoard Member


    with ATMega2560+ESP8266 WiFI combo board with DCC++EX 3.0.0 Standalone WiFi Command Station.

    My Current Config:
    DCC++EX 3.0.0
    config.h set with my local routers SSID / PW - it returned / 2560
    Clone ATmega2560+ESP8266WiFi Combo Board
    Deek L298P Motor shield
    16.5vdc laptop power supply to the Motor shield, with 14.5vac to the tracks for HO gauge
    9vdc power supply to the ATmega boards female power barrel.
    Android Smartphone w Engine Driver v2.26.115

    After working with Steve(esfeld) and Fred Decker(FlightRisk) on the ATmega2560 + ESP8266 WiFi combined board,
    I used this site with great success.

    Multiple Easy Steps;
    1) Download the ESP Files,
    2) Flash the ESP8266 chip,
    3) Edit & Load the DCC++EX 3.0 to the Mega2560 chip,
    4) Set up Engine Driver Throttle

    1) downloaded the Flash Download Tool 3.8.5 nodencu-flasher
    & download the ESP8266_NONOS_AT_Bin_v1.7.4 Bin files found here

    2) To Flash with ESP8266_NONOS_AT_Bin_v1.7.4 set the ESP section of the board with the USB unplugged. (no power)
    (set dip switches 1,2,3,4,8 off .. 5,6,7 on)
    (set TX/RX dip switch to RXD3 & TXD3)
    Plugged in Mega+WiFI board to comm port X, pressed Mode button,

    Run the 3.8.5 Flasher Tool {give it time to completely open}
    press [Developer Mode] button
    press [ESP8266 Download Tool] button

    Set up file location in the Tool version 3.8.5
    Pay close attention setting up the Exact *.bin Files & locations 0x......
    And then set the Exact radial dial & baud rate settings;
    (26M, 40MHz, DIO, 16Mbit-C1, com: xx, 460800 baud).

    First press the Erase button and let the ESP erase the chip memory
    Then press the Start button and the bin files will flash load onto the ESP chip

    After flashing, the ESP8266 Log will show it uploaded them all successfully and it closes the port.
    You Disconnect the USB cable.

    3) Set up the Arduino ATmega2560 side of the board with DCC++EX 3.0.+
    (dip switches 1,2,5,6,7,8 off .. 3,4 on)
    (Leave the TX/RX dips on RXD3 TXD3)
    re-connected the USB cable

    In the DCC++EX Command Station Folder make a Copy of the sampleconfig.h file and rename it to config.h
    Open the DCC++EX 3.0 in the Arduino IDE Interactive Development Editor then;
    Edited & change the tab config.h data to your local or home Router's SSID & Password.
    #define WIFI_SSID "......" to your "local SSID"
    #define WIFI_PASSWORD "......" to your "local PW"

    Compile and upload to the
    ATMega2560 board (com: xx, baud 115200),
    Verify your com port and baud rate in windows device manager

    After the Arduino IDE uploads DCC-EX 3.0 sketch
    Disconnect USB cable
    Reset dip switches 1,2,3,4 on .. 5,6,7,8 off
    (Leave the TX/RX dips on RXD3 TXD3)

    Power up the Arduino ATMega+ESP8266WiFi board by Either a USB cable OR a 7-12vdc power supply to the Arduino lower female power barrel.

    When powered on check the Arduino IDE Tools > Serial Monitor.
    It should show the ATMega2560 & ESP8266 WiFI communicating and assigning a IP Address and Port 2560 to the new DCC++EX Command Station.
    4) Set your Smartphone WiFi to the same local SSID you entered into the DCC++EX config.h file
    Start your Smart Phone Engine Driver App and
    enter the XXX.XXX.X.XXX IP address assigned in the Arduino Serial Monitor above and Port 2560.

    If the Engine driver fails to connect the first time with the Command Station just press the Mega's red Reset button and try the IP / Port connection again.

    You should have a direct Throttle connection to the DCC++EX 3.0 Standalone WiFI Command Station Via your home Router.
    Note : This is an Operations only config, the Engine Driver Power button only powers on the Main track, Not the Prog track.
    Function Keys are only local Default Function Settings, and are Not transferred from the JMRI Server Roster.

    Let me know if this helps.
    Good Luck & have Fun!

    Last edited: Feb 3, 2021
  10. roby02091987

    roby02091987 TrainBoard Member

    That is awesome!!! Thanks a lot, guys!! I'll try it as soon as i've a bit of time.
    KC Smith likes this.
  11. esfeld

    esfeld TrainBoard Member

    Kevin: Excellent and concise write up .... now I'm waiting for the DCC-EX team to add WiFi static IP configuration and add the IP address to the LED/OLED readout. I have been trying to code these myself but have run into numerous library inconsistencies ... but still trying.
    KC Smith likes this.
  12. KC Smith

    KC Smith TrainBoard Member


    Thanks Steve,
    I was inspired by your previous posts on flashing the ESP chip.

    I'm also looking forward to the DCC++EX enhancements particularly the SETUP Command user file.

    I have Five differently configured Arduino DCC++ Command Stations (CS) for Development, Testing & Production all with Engine Driver Throttles
    Uno DCC++ Classic CS
    Uno DCC++EX CS with HT06 Bluetooth (replaces USB cable)
    Mega with MakerFab WiFi DCC++EX Standalone CS
    Mega+ESP WiFi DCC++EX Standalone CS
    Uno DC+ Bunza's DC JMRI/Wifi (a Big Hit with my club's DC Cab only members & with my ATC sketches for DC engines)

    And Various Mega, Uno & Nano boards with DCC & DC Sketches for
    Automated Throttle Control (ATC via TX/RX) for 3 Engines running on a modular layout {Similar to Chris' Train Programmable Language TPL idea}
    Servo points & IR Sensors,
    Sample Signal Head Lighting
    MP3 Player microSD sound board with triggers
    (the above are work in progress and not as yet all fully integrated)

    My long term Hopes would be to develop a Wifi Node Network with ESP8266 chips with fixed Static IP addresses and eliminate a lot of cables & wiring.

    Another thing that would also help is for JMRI Preferences/Connections to have the USB Com# to have a Descriptor after it.
    Com 6 Arduino CS Bluetooth1,
    Com 4 Uno CS,
    Com 5 Mega CMRI,
    Com 7 Nano ATC, etc

    I also have JMRI Decoder Pro with various script 'Push Buttons' set up to handle Multi Engine scripts to run around the layout.{similar to TPL}
    It would be nice to be able to load a script pointer into the Engine Driver Function key and allow some of the above scripts to run by a press of a Wi-Fi throttle function key.

    Now you got me started......

    Thanks again for all your persistence and tinkering with DCC++ over the years, and good luck with the OLED IP display.

    Last edited: Feb 3, 2021
    esfeld and Sumner like this.
  13. roby02091987

    roby02091987 TrainBoard Member

    Success at the first try! Thanks a lot guys, you really helped me! Keep up the good work! :)
    esfeld and KC Smith like this.

Share This Page