Getting Started with the ESP8266 Vivek Vidyasagaran
This is a post about how to get started working with the ESP8266 module and start doing interesting things with it. I will describe what we created, which is specific to our project, but a lot of the things are common to a lot of different applications for the module.
Purchasing The first thing you’ll find when you google the ESP8266 module is that there are a lot of different form factors for the module. It comes in a variety of shapes and sizes, each of which finds a specific balance between ease-of-use and size. I’ll just talk about the ones we were dealing with. There are probably a few more varieties of this around.
This is adafruit’s version. This is probably the easiest one to work with. It’s got clean pins that expose all of it’s functionality and can easily be put on a breadboard for experimentation. ESP-01
This is the much smaller version. It is remarkably tiny. It’s hard to believe that this little guy has a Wifi module as well as a pretty respectable microcontroller inside. And all for just about $3! One problem with this is that, as you might have noticed, it has only 8 pins. Vcc, Gnd, Tx, Rx, Chip PowerDown and Reset make up 6 of them, leaving just 2 GPIO pins. So not as much flexibility as the previous module. But still definitely a good choice for limited functionality.
This gives you all the standard capabilities in the larger form factor, and also allows for an external antenna to be connected. We ended up using this module for our proximity detection in the final version because the external antenna is far more omnidirectional than the one on-board. ESP-12
Finally, this is another version. It has all the pins like the Huzzah, just in a non-breadboard-friendly format. This is the sort of module you would use when you have fabricated a PCB for your specific needs and need to mount your Wifi chip onto it (although that didn’t stop us from experimenting with this on a breadboard anyway). It’s about the same size as the previous form factor, with all the functionality of the first one. Set-up Some of these modules (NodeMCU) come with a Lua toolchain. You use Lua on your development environement. However, there is an Arduino toolchain too (which is probably the best way to go if you are coming from the arduino environment and have used their IDE before). There’s good documentation on how to get this set up and running in the Arduino environment so I won’t go into that. It’s very easy and once done, gives you the very familiar Arduino IDE to use as you would any Arduino board.
Once your PC/Mac is set up, we need to connect the module to it. The Huzzah has a very convenient micro USB port that you can use to plug it directly into the computer. If you are using the other types, you will need to use a USB to TTL serial converter, that looks something like this:
This is an RFduino USB Shield that we happened to have with us. What you are looking for is something that converts from USB to serial (TX and RX). ESP-01Once that’s done, you are ready to plug the module in. The connections required for each module type are slightly different. For the 8-pin module, this is how everything is connected up:
Notice the dashed black line! This is connected to GPIO0. This is important because you must connect this only when uploading new code to the module (flashing it). Whenever this pin is connected to ground, it assumes new code is coming in through the TX and RX pins, and goes into flash mode. Once you are done programming, remember to remove that connection! Otherwise the board will get reprogrammed with junk values.
Just to clarify, this is what this diagram will look like once you are done programming and are just running the program.
ESP-12 On this module, you will need to do a few more connections. The above connections are largely the same, with a few extra steps:
Here’s our connected board. There are a lot more connections here because of all the peripherals, but we will get to that soon. For now, just take comfort in the fact that your board is probably not as messy as ours.