NodeMCU and other ESP8266 modules are starting to become very popular because they offer an embedded development platform with a CPU+RAM+Storage+WiFi all in one for (considerably) less than the price of an Arduino. There are a number of breadboard-friendly modules with all pins exposed (and more coming soon.)
However, this post is about the breadboard-unfriendly ESP-01 module. It only has two GPIO pins (four if you include the TX & RX pins), but it's smaller and most importantly, cheaper.
US vendors tend to charge around $7, but if you don't mind importing, they can be had for $3.50 or less.
The biggest problem with the ESP-01 is that it's annoying to wire up and program, so that's what we're solving today.
Parts
- ESP-01 module: The reason were going through all this trouble. $3.50 @ Electrodragon
USB-Serial TTL programmer: I'm using an Adafruit FTDI Friend, although I'm hesitant to recommend FTDI products after they shipped mallware with their Windows drivers... $14.75 @ Adafruit.
Update: I've confirmed that a CP2102 USB-TLL UART also works well on OS X: $2.20 @ Electrodragon. You can either use the included cable, or switch the pin headers on the motherboard to female for a direct connection. (All relevant pins are in the same position.)
- 3.3v Voltage Regulator: Needs to be a slightly beefy one because the ESP8266EX chips can reportedly draw as much as 350-400mA. I'm using a LM2937ET-3.3/NOPB from TI. $1.61 @ Texas Instruments (Or request a free sample)
- 10 μF Capacitor: For the 3.3v side of the voltage regulator. $0.02 each @ Tayda Electronics or $3.30 for a 120-piece kit @ Electrodragon
- 0.1 μF Capacitor: (100nf) For the vin/5v side of the voltage regulator. $0.02 each @ Tayda Electronics (Or use the 0.2uf Capacitor from the aforementioned Electrodragon kit
- Two Buttons: SPST (Single Pole, Single Throw) momentary on switches. I'm using Omron B3F buttons. $0.04 each @ Tayda Electronics or $1.20 for 50 @ Electrodragon
- 10k Ω Resistor: Pull-up for the Reset button. (Note: depending on your usage, your may also want a second one for the Program button on
GPIO 0
.) $0.10 for 10 @ Tayda Electronics or $0.90 for 100 @ Electrodragon or $3 for a 600-piece kit @ Electrodragon - 1k Ω Resistor: Pull-up for the
CH_PD
pin that enables the ESP-01 module. $0.10 for 10 @ Tayda Electronics or $0.90 for 100 @ Electrodragon or the aforementioned $3 600-piece kit @ Electrodragon - 2x4 Female Pin Headers: For connecting the ESP-01 module. (I'm not even sure where to buy these, I think mine was a free sample from Samtec that was leftover from a different project. Nobody will look down on you if you just break off two 1x4 pieces of single-row pin headers and solder them side-by-side ;)
- Male and Female Breakaway Pin Headers: For connecting USB-Serial TTL programmer and connecting to the GPIO pins. $0.90 (male) & $1.70 (female) @ Electrodragon + $1.40 (male, right-angle - optional) @ Electrodragon
- Stripboard: The "board" part of our motherboard. $0.66 @ Tayda Electronics
- Misc Wire: A few short pieces of wire, probably less than 2 inches total. $0.10 per foot @ Tayda Electronics or $1.60 for 10 meters @ Electrodragon
- Brass Spacers: Optional but keeps the board from potentially shorting out on your desk/whatever. $0.90 for 10 @ Electrodragon
Total cost: ~$12 + shipping to go with the cheapest options. Be aware that Tayda Electronics has a minimum order of $5, so with that and shipping you'll probably have to spend $20-25 to get everything.
Tools
- Soldering Iron & Solder: I recently upgraded to a Weller WESD51 and I am loving it.
- Flush Cutters: To cut the leads off after soldering each part in. These are also handy for "breakaway" female pin headers.
- Wire Strippers: For cutting and stripping the few bits of wire we need.
- X-Acto Knife: Necessary for cutting the stripboard track between the two rows of pins on the ESP-01 module, and a fallback option for the other cuts.
- Drill w/ 4mm drill bit: Makes all of the other stripboard cuts much easier. Just position the drill in the center of an unused pin hole and spin it for a few moments to strip away the copper.
Building
(Fritzing .fzz file, uses Yan Donelly's ESP-01 Fritzing part)
Connect everything as shown in the diagram. Be sure to cut the stripboard tracks between the two rows of pins where the ESP-01 connects.
(And the other locations - the CH_PD
track and a few on either side of the power tracks - but you can see each of those cuts in the graphic.)
I changed the spacing a bit when I assembled mine to give my fingers more room to connect and disconnect things from the pin headers.
Programing
There are a few ways to program the ESP-8266, but my favorite is to use the Arduino IDE with the ESP8266 board from esp8266.com. Adafruit has a nice guide for installing it.
When uploading your sketch, you have to be a little carefule about the order and timing of the button presses:
- Click upload in the Arduino IDE
- Quickly press and hold the RESET button (the one farther from the ESP-01)
- Quickly press and hold the PROGRAM button
- Watch the status line in the Arduino IDE. When it changes from "Compiling..." to "Uploading..." release the RESET button
- After you see it starting to print the upload status in red text, release the PROGRAM button.
Here's an example sketch to use PROGRAM button on GPIO 0
as a regular input:
const int buttonPin = 0;
void setup() {
Serial.begin(9600);
// Normally the button will take the pin from "floating" (not connected to anything) to grounded
// This enables the internal pullup resistor so that the default state is high rather than floating.
pinMode(buttonPin, INPUT_PULLUP);
}
void loop() {
Serial.print("Button is ");
int status = digitalRead(buttonPin);
// because of the pullup resistor, the pin state is reversed: button pressed = LOW, button released = HIGH
if (status == LOW) {
Serial.println("pressed");
} else {
Serial.println("released");
}
delay(500);
}
Happy hacking! Discuss on esp8266.com.