Ways to use an ESP8266...

TwinDad Feb 27, 2017

  1. TwinDad

    TwinDad TrainBoard Member

    1,844
    551
    34
    I finally got my ESP8266 boards in the mail... I'm actually a bit confused about all the options folks have come up with, so I thought I'd start a thread to "advertise" and discuss them...

    It seems like there are at least three major possibilities...

    • ESP8266 as "dumb" WiFi/Ethernet "shield" (or module) for an Arduino MEGA with COMM_TYPE=1/2/3
    • ESP8266 as a "smart" WiFi/Ethernet coprocessor for an Arduino UNO with COMM_TYPE=0 (this isn't necessarily all that smart - it's just a WiFi/Serial bridge ... but it offloads all the Ethernet work from the Arduino. That's the "smart" part)
    • ESP8266 as "super-smart" web interface/server thing on steroids... with a serial-attached UNO.
    • ESP8266 as the Base Station itself, with no Arduino involved.
    Did I miss any?
     
    Scott Eric Catalano and KC Smith like this.
  2. Atani

    Atani TrainBoard Member

    1,469
    1,756
    37
    I am not sure this is an option entirely. I don't know that the ESP can drive the necessary 8Khz signal easily (though I wouldn't be surprised if it could)

    The approach I am using for the ESP is closest to what you are calling "super-smart" in that it has a web ui with necessary pieces for JMRI integration and eventually WiThrottle possibly. The base station is also modified to expose the ESP in a way that the base station can properly report its IP as part of the "<s>" output. As far as the base station is concerned though, the ESP is just an extra device that it can interact with to send/receive DCC++ commands. I opted to go beyond the basic "pass everything on port 2650 to DCC++" in an effort to bring a bit more intelligence to the web ui as well as possibility to expose more features. So far the features I have exposed are limited but as time permits they will be increased.
     
  3. Simon Mitchell

    Simon Mitchell TrainBoard Member

    113
    105
    7
    onboard decoder...

    and re the PWM freq, is this any use?
     
  4. UK Steve

    UK Steve TrainBoard Member

    453
    683
    12
    Cool, now the fun begins....

    Just a reminder Mark,

    you need to upgrade the Arduino IDE before you can start playing with your new ESP's.

    The links in post #1587 here http://www.trainboard.com/highball/...ource-dcc-station-and-interface.84800/page-80
    are a great starting point. And once you've completed those upgrades, a nice little example to see if it's all working is the WiFi Scan sketch which you'll now find in the example library.

    UntitledWiFi.png

    Make sure your target board is set as in this next image. There is no need to make any adjustments to the sketch. Compile and upload as you would an Arduino. Node MCU dev boards also auto switch to flash mode via the upload tool so no need to worry about that either. Once done open the Serial Monitor an check out the results. Simples:)

    UntitledBoard.png

    Later you might as well just go for this option......

    This is something I'll be exploring down the road......
     
    Last edited: Feb 28, 2017
  5. TwinDad

    TwinDad TrainBoard Member

    1,844
    551
    34
    Cool. That was easy. IDE updated, sample sketch run successfully.
     
  6. UK Steve

    UK Steve TrainBoard Member

    453
    683
    12
    Mark,

    Great, I bet most first time users wish it went that easy:)

    How about a little Telnet to Serial fun. In this slightly modified example of the same name....

    Just enter your network credentials between the quotes on lines 25 and 26 of the attached file. Compile upload and watch the serial monitor. Note, baud setting is 115200

    You should see a message "Ready! Use 'telnet *DEVICE IP HERE* 23' to connect"

    If you point PuTTY to the IP on port 23 you should be able to send text in both directions, a simple Serial<=>WiFi bridge.
    This forms a basis for use as the Base Station WiFi interface.

    Copy/Paste the .txt file content into a new project in the IDE. Board settings as before......have fun.
     

    Attached Files:

    Scott Eric Catalano and sboyer2 like this.
  7. UK Steve

    UK Steve TrainBoard Member

    453
    683
    12
    So hopefully you'll get a flag for this post to continue here then:)

    ESP TX goes to Pin 0 arduino
    ESP RX goes to Pin 1 arduino

    I guess you're trying to run the WiThrottle interpreter code on Base Station then?

    Edit: Oh and it's generally accepted that ESP's can handle 5v logic these days, don't ever put 5v directly on Vcc though. On Node MCU you can supply 5v to Vin as it then goes through the onboard regulator same as USB

    It's always handy to have a copy of this around:)

    nodemcu_pins.png
     
    Last edited: Mar 1, 2017
  8. TwinDad

    TwinDad TrainBoard Member

    1,844
    551
    34
    I got it to work... mostly.

    I had to back out the Access Point changes and stick with using my home WiFi. I do have to reboot the Arduino *after* the ESP for some reason, but I'm able to connect with my phone and issue throttle commands.

    Oh, and to get there I had to disconnect the Arduino from the computer and power it separately (using a 12V wall wart, but I'm sure the USB wall wart would work too).

    So now I have something "good enough" for my shelf layout... will be better when I crack the Access Point nut and can get rid of the pocket router. And of course I still need to add on and test the motor shield and LCD display. Oh, and I need to find a way to reduce the memory footprint. I had to use my Mega, as I think I was running out of stack space on my UNO. Although with the other features I want to add, I may need to use the Mega anyway... or offload a bunch of stuff to the ESP. I suppose the ESP could control the display and buttons, if I wanted it to.

    Thanks for the help y'all!
     
    Scott Eric Catalano and sboyer2 like this.
  9. esfeld

    esfeld TrainBoard Member

    442
    382
    17
    Yeah! Looks like were 8266 active again.
    Steve F
     
    Scott Eric Catalano and sboyer2 like this.
  10. esfeld

    esfeld TrainBoard Member

    442
    382
    17
    "ESP8266 as the Base Station itself, with no Arduino involved."
    Steve ..... ESP32???
    Steve F
     
    Scott Eric Catalano and sboyer2 like this.

Share This Page