ESP8266 programming

There are two main categories of ESP8266 boards: development boards with a USB interface (USB-to-Serial convertor) on-board, and boards without a USB connection.

Development boards with a USB interface

For example: NodeMCU, SparkFun ESP8266 Thing - Dev Board, SparkFun Blynk Board, Adafruit Feather HUZZAH with ESP8266 Wi-Fi ...
  • These boards will show up in Device manager (Windows) or in lsusb (Linux) as soon as you plug them in. In macOS they simply are present in /dev. 
  • They have a 3.3V regulator on-board, and can be programmed over USB directly, so you don't need any external components to get it working.
  • The only thing you may need to do, is solder on some headers.

Bare-bones boards and boards without a USB interface

This category has 2 sub-categories: boards with a 3.3V regulator on-board, and boards with just the ESP8266 and a flash memory chip, without 3.3V regulator. If your board doesn't have a 5V to 3.3V regulator, buy one separately. You could use an LM1117-3.3 for example. The on-board 3.3V regulator of most Arduino boards is not powerful enough to power the ESP.

To program the board, you'll need a USB-to-Serial converter. The FTDI FT232RL is quite popular, because it can switch between 5V and 3.3V. It is essential that the USB-to-Serial converter you buy operates at 3.3V. If you buy a 5V model, you will damage the ESP8266.

Connecting the USB-to-Serial converter

  1. Connect the ground (GND) of the USB-to-Serial converter to the ground of the ESP8266.
  2. Connect the RX-pin of the USB-to-Serial converter to the TXD pin of the ESP8266. (On some boards, it's labelled TX instead of TXD, but it's the same pin.)
  3. Connect the TX-pin of the USB-to-Serial converter to the RXD pin of the ESP8266. (On some boards, it's labelled RX instead of RXD, but it's the same pin.)
  4. If your ESP8266 board has a DTR pin, connect it to the DTR pin of the USB-to-Serial converter. This enables auto-reset when uploading a sketch, more about that later. 

Enabling the chip

If you're using a bare-bone ESP-## board by AI Thinker, you have to add some resistors to turn on the ESP8266, and to select the right boot mode.
  1. Enable the chip by connecting the CH_PD (Chip Power Down, sometimes labeled CH_EN or chip enable) pin to VCC through a 10KΩ resistor.
  2. Disable SD-card boot by connecting GPIO15 to ground through a 10KΩ resistor.
  3. Select normal boot mode by connecting GPIO0 to VCC through a 10KΩ resistor.
  4. Prevent random resets by connecting the RST (reset) pin to VCC through a 10KΩ resistor.
  5. Make sure you don't have anything connected to GPIO2. Read about GPIO2 below.

Adding reset and program buttons

If your ESP8266 board doesn't have a reset button, you could add one by connecting a push button to between the RST pin and ground (GND).
 
To put the chip into programming mode, you have to pull GPIO0 low during startup. That's why we also need a program button. Because it's possible to use GPIO0 as an output, we can't directly short it to ground, that could damage the chip. To prevent this, connect 470Ω resistor in series with the switch. It's important that this resistance is low enough, otherwise, it will be pulled high by the 10KΩ resistor we added in the previous paragraph.

Connecting the power supply

If the ESP8266 module you have doesn't have a 3.3V voltage regulator on board, you have to add one externally. You could use an LM1117-3.3 for example.
  1. Connect the first pin of the regulator to ground.
  2. Place a 10µF capacitor between pin 2 (Vout) and ground. Watch the polarity!
  3. Place a 10µF capacitor between pin 3 (Vin) and ground.
  4. Connect pin 2 to the 3.3V or VCCof the ESP8266.
  5. Connect pin 3 to a 5V power source, a USB port, for example.

VReg.png

ESP8266-2.png

Before you begin ...

There's a few things you have to look out for when using an ESP8266:
  • The most important thing is that it runs at 3.3V, so if you connect it to a 5V power supply, you'll kill it. Unlike some 3.3V Arduino or Teensy boards, the ESP8266's I/O pins are not 5V tolerant, so if you use a 5V USB-to-Serial converter, or 5V sensors etc. you'll blow it up.
  • A second thing to keep in mind is that the ESP8266 can only source or sink 12mA per output pin, compared to 20-40mA for most Arduinos.
  • The ESP8266 has one analog to digital converter, but it has a strange voltage range: 0 - 1V, voltages above 1V might damage the board.
 
One last thing to keep in mind is that the ESP8266 has to share the system resources and CPU time between your sketch and the Wi-Fi driver. Also, features like PWM, interrupts or I²C are emulated in software, most Arduinos on the other hand, have dedicated hardware parts for these tasks. For most applications however, this is not too much of an issue.