Book Image

ESP8266 Robotics Projects

By : Pradeeka Seneviratne
Book Image

ESP8266 Robotics Projects

By: Pradeeka Seneviratne

Overview of this book

The ESP8266 Wi-Fi module is a self-contained SOC with an integrated TCP/IP protocol stack and can give any microcontroller access to your Wi-Fi network. It has a powerful processing and storage capability and also supports application hosting and Wi-Fi networking. This book is all about robotics projects based on the original ESP8266 microcontroller board and some variants of ESP8266 boards. It starts by showing all the necessary things that you need to build your development environment with basic hardware and software components. The book uses the original ESP8266 board and some variants such as the Adafruit HUZZAH ESP8266 and the Adafruit Feather HUZZAH ESP8266 . You will learn how to use different type of chassis kits, motors, motor drivers, power supplies, distribution boards, sensors, and actuators to build robotics projects that can be controlled via Wi-Fi. In addition, you will learn how to use line sensors, the ArduiCam, Wii Remote, wheel encoders, and the Gripper kit to build more specialized robots. By the end of this book, you will have built a Wi-Fi control robot using ESP8266.
Table of Contents (15 chapters)
Title Page
Credits
About the Author
About the Reviewer
www.PacktPub.com
Customer Feedback
Preface

Connecting with a breadboard


You can use one of the following things to connect ESP8266 with a breadboard:

Power supply

The ESP8266 works only with regulated 3.3V. You can build a simple regulated power supply with an LD1117-3.3 linear voltage regulator. It can provide 3.3V at 800 mA. You can purchase a TO-220 package of the LD1117-3.3 for use with a breadboard. Figure 1.5 shows the circuit diagram for 3.3V output. You can supply 4-15V DC to Vin using one of the following sources:

  • 7V LiPo battery
  • 5V power bank
  • 9V battery
  • 5V "wall wart" power supply

Figure 1.5: 3.3V regulated power supply circuit diagram

Now, you can connect the power supply to ESP-01:

  1. Connect Vout to the Vcc pin of ESP-01.
  2. Connect GND to the GND pin of ESP-01.

Connecting through USB for flashing

ESP8266 ESP-01 doesn't have a built-in USB to serial conversion chip to directly connect to your computer through a USB cable for flashing programs. As a solution, you can use a USB to TTL serial console cable to connect ESP8266 to a computer. Figure 1.6 shows a USB TTL serial console cable from Adafruit (https://www.adafruit.com/product/954):

Figure 1.6: A USB to TTL serial console cable. Image courtesy of Adafruit Industries (https://www.adafruit.com)

The type A USB plug includes a USB to serial conversion chip and provides four wires to connect to your ESP8266ESP-01 board. Table 1.1 shows the functions of the four wires:

Color

Function

Red

Power

Black

Ground

White

RX

Green

TX

Table 1.1: Color codes and functions of wires

You can use the following steps to connect the USB to TTL serial cable with your ESP8266:

  1. Connect the white RX wire of the cable to the TX pin of ESP8266
  2. Connect the green TX wire of the cable to the RX pin of ESP8266
  3. Connect the black ground wire of the cable to the GND pin of ESP8266
  4. Connect the CH_PD pin of ESP8266 to the Vcc wire of the power supply

Note

Don't connect the red power wire because it is 5V.

Using a serial terminal program

The following steps will guide you how to use a serial terminal program to communicate and execute AT commands with ESP-01. In this example, you will use PuTTY, SSH, and a Telnet client for Windows to run AT commands through a serial port:

  1. First, download the latest PuTTY MSI installer or binary from the following sources:
  1. Open the PuTTY Configuration window by double clicking on putty.exe or the putty shortcut.
  2. In the Serial line text box, type the COM port that is assigned to your ESP8266 board (Figure 1.7).
  3. In the Speed text box, type 115200 as the baud rate.
  1. Click on the Open button to make a serial connection:

Figure 1.7: The PuTTY configuration window

  1. If you have provided the correct settings, the serial connection will establish between ESP8266 and your computer.
  2. You can use the serial terminal window to issue AT commands for ESP8266 from your computer.

AT commands

Table 1.2 shows the complete set of AT commands that you can use with ESP8266:

AT command

Manual

AT

Attention.

AT+RST

Resetting the unit.

AT+GMR

Retrieving the firmware version ID.

AT+CWMODE=?

AT+CWMODE?

AT+CWMODE=<mode>

Setting operation mode:

  • Client
  • Access point
  • Client and access point

The access point functionality does not have a DHCP function and has only minimum functionalities. However, it will assign an IP address to the client and there is no way to do a manual IP, manual DNS, and other advanced IP functionalities. This unit only provides minimal functionalities.

AT+CWJAP=<ssid>,<pwd>

AT+CWJAP?

Joining a network or just an access point.

AT+CWLAP

Retrieving the list of the visible network.

AT+CWQAP

Disconnecting from the current network connection.

AT+CWSAP=<ssid>,<pwd>,<chi>,<ecn>

AT+CWSAP?

Setting up access point SSID, password, RF channel, and security scheme.

The following is the security scheme:

  • 0: Open. No security.
  • 1WEP.
  • 2WPA_PSK.
  • 3WPA2_PSK.
  • 4WPA_WPA2_PSK.

AT+CWLF

Retrieving a list of assigned IP addresses.

AT+CIPSTATUS

Retrieving the current connection as socket client or socket server.

AT+CIPSTART=?

AT+CIPSTART=<type>,<addr>,<port> (AT+CIPMUX=0)

AT+CIPSTART=<id>,<type>,<port> (AT+CIPMUX=1)

Connecting to socket server (TCP or UDP).

AT+CIPSEND=<length> (AT+CIPMUX=0 & AT+CIPMODE=0)

AT+CIPSEND=<id>,<length> (AT+CIPMUX=1 & AT+CIPMODE=0)

AT+CIPSEND (AT+CIPMUX=0 & AT+CIPMODE=1)

Sending by connection channel and by specific length.

AT+CIPCLOSE

Closing the socket connection.

AT+CIFSR

Retrieving the assigned IP address when the unit is connecting to a network.

AT+ CIPMUX=AT+CIPMUX?

Setting a single connection (AT+CIPMUX=0) or multi-channel connection (AT+CIPMUX=1).

AT+CIPSERVER= [,] (AT+CIPMUX=1)

Starting at the specified port or stopping the server.

The default port is 333.

<mod> is as follows:

  • 0: Close the socket server
  • 1: Open the socket server

AT+CIPMODE=<mode>

AT+CIPMODE?

Setting transparent mode (data from the socket client will be sent to the serial port as is) or connection channel specific mode (+IPD,<connection channel>,<length>) segments.

Data sent from the socket client will be broken into multiple unsolicited (+IPD,<connection channel>,<length>) segments.

<mode>is as follows:

  • 0: Data received will be sent to the serial port with a +IPD,<connection channel>,<length> format. (AT+CIPMUX=[0,1])
  • 1: Data received will be sent to the serial port as a data stream. (AT+CIPMUX=0)

AT+CIPSTO=<time>

AT+CIPSTO?

Setting the automatic socket client disconnection timeout from 1 to 28800 seconds due to inactivities.

Packetized data from the unit

Unsolicited data packet (+IPD, <connection channel>,<length>).

Table 1.2: The ESP8266 AT command set (Source: SparkFun Electronics)

Using AT commands

Every AT command starts with the letters AT. Here's an example:

AT+GMR <CR>

Type the AT command AT+GMR and press the Enter key. Don't type <CR>. The CR indicates carriage return.

This will return the firmware version ID of the ESP8266 module, as shown in Figure 1.8:

Figure 1.8: Terminal output for the AT+GMR command

Likewise, you can run any AT command with the PuTTY terminal to execute on ESP8266 through the serial connection.