Wi-Fi controlled Robot via Huzzah ESP8266

Description

This project utilizes the Adafruit HUZZAH ESP8266 Breakout Module to enable remote control of a wheeled robot through a web page over Wi-Fi. Please read the previous link or this Adafruit Learning Page before using this board.

The chassis and motors for the robot are from Sparkfun's Redbot Kit. This project also uses a Pololu H-Bridge for motor control and a speaker with audio amp that acts as a horn.

Compared to older ESP8266 modules, the Huzzah is much more powerful, complete with its own set of pins for GPIO, Serial, etc. Because of these extra utilities, however, the Huzzah is meant to be interfaced through Lua, which can lead to compatibility difficulties with MBED. To avoid the hassle of using Lua and writing a lot of html code in the mbed file, the firmware can be overwritten so that the Huzzah is configured through the familiar Arduino IDE. When used in this manner, the Huzzah can take on some of the system responsibilities of the mbed, freeing up the mbed for other tasks.

NOTE: To program the ESP8266 Huzzah board as an Arduino you will need a USB-Serial FTDI Cable!

This project is similar to one found on Adafruit’s website, which uses a CC3000 Wi-Fi Arduino chip. In fact, the basis of our web interface can be found in the the Github code from that project. A few key differences in this code include a change in JQuery functions for responding to mouse clicks. Instead of listening for a mouse click event, we listen for a mousedown (click and hold) and a mouseup (release held click). This allows user control over when exactly the robot starts and stops moving. A downside to this is that we cannot have multi-direction travel. The robot rotates in place when turning to the left or right.

By looking at the Wi-Fi.h and WiFi-Server.h files for Arduino, and the Arduino sketch from the previously mentioned Adafruit project, this Arduino file (shown below) acts as an aREST server to service the web-page. The aREST library simply needs to be copied to your Arduino /libraries folder. This powerful API let’s the server listen for requests and handle them instantly as they come through. Note how we expose the variables and functions to the aREST API so that the node.js interface can call those functions by accessing a webpage.

FUN FACT: If you go to the IP Address of your server, say 192.168.1.1, and add ‘/’ and the variable name or function name you exposed to the aREST API, you can send commands to the robot in this manner. The node.js interface provides a nice GUI for you to use, but only from the computer that is running that code. You will also need to install node & npm on your computer. Then use the command “sudo npm install express arest jade” which will install the modules express, arest, and jade. Jade is what we will be using to display the interface on the webpage.

Once complete, the robot can be controlled by a computer that initiates communications with the Huzzah over the same LAN.

Wiring

Due to the number of high current-drawing components in our system, this project requires two 4xAA battery packs as power supplies, one solely for the motors and one for all the breadboard components.

For clarity, each component of the system has its own a wiring table, as outlined below.

mbedHuzzah ESP8266
VOUT (3.3 V)VBatt
GNDGND
P30P13
P29P12
P28P14
P27P4
P26P5
mbedH-BridgeExternal Power SupplyMotors
VOUT (3.3 V)VCC, STBY'
VMOT+
GNDGND-
AO1Right Motor +
AO2Right Motor -
BO1Left Motor +
BO2Left Motor -
P15AIN1
P16AIN2
P17BIN2
P18BIN1
P21PWMA
P22PWMB
mbedClass D Audio AmpSpeaker
VOUT (3.3 V)PWR +
GNDPWR -, IN -
P23IN +
OUT ++
OUT --

Media

/media/uploads/Zaydax/iece4180lab4wiring.jpg

Code

Wi-Fi_Robot

// Pratik Gangwani 
// Justin Tamayo 
// 3/15/16
// ECE 4180 Lab 4; Wi-Fi controlled robot
// C File to run MBEd anc control motor, LED, and speaker functions by reading in digital signals from Huzzah 8266 board

#include "mbed.h"
#include "Motor.h"
#include "Speaker.h"

//Define MBED LED's for use
DigitalOut myled1(LED1);
DigitalOut myled2(LED2);
DigitalOut myled3(LED3);
DigitalOut myled4(LED4);

// Define Digital Pins to read in digital signals from Huzzah 8266 board
DigitalIn forward(p30);
DigitalIn backward(p29);
DigitalIn left(p28);
DigitalIn right(p27);
DigitalIn horn(p26);

// Define Motor pins to connect to H-Bridge
Motor rightMotor(p21, p16, p15); // pwm, fwd, rev
Motor leftMotor(p22, p19, p17); // pwm, fwd, rev

// Define Speaker pin (MUST BE PIN 18, ANALOG OUT for use with Speaker.h!)
Speaker mySpeaker(p18);

int main() {

// Loop forever
// Check to see if a pin is high. If that pin is high, execute that pin for as long as the signal is high on that pin. 
// When you let go on the mouse click the code defaults to doing nothing
// Each pin moves the robot in a particular direction, and activates a specific LED
// Horn will not run forever if you hold it down, it is simply a click
// Setting speed to 0.5 on the motors saves a lot of battery power

    while(1){
        
        if(forward) {
            rightMotor.speed(0.5);
            leftMotor.speed(0.5);
            myled1 = 1;
            myled2 = 0;
            myled3 = 0;
            myled4 = 0;
        } else if(backward) {
            rightMotor.speed(-0.5);
            leftMotor.speed(-0.5);
            myled1 = 0;
            myled2 = 1;
            myled3 = 0;
            myled4 = 0;
        } else if(left) {
            rightMotor.speed(0.5);
            leftMotor.speed(-0.5);
            myled1 = 0;
            myled2 = 0;
            myled3 = 1;
            myled4 = 0;
        } else if(right) {
            rightMotor.speed(-0.5);
            leftMotor.speed(0.5);
            myled1 = 0;
            myled2 = 0;
            myled3 = 0;
            myled4 = 1;
        } else if(horn) {
            rightMotor.speed(0.0);
            leftMotor.speed(0.0);
            myled1 = 1;
            myled2 = 1;
            myled3 = 1;
            myled4 = 1;
            mySpeaker.PlayNote(440.0, 0.5, 0.5);
        } else {
            rightMotor.speed(0.0);
            leftMotor.speed(0.0);
            myled1 = 0;
            myled2 = 0;
            myled3 = 0;
            myled4 = 0;
        }
    }
}

Import programWiFiRobot

ECE 4180 Lab 4. Wifi robot controlled via webpage with Huzzah ESP8266 chip as server.

All files for this project (e.g. MBED code, ESP8266 code, Javascript files, etc.) are available below at the Github page.

Wi-Fi Robot Github Page

Demo Video


1 comment on Wi-Fi controlled Robot via Huzzah ESP8266:

10 May 2017

Hi, Can you provide more information using the ESP8266 IP address to send commands? I am looking to send data to my esp8266 using android application

Please log in to post comments.