Exercise: Wireless with ESP8266

Objective

The ESP8266 is a very small, very cheap wifi module. It can be programmed directly, but we will use it with an arduino. These chips are very small, cheap, and will allow the arduino to make wifi connections, ping servers, connect to mobile devices, act as a web server, and so on. We will connect to an external webserver and return text from the page.

Steps and observations

The ESP8266 is a finicky little chip, and care must be given to connect everything properly. The most important thing to note is that it operates at 3.3v, not 5v. Do not connect this chip to the 5v pin. It will probably break things. The ESP chip is small, cheap, and does not contain failsafe logic. In other words, it will just fry.

After conneting the RX,TX,Ground, and VCC pins, it seems you are ready to begin - but there are some things about the ESP8266 that you will need to know.

The first is that the CH_PD chip needs to be floated high. This means it needs to be connected - through a resitor (a 10k will do) - to a power supply. This allows the pin's signal to be '1' instead of '0'. The CH_PD pin is the "Chip Enabled" signal.

Next, the reset PIN also has an interesting operation. It is 1 for normal operation, and 0 for reset. We could float it high, just like the CH_PD chip - but then we wouldn't be able to reset our device. One option would be to wire it to a button that grounds the pin when pressed. We will connect it to a digital out pin on the arduino (pin 4, in our case). This lets us reset the ESP8266 in our software by changing the output of the pin. This will come in handy

We will need to install a custom library for this project. Read here for more information on installing arduino libraries

Okay, let's get started

  1. Connect Everything.
    1. Connect the 3.3v and ground pins from the arduino to appropriate (+, -) rails on the breadboard. Use red wires for 3.3v and black wires for ground.
    2. Connect the GND pin on the ESP8266 to the GND (-) rail on the breadboard
    3. Connect the TX on the ESP8266 to pin 2, and the RX on the ESP8266 to pin 3 on the arduino.
    4. Connect the RESET on the ESP to pin 4.
    5. Connect the CH_PD pin to a node on the breadboard.
    6. Connect a 10k resistor from the 3.3v rail on the breadboard to the same node as the CH_PD pin
    7. Connect the VCC pin to the 3.3v rail on the breadboard.
  2. Download and install the Adafruit ESP8266 library from this webpage and install it. If you got these files from github, a copy of the library is in the same folder this file is.
  3. Open the example code and read through it. Notice we can easily modify the pins we use to connect the board, the wifi SSD and password, and the webpage that the arduino will attempt to connect to.
  4. Try changing the web page that gets fetched to 'http://www.arduino.hdyar.com', which I set up for this assignment.
  5. Upload the project. Open the Serial Monitor. Use 57600 baud.
  6. CMU's wifi networks use a security protocal that we cannot handle with the ESP8266. (Or at least, not without some serious hacking). Use a portable network from a phone, or use one of the macbooks and turn on internet sharing to create an network that the ESP can connect to.

Comments

When it comes to internet connected devices, there are many many reasons errors can occur - often without helpful fedback. This difficulty in debugging always been an issue with internet connected devices. Don't worry. Hang in there. Keep working at it. Be smart. Narrow down your potential issues systematically. I believe in you.

If you are seeing errors in your serial monitor that have to do with connection, relax! Things could be worse! You are sending data and reciving it from the esp8266, which is responding to the commands being sent and also is not on fire.

The Arduino UNO can operate at 3.3v output, but many other arduino's operated at 5v and needed a line converter to connect to the board at 3.3v.

The example code we used is very simple, just reading a simple plaintext web page. We could set up our own webpage with some web code that, say, displays tweets. We could output this to an LCD screen from the Arduino. Perhaps we could modify this webpage from a phone using technologies like JQuery (edit: wait, I mean node.js or php. The arduino wouldn't be able to process client side javascript). No need to even write mobile phone apps. Without complicating the arduino code much and just a little knowledge of web programming, we already are in a ready state for hacking away at projects. That said, there is still much more to be done. Programmers have turned these little devices into web servers and more. Check out ESP8266.com and go googling about projects for a host of information and ideas, and lots of open source code.

Diagram created in Fritzing by Smokey

Other Files

  1. Adafruit Library and Example code.
  2. esp8266.com has many resources about the ESP
  3. An extensive eBook about the ESP8266