Technology

Off-the-Shelf Hacker: Add WiFi Connectivity to Your DIY Projects with the ESP8266

6 Feb 2016 6:01am, by

Perhaps because of the device’s immense popularity, there is a conflicting information on the Web about the ESP8266 DIY WiFi module, leading to much frustration and pulling of hair.

In future editions of the Off-The-Shelf Hacker, we’ll examine how to use Node.js or Lua to program this versatile WiFi system-on-a-chip (SoC). First, though, it makes sense to look at a few of its quirks and nuances, particularly with making firmware uploads work.

“The ESP8266 WiFi Module is a self-contained SOC with integrated TCP/IP protocol stack that can give any microcontroller access to your WiFi network,” manufacturer’s website reads. “The ESP8266 is capable of either hosting an application or offloading all Wi-Fi networking functions from another application processor.”

13678-01

Today, I’ll cover what I’ve found to work reliably for the ESP8266-01 model. These are the most common boards and only have eight pins. We’ll use the -07 model (with lots more pins and an external antenna) in a later article.

Remember, too, that the 8266 is a 3.3-volt device. While some people say they’ve used them with 5-volt connections, I’d definitely stick to the 3.3-volt spec for power, serial communication and GPIO pin operations. And I order three at a time..so, you know…just to be on the safe side. Ten bucks, big deal.

FTDI Hookup And Level Shifting

The 8266 uses a serial interface for programming. My Linux notebook only has USB ports.

What to do? Use an FTDI cable. It converts a notebook USB connection into something an 8266, Arduino, XBee radio module or any number of other serial devices can understand.

There are two common cable versions available, 5 volts and 3.3 volts. They are about $18 each through Adafruit, Sparkfun and other vendors. As mentioned earlier, the 8266 modules work with 3.3 volts, not 5.0 volts. That’s a challenge if you only have a 5 volt FTDI cable, like me.

A practical solution that I had in my parts bin is to use a level shifter. I keep a few handy for these kinds of situations. It’s a little board that goes between the end of the 5-volt FTDI cable and the 8266, converting the signals to the required 3.3-volt level. Using a 3.3-volt FTDI cable would be neater and easier. I’m cheap. What can I say?

Below is the schematic of the 8266 on my breadboard.

Simple ESP8266 Setup

Simple ESP8266 Setup

You’ll notice that I’ve included three switch symbols. Of course, physically, they represent plugging and unplugging wires into the breadboard, as we’ll discuss shortly, when doing a firmware upload.

Also, the FTDI Basic programmer represents my FTDI cable. Functionally, they are interchangeable. The FTDI cable, plugs into my Linux notebook through the USB port.

Now that you know about the FTDI cable, we’ll need a program to upload.

A great way to program the 8266 is by using the Arduino IDE. There are a ton of examples in the latest version of the application. I’m using version 1.6.7. For this exercise, I loaded the basic “hello server” Web page demonstration program and tweaked it a little bit. The important parts to modify are the network parameters. My network router uses encryption, so the password needs to be included, otherwise, the 8266 will never connect. Edit in your own access point ID and password lines at the beginning of the file.

const char* ssid = "your access point ID goes here";
 const char* password = "your access point password goes here";

Uploading Firmware

Once you’ve edited your program, it’s time to upload the firmware to the 8266 module.

This is a little tricky with the 5-volt FTDI cable and level converter, but it works great if you just know the proper steps:

  1. Unplug GPIO0 from the normal 3.3-volt connection position.
  2. Plug GPIO0 into the ground (negative battery connection). This configures the 8266 for upload mode.
  3. Temporarily unplug the TX1 connection and leave it unconnected.
  4. Temporarily plug and unplug the Reset line to ground. The blue LED should flash solid then once briefly as the ESP8266 reboots. This is needed to actually boot into upload mode.
  5. Plug the TX1 connection back in. This reconnects the FTDI/Level shifter to the 8266.

Now hit the Upload button at the top of the Arduino IDE.

The IDE will compile the program and start uploading the firmware to the 8266. You’ll know it’s working because there will be an uploading message and a series of dots scrolling across the Arduino status window. When the dots stop moving the upload is complete:

  1. Move the GPIO0 connection from the ground back to the positive 3.3-volt position. This configures the 8266 for run mode.
  2. Temporarily unplug the TX1 connection.
  3. Temporarily plug and unplug the Reset line to ground. The blue LED should flash solid then once briefly as the 8266 reboots and gets an IP address from your network.

After a couple of seconds, you can punch the 8266’s IP address into a browser and see the text line appear from the newly implemented Web server.

There are a couple of ways to find the 8266’s IP address. Load “Fing” on your Android phone and scan your network for the 8266 module. Mine shows up as “espressif”.

Another way to determine the IP is to reset the 8266 and watch the serial console on the Arduino IDE. Follow these steps.

  1. Temporarily unplug the TX1 connection and leave it unconnected.
  2. Temporarily plug and unplug the Reset line to ground.
  3. Immediately plug the TX1 connection back in and watch the serial monitor.

You’ll see some funky characters while the 8266 boots, then several strings of characters, one of which will be the module’s IP address.

Remember that the TX1 connection is the wire to the module (on the breadboard), not the USB connector. If you unplug the USB connector from the notebook, the Arduino IDE will get confused and not want to talk to the 8266 module anymore. Close and restart the Arduino IDE, to get it going again.

Go Program Your 8266

There you have it. Painless firmware uploading on an ESP8266-01. Once, it’s programmed you don’t even need the FTDI/Level shifter connected anymore. And, upon power up, the 8266 should reboot into run mode without having to ground the reset pin.

Feel free to check out the other 8266 examples in the Arduino IDE. It’s a powerful little board, with a lot of potential. And, they are cheap (inexpensive) too.


A digest of the week’s most important stories & analyses.

View / Add Comments

Please stay on topic and be respectful of others. Review our Terms of Use.