This was a fun exercise to get started with my new ESP32 dev board from Amazon. The robot is cobbled together: Servos and Battery Packs are connected to the Breadboard using neon duct tape, and the R2D2 caster is held on with Velcro. It consists of 2 parts: the ESP32 Robot, and the ESP8266 remote. It could be just as easy to send commands with a cell phone browser or custom app.The Robot is based around an ESP32 Dev kit. The ESP32 acts as a WiFi access point (AP), and as an HTTP server. I set the on-board LED to turn on whenever the AP has clients connected. Once connected to the access point, the robot responds to GET requests on port 80. The AP defaults to an IP of 192.168.4.1, and accepts 3 main commands for the servos:
- Forward: http://192.168.4.1/servo/up
- Backward: http://192.168.4.1/servo/down
- Stop: http://192.168.4.1/servo/stop
The code is designed so that the Forward command goes more-or-less straight forward, but the Backward command makes it back up and turn, like a child's first RC car. It could be a fun exercise to add support for specifying exact speed or controlling the servos independently, but my remote only had three buttons so that's all I needed. Figuring out how to control the servos was a fun experience, as the analogWrite() command has not yet been implemented in the ESP32 Arduino Core. Thank you to Hackaday's Elliot Williams for introducing me to ledcWrite() and its supporting functions! At 50 Hz and 16-bit depth, values between 1500 and 8000 worked to cover most if not all of the range of my RadioShack (RIP) servos. I had the servos lying around. A couple years ago I modified them for continuous rotation using this tutorial from societyofrobots.com.
The batteries include a 6000 mAh USB power pack and a 4xAA battery holder. I originally powered it using just the USB power, but the system crashed with almost every servo request. Turns out the servos were sucking too much power and browning out the chip. Now the four AA batteries power the servos, the USB pack powers the board, and everything is great. I've read that the ESP32 is supposed to have some special Brownout reset functionality or something. I must not have been taking advantage of this, because the servo calls were causing the processor to halt, not reset.
The Remote is based around the Adafruit Feather HUZZAH and OLED Feather Wing that I received in ADABOX003. The ESP8266 acts as a WiFi Station (STA), and as an HTTP client. All of the Feathers have built in LiPo battery connectors and chargers, so it makes a perfect handheld remote! When turned on, the ESP8266 attempts to connect to the ESP32's access point. SSID and PSK are hard-coded into both AP and STA firmwares. The OLED Feather Wing conveniently includes three buttons labeled A, B and C, so those serve as the Foward, Stop, and Backward buttons. When a button is pressed, the corresponding GET request is sent to the ESP32, and a "+", "0", or "-" is printed on the display.
I initially had issues getting the ESP8266 to connect to the ESP32's AP, or getting "Connection Refused" when making the GET requests. These issues did not manifest when the roles were switched (8266 as AP and 32 as STA works fine all day). All of my issues were solved by these commands in the setup function on the 8266:
WiFi.mode(WIFI_OFF); // Turn off radio completely
delay(1000); // Wait for '32 to decide '8266 is not connected anymore
WiFi.mode(WIFI_STA); // Turn on radio in STAtion mode: don't broadcast my own SSID
In retrospect, I think the two boards were automatically remembering and connecting to each other's access points, giving each other conflicting identical IP addresses, and mayhem ensued. I'm still getting to know the ESP8266, and I'm often pleasantly surprised by all the features included in such an inexpensive device. The WiFi stack takes care of automatically reconnecting to the AP if the network disappears and reappears (which happened often while flashing and re-flashing the robot). The stack also remembers...Read more »