WiFi 'tethered' Arduino robot

From richmondmakerlabs.uk
Jump to navigation Jump to search

Back to Ian M's profile

Back in 2021 I was working on an Arduino based robot buggy. These are my notes on how to 'tether' the robot via an existing WiFi network to permit Arduino program upload, and serial terminal monitoring and control, from a Windows PC as-if I had a USB lead plugged into the Arduino.

Materials Required

  • Arduino, on robot - the Arduino must use the standard serial bootloader not the USB bootloader used on Leonardo etc.
  • Small ESP8266 module - e.g. Wemos D1 Mini (clone), or ESP01, or ESP01S (+ carrier board with 3.3V regulator).
  • Quad MOSFET Level Converter, e.g. https://www.sparkfun.com/products/12009
  • Miniature latching DPDT switch
  • DuPont jumper wires, to suit headers on robot
  • Strip of 0.1" pitch header pins
  • Small bore heatshrink sleeving

The level converter is needed if the Arduino is 5V. ESP01(S) don't have an on-board 3.3V regulator, average 70mA and can draw over 350mA peak, so you cant power one from a 5V Arduino's 3.3V auxiliary regulator. The DPDT switch is needed if you want to retain the capability to program the Arduino via USB. The header pins are needed if you want to make the level converter or ESP8266 module pluggable.

Theory

If nothing is connected to an Arduino's USB port, you can connect a serial interface to its MCU's RX and TX UART pins and program it over this interface. /RESET needs to be pulsed low immediately before programming to enter the bootloader. All that's left is the need for some method of connecting your PC to the Arduino UART pins wirelessly . . .

Construction

The hookup is: 5V Arduino <=> Level Converter <=> Switch <=> ESP8266 module or: 3.3V Arduino <=> Switch <=> ESP8266 module

Cut two jumper wires in the middle and solder all the cut ends to the switch so it can disconnect both wires. Optionally solder a link across both NO contacts so that when the switch is open, the ESP8266 RX and TX pins are looped together.

Fro 5V Arduinos, make Y (or daisychain) wires for power and ground, e.g. by cutting two DuPont jumpers and splicing three cut ends together, insulating it with heatshink. Make one red, and one black Y wire.

Populate the level converter (if used) and ESP8266 module with header pins.

Connect everything together:

5V Arduino Wiring - one wire per row
Arduino pin Level Converter pin Switch pin ESP8266 module pin Notes
5V HV - 5V (regulator feed) Y wire
3.3V LV
Gnd Gnd - Gnd Y wire
RX (0) HV0 Data to Arduino
LV0 NC0 "
COM0 TX "
TX (1) HV1 Data from Arduino
LV1 NC1 "
COM1 RX "
NO0-NO1 Esp-Link Loopback
Reset* HV3 Triggers bootloader
LV3 - GPIO* "
3.3V Arduino Wiring - one wire per row
Arduino pin Switch pin ESP8266 module pin Notes
3.3V - Vcc
Gnd - Gnd
RX (0) NC0 Data to Arduino
COM0 TX "
TX (1) NC1 Data from Arduino
COM1 RX "
NO0 - NO1 Esp-Link Loopback
Reset* GPIO* Triggers bootloader
  • If you are using a robot I/O shield it may not break out the Reset pin. You can pick it up on the Arduino's ISP header, but you will need a female DuPont wire without the shell on one end, and the crimp bent over at a right-angle, then insulated with heatshrink so you can connect to it without fouling your I/O shield.
  • Which ESP8266 GPIO to use for Reset depends on your module. It cant be RX, TX or used for the ESP8266 SPI Flash program memory.

Software

Firmware

The ESP8266 must be programmed with esp-link firmware: https://github.com/jeelabs/esp-link

Follow the instructions there to get it connected to your WiFi.

Enter something sensible for the Hostname, mine is called: ians-robot

Configure the esp-link pins to suit your module, and chosen GPIO pin for Reset.

N.B. If you move to another location with a different WiFi network, you'll need to reconfigure esp-link. You can also configure esp-link to provide an adhoc network your PC can connect to, but that's a PITA under Windows 10, if you also want internet access via WiFi, as even if you have two adapters, without a 3rd party (OEM) WiFi manager for one of them, Windows will try to connect both to the same network!

PC Software

If you are using Linux, or OSX, that's pretty much all you need as AVRDUDE can connect to a network port (and reset the Arduino on connect) using the -P net:hostname:2323 command-line option. Its possible to hack the Arduino IDE config files to add a programmer definition that invokes AVRDUDE with a command line that will connect direct to your robot, but I'm unsure of the exact method. You'll need to use a TELNET utility to connect to your robot for monitoring and control.

On Windows, its a little more complex as you'll need a virtual COM port utility and a network redirector for it. I'm using the freeware 'com0com' Null-modem emulator: https://sourceforge.net/projects/com0com/

  1. Grab the latest version of com0com and also com2tcp-1.3.0.0-386.zip from its files area.
  2. Extract and install the appropriate (x64 or x86) version of it for your windows. Don't let it create any port pairs during setup as it needs custom settings.
  3. Extract com2tcp-1.3.0.0-386.zip and copy com2tcp.exe to your new com0com program folder. Rename the com2tcp ReadMe.txt file (so you don't overwrite the com0com one) and copy it to the same place.
  4. com0com needs Microsoft Net Framework 2.0 (or higher) - Google how to activate or install that on you Windows version.
  5. The com0com driver will probably need updating - run Windows Update, goto 'View other updates' '>Driver Updates' and accept any 'Ports' or 'CNCPorts' updates by 'Vyacheslav Frolov'.
  6. Restart your PC!
  7. Run the com0com GUI config utility and set up a port pair: The visible side of the pair should be called COMnn (set nn to your preference), and have 'emulate baud rate' and 'enable plug-in mode' checked. The hidden side of the pair should be called ESPLINK, and have 'emulate baud rate' and 'enable hidden mode ' checked, so that when it is opened the visible side appears.
  8. Create a shortcut to com2tcp.exe called 'Connect to robot', to run minimised:

    cmd /c "C:\Program Files (x86)\com0com\com2tcp.exe" --baud 115200 \\.\ESPLINK hostname 2323 & pause

    Change 'hostname' to match esp-link settings + whatever LAN suffix (if any) your router uses. You *may* change the baud rate, but 115200 works well for me. To avoid buffer overruns the baud rate needs to match the esp-link settings. Do not change the port 2323 as that signals esp-link to reset the target when it is opened (required for AVRDUDE <> bootloader sync).

  9. Now, if your robot is switched on, it will connect to WiFi and if its DPDT switch is in its through-connected position, you can connect the COM port you selected in step 7 to it by running the above shortcut. Select that port in the Arduino IDE and is should 'just work' as-if you had plugged in the USB cable, for both programming and the serial terminal. When you are done, close the 'Connect to robot' window and the COM port will go away.
  • If the COM port doesn't appear in the Arduino ports list, or if programming fails go to the Connect to robot' window and examine any error messages from com2tcp.exe.
  • To program the Arduino via its USB port, you must disconnect the ESP8266 by putting the switch in its open or loopback position, or if you omitted the switch, by unplugging the RX and TX jumper wires.
  • I have a Windows batch script that automates configuring com-0com to connect to the robot, and creating the 'Connect to robot' shortcut (steps 7 and 8 above). It needs the OptimumX Shortcut utility: https://www.optimumx.com/download/Shortcut.zip unpacked in the same folder and also com2tcp.exe, which it copies to the com0com folder if it isn't already there. Run it from a command prompt with a /? switch, and it will tell you how to use it. Get it here: File:SetupRobotLink.zip Use at your own risk!