ESP8266 Robotics Projects

4.5 (4 reviews total)
By Pradeeka Seneviratne
  • Instant online access to over 8,000+ books and videos
  • Constantly updated with 100+ new titles each month
  • Breadth and depth in over 1,000+ technologies
  1. Getting Ready

About 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.

Publication date:
November 2017
Publisher
Packt
Pages
208
ISBN
9781788474610

 

Chapter 1. Getting Ready

Welcome to the exciting world of programming ESP8266 with Arduino core for ESP8266. This chapter introduces ESP8266 and a simple LED blink program using the Arduino core for the ESP8266 library.

In this chapter, you will learn the following topics:

  • The basics of ESP8266 and the module family
  • The original ESP8266 ESP-01
  • Applying regulated power to ESP-01
  • Connecting ESP-01 with computer through a USB to TTL serial console cable
  • Preparing the development environment by installing the Arduino core for the ESP8266 library
  • Writing a simple LED blink program using the Arduino core for ESP8266
  • Using AT commands
  • The overview of some robotics hardware and accessories
 

ESP8266EX


The ESP8266EX (Figure 1.1) is a single-chip microcontroller developed by Espressif (https://espressif.com/). It can be used to develop low-power, highly-integrated Wi-Fi solutions especially for mobile devices, wearable electronics, and the Internet of Things (IoT) applications. The main advantage of ESP8266EX is that it can give any microcontroller access to a Wi-Fi network. As an example, it can offload all Wi-Fi networking functions for Arduino just like the Arduino Wi-Fi shield:

Figure 1.1: ESP8266EX chip

The chip has the following great features:

  • Small size (5 mm x 5 mm)
  • Requires minimal external circuitry
  • Wide temperature range (-40°C to + 125°C)
  • All-in-one small package -SoC (integrates a 32-bit Tensilica MCU, standard digital peripheral interfaces, antenna switches, RF balun, power amplifier, low-noise receive amplifier, filters, and power management modules)
  • Low power consumption

ESP-01

ESP-01 is a small Wi-Fi module based on Espressif ESP8266EX that can give any microcontroller access to a Wi-Fi network. The ESP-01 module (Figure 1.2) is the basic and the most popular board of the ESP8266 module family. You should have an ESP8266 ESP-01 module to understand the basics of ESP8266 and build robotics projects.

This is a list of vendors that typically stock the ESP-01 modules:

Figure 1.2: The original ESP8266 ESP-01. Image courtesy of SparkFun Electronics (https://www.sparkfun.com)

The original ESP8266 ESP-01 has the following features:

  • Offloads all Wi-Fi networking functions from another application's processor
  • Self-hosting of applications
  • Only four pins interface, VCC-3V3, GND, TX, and RX
  • 1 MB (8 MB) flash memory
  • Pre-programmed AT command set firmware
  • Supports APSD for VoIP applications and Bluetooth co-existence interfaces

Here is a list of all the ESP8266 boards of the ESP8266 module family at the time of writing:

  • ESP-01
  • ESP-02
  • ESP-03
  • ESP-04
  • ESP-05
  • ESP-06
  • ESP-07
  • ESP-08
  • ESP-09
  • ESP-10
  • ESP-11
  • ESP-12
  • ESP-12F
  • ESP-12-E/Q
  • ESP-12S
  • ESP-13
  • ESP-14

Board features and connections

The top of the ESP-01 board consist of the following things:

  • An ESP8266EX chip—Offloading all Wi-Fi networking functions
  • A Berg Micro BG25Q80A 1518 flash chip—Serial Peripheral Interface (SPI) flash memory
  • A printed Wi-Fi antenna—Transmitting and receiving Wi-Fi signals

Figure 1.3: ESP-01 top view

Connections

The original ESP8266 ESP-01 board has eight pins and comes without headers. You can solder regular wires with pins, but if you want to use it with a breadboard, you should attach headers:

Figure 1.4: ESP-01 pinout

  • GPIO0: Connects to pin 3 of the ESP8266
  • GPIO2: Connects to pin 5 of the ESP8266
  • TX: This is the transmitting line that connects to RX of another device
  • RX: This is the receiving line that connects to TX of another device
  • 3V: This accepts regulated 3.3V DC from a regulator to power the board
  • GND: The ground pin
  • CH_PD: Chip select
  • RST: The reset pin
 

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.
  • 1: WEP.
  • 2: WPA_PSK.
  • 3: WPA2_PSK.
  • 4: WPA_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.

 

Using the Arduino IDE


The Arduino IDE provides an easy way to write sketches for Arduino and other development boards. You can use ESP8266 with the Arduino IDE. First, install the ESP8266 board package on Arduino IDE.

The ESP8266 also supports the following development environments:

  • Use a simple Notepad/GCC setup
  • Fine-tune an Eclipse environment
  • Use a virtual machine provided by Espressif

Installing the Arduino core for an ESP8266 Wi-Fi chip

The Arduino core for ESP8266 includes a set of libraries to do the following things with your ESP8266 Wi-Fi module:

  • Communicate over Wi-Fi using TCP and UDP protocols
  • Set up HTTP, mDNS, SSDP, and DNS servers
  • Perform OTA updates
  • Use a filesystem in flash memory
  • Work with SD cards, servos, SPI, and I2C peripherals

It also allows you to write sketches for ESP8266 with the core Arduino functions and libraries. You can run the sketches directly on ESP8266 without using an external microcontroller board:

  1. Open the Arduino IDE and on the menu bar select File | Preferences.
  1. Type the URL http://arduino.esp8266.com/stable/package_esp8266com_index.json for the ESP8266 board manager package for Arduino in the Additional Boards Manager URLs text box and click on OK to close the dialog box (Figure 1.9):

Figure 1.9: The Arduino IDE preferences

  1. Open the Boards Manager by selecting Tools | Board | Boards Manager. You should see a new entry in the list titled esp8266 by ESP8266 Community (Figure 1.10):

Figure 1.10: The Arduino IDE Boards Manager

  1. At the time of this writing, the Arduino core for ESP8266 Wi-Fi chip supports the following boards:
    • Generic ESP8266 Module
    • Olimex MOD-WIFI-ESP8266(-DEV)
    • NodeMCU 0.9 (ESP-12 Module)
    • NodeMCU 1.0 (ESP-12E Module)
    • Adafruit HUZZAH ESP8266 (ESP-12)
    • ESPresso Lite 1.0
    • ESPresso Lite 2.0
    • Phoenix 1.0
    • Phoenix 2.0
    • SparkFun Thing
    • SweetPea ESP-210
    • WeMos D1
    • WeMos D1 mini
    • ESPino (ESP-12 Module)
    • ESPino (WROOM-02 Module)
    • WifInfo
    • ESPDuino
  2. Click on the Install button to install it on your Arduino IDE. This will take a few minutes to install, depending on your internet speed.
  3. Click on Close to close the Boards Manager dialog box.
  4. Select Tools | Board: "Generic ESP8266 Module" | Generic ESP8266 for board type.
  5. The upload speed should be 115200; however, you can increase it to a higher value by clicking on Tools | Upload Speed and selecting a value greater than 115200.

Hello world

Now, you will write your first program (sketch) for ESP8266 with the Arduino IDE to blink a LED connected to PIN 2 of ESP8266.

You'll need the following things to build the circuit:

  • One LED (any color)
  • One 1 kilo ohm resistor
  • 3V regulated power supply

Connect the components together, as shown in Figure 1.11:

Figure 1.11: The LED blink circuit hook up

Listing 1-1 – Blink a LED

Using your Arduino IDE, type the code as shown in the Listing 1-1:

#define ESP8266_LED 2void setup() {  pinMode(ESP8266_LED, OUTPUT);}void loop() {  digitalWrite(ESP8266_LED, HIGH);delay(500);digitalWrite(ESP8266_LED, LOW);delay(500);}

Then, verify the sketch by clicking on the Verify button. Finally, upload the program by clicking on the Upload button. This will take a few seconds to complete. After completing the flashing, the LED will start to blink.

 

Using chassis kits and accessories to build robots


Chassis kits provide everything to build robots with most microcontroller boards. You'll use the following chassis kits to build projects.

Mini 3-Layer Round Robot Chassis Kit

The 3-Layer Mini Round Robot chassis Kit (Figure 1.12) includes the following things you need to build the shell of a two-wheel drive mobile platform robot:

  • Two drive motors
  • Two wheels
  • One plastic caster ball
  • Anodized aluminum frames and all mounting hardware for assembly

You can purchase a kit from Adafruit Industries (https://www.adafruit.com/product/3244) to work with projects that will be discussed in Chapter 2, Building a Mini Round Robot with Original ESP8266, Chapter 3, Using Encoders, and Chapter 4, Building a Mini Round Robot with the Feather HUZZAH ESP8266:

Figure 1.12: A Mini Round Robot Chassis Kit. Image courtesy of Adafruit Industries (https://www.adafruit.com)

Zumo chassis kit

The Zumo chassis kit (Figure 1.13) allows you to build tracked robots that run on continuous tracks instead of wheels. Tracked vehicles can be used for:

  • Construction vehicles
  • Military armored vehicles
  • Unmanned ground vehicles

The Zumo chassis kit includes the following things:

  • Zumo chassis main body
  • 1/16" black acrylic mounting plate
  • Two drive sprockets
  • Two idler sprockets
  • Two 22-tooth silicone tracks
  • Two shoulder bolts with washers and M3 nuts
  • Four 1/4" #2-56 screws and nuts
  • Battery terminals

You can purchase a kit from Pololu (https://www.pololu.com/product/1418) to work with the project that will be discussed in Chapter 5, Line-Following Zumo Robot:

Figure 1.13: A Zumo chassis kit. Image courtesy of Pololu (https://www.pololu.com)

Romi chassis kit

The Romi chassis kit (Figure 1.14) includes the following things you need to build a two-wheel drive robot:

  • One black Romi chassis base plate
  • Two mini plastic gearmotors (120:1 HP with offset output and extended motor shaft)
  • A pair of black Romi chassis motor clips
  • A pair of white 70 × 8 mm Pololu Wheels
  • One black Romi chassis ball caster kit
  • One Romi chassis battery contact set

You can purchase a kit from Pololu (https://www.pololu.com/category/202/romi-chassis-and-accessories) to build the project that will be discussed in Chapter 6, Building an ESP8266 Robot Controller:

Figure 1.14: A Romi chassis kit - Black. Image courtesy of Pololu (https://www.pololu.com)

Mini robot rover chassis kit

The mini robot rover chassis kit (Figure 1.15) includes the following things needed to build the shell of a two-wheel  drive robot:

  • Two wheels
  • Two DC motors in MicroServo shape
  • One support wheel
  • One metal chassis
  • One top metal plate with mounting hardware

Figure 1.15: A mini robot rover chassis kit. Image courtesy of Adafruit Industries (https://www.adafruit.com)

You can purchase a kit from Adafruit industries (https://www.adafruit.com/product/2939) to build the project that will be discussed in Chapter 7, Building a Gripper Robot.

Rover 5 robot platform

The Rover 5 robot platform (Figure 1.16) allows you to build a four-wheel drive tracked robot. The kit includes the following things:

  • Adjustable gearbox angles
  • 4 independent DC motors
  • 4 independent Hall-effect encoders
  • Thick rubber tank treads
  • 6 x AA battery holder
  • 10 Kg/cm stall torque per motor

Figure 1.16: A Rover 5 robot platform. Image courtesy of Pololu (https://www.pololu.com)

You can purchase a kit from Pololu (https://www.pololu.com/product/1551) to build a project that will be discussed in Chapter 8, Photo Rover Robot.

Wheel encoder kit

The wheel encoder kit (Figure 1.17) allows you to measure the speed or distance that the chassis travels. You'll learn how to connect the wheel encoder kit to any wheeled robot in Chapter 3, Using Encoders:

Figure 1.17: A wheel encoder kit. Image courtesy of SparkFun Electronics (https://www.sparkfun.com)

Parallel Gripper Kit A - Channel mount

A gripper can be connected to a robot to allow grip objects. Figure 1.18 shows a Parallel Gripper Kit assembled. You will need any standard size Hitec or Futaba servo to integrate with the gripper kit. You can purchase one from SparkFun Electronics (https://www.sparkfun.com/products/13178):

Figure 1.18: Parallel Gripper Kit A - Channel mount

 

Summary


In this chapter, you learned the basics of the ESP8266 microcontroller and the modules based on it. Then, you learned how to run AT commands on ESP8266 and used the Arduino core for ESP8266 to write sketches. Finally, you gained knowledge on various robot chassis kits and accessories that can be used to build robots.

Chapter 2, Building a Mini Round Robot with Original ESP8266, offers the fundamentals of robotic vehicles by building a mini round robot with ESP-01.

 

About the Author

  • Pradeeka Seneviratne

    Pradeeka Seneviratne is a software engineer with over 10 years' experience in computer programming and systems design. He is an expert in the development of Arduino- and Raspberry Pi-based embedded systems. Pradeeka is currently a full-time embedded software engineer who works with embedded systems and highly scalable technologies. Previously, he worked as a software engineer for several IT infrastructure and technology servicing companies. He collaborated with the Outernet project as a volunteer hardware and software tester for Lighthouse- and Raspberry Pi-based DIY Outernet receivers based on Ku band satellite frequencies. He is also the author of five books:

    • Internet of Things with Arduino Blueprints [Packt Publishing]
    • IoT: Building Arduino-Based Projects [Packt Publishing]
    • Building Arduino PLCs [Apress]
    • Raspberry Pi 3 Projects for Java Programmers [Packt Publishing]
    • Beginning BBC micro:bit [Apress]

    Browse publications by this author

Latest Reviews

(4 reviews total)
----------------------------
Ich bin mit den gekauften und den freien Ebooks sehr zufrieden und PACKT nur weiterempfehlen.
A falta de leerlo, me parece un libro muy interesante

Recommended For You

Book Title
Unlock this full book with a FREE 10-day trial
Start Free Trial