Programming an ESP-8266 with FTDI Programmer

The ESP-8266 is one of my best findings of 2015. I wanted to experiment a bit with what’s called the Internet of Things (IoT). It obviously involved connecting my projects to the Internet, so I looked for a wifi module that I could use with one of my ATtiny microcontrollers to push data to the Internet. On eBay, I found an ESP-01 module, for around 2 USD, so I couldn’t help but order one!

ESP-01-alone

By default, the ESP-8266 firmware expects you to send it AT commands via serial communication. This is not as obvious as it sounds when we try to do this with ATtinys because they don’t have hardware serial communication support. I tried the SoftwareSerial library but it was unreliable because the ESP-8266 requires a communication speed of 115,200 bauds by defaults. To change the ESP-01 baud rate, I had to upload a new firmware on it.

While I was looking for another firmware, I stumbled on something that looked very promising. Some people worked at supporting the ESP-8266 in the Arduino IDE. So, that meant I could simply program my ESP-8266 with the business logic that I would usually put in an ATtiny and that it could all be done using the Arduino IDE and librairies I already know!

If you are wondering why I used an ESP-01 instead of creating my own board with an ESP8266 chip, well it’s because soldering an ESP-8266 micro controller is not an obvious task because of its form factor (the pins are very small). But, luckily, there are a lot of different pre-built boards available for us to use. In my case, I’m using the ESP-01 but there are larger boards if you need to use more than 2 IO pins.

ESP-01-both-sides

ESP-01 Specifications

The ESP-8266 is having the following specifications:
Maximum voltage of 3.6V
– 32 bits RISC CPU running at 80 MHz
– 64KB of program space
– 96KB of RAM
– Support for 802.11 b/g/n wifi (including WEP & WPA/WPA2 authentication)
– 16 IO pins (but the ESP-01 makes only 2 of them available)

ESP-01-Pinout

Setting up Arduino IDE (v1.6.6) to support ESP-8266

– Launch Arduino IDE
– Open Arduino | Preferences menu option
– In the Preferences window, add the following to the Additional Boards Manager URLs field:

https://arduino.esp8266.com/stable/package_esp8266com_index.json.

If there’s already another URL in that field, simply put a comma between them.
– Press the OK button.
– Close and restart your Arduino IDE (that’s a work around for a bug in the IDE version I use).
– Open Tools | Board | Boards Manager… menu option
– Scroll until you find the entry named: esp8266 and click the entry
– Press the Install button
– Close that window

That’s it, you should now see the ESP-8266 as part of the board options in the Tools | Board menu!

Programming an ESP-01

Once my IDE was ready to program my ESP-01 module, the next step was to figure out how to physically connect that module to my computer to download a new firmware on it.

Breadboard adapter

Because the pins are in 2X4 format, you can’t simply connect the ESP-01 on a breadboard to program it.
ESP-01-pins
To work around that issue, I made a small adapter using some proto-board and headers.

ESP-01-Breadboard-adapter

Wiring FTDI programmer and ESP8266

Then, it was just a question of wiring my FTDI programmer to the breadboard in the following way:

FTDI-to-ESP8266-Wiring

Important Note: Set the FTDI programmer jumper to 3.3V to be compatible with the ESP8266!

FTDI        ESP-01
VCC     VCC
VCC     CH_PD
GND     GND
GND     GPIO0 
RXD     TX
TXD     RX

Note: The GPIO0 pin is pulled to ground to tell the ESP8266 that we want to program the firmware. It should be pulled to VCC the rest of the time.

Uploading the blink program

The last step was to make sure I was able to upload a program to the ESP-01 board. In the Arduino IDE, I loaded the Blink example (using File | Examples | 01.Basics | Blink menu option).

This code doesn’t work as is. We have to fix it so it uses one of the ESP-01 output pins. Lets assume we will use GPIO2. That means that we have to replace all references to pin 13 by a constant to GPIO2 pin number:

// Connect LED to GPIO2 pin
static const int LED_PIN = 2;

void setup() {
  pinMode(LED_PIN, OUTPUT);
}

void loop() {
  digitalWrite(LED_PIN, HIGH);   
  delay(1000);              
  digitalWrite(LED_PIN, LOW);    
  delay(1000);              
}

In the Tools menu, make sure you select the following values (the programmer doesn’t matter):

esp8266 - ArduinoIDE menu

Then, press the upload button. It should upload the firmware to your ESP-01 module.

Validate that the blink program works

Rewire your breadboard like this:

FTDI-ESP8266-Blink_bb

The LED should start blinking as expected.

I know this is a very simple example but it opens the door to a lot of possibilities!
My next post will explain how I used the ESP-8266 + a DHT-11 sensor to read my room temperature/humidity and send it to thingspeak.com to create graphs.

Leave a Reply

Your email address will not be published. Required fields are marked *

Comments Protected by WP-SpamShield Spam Plugin