How to program the ESP8266 from an Arduino Uno

After playing around with my ESP8266 (ESP-01) for a while by just using the serial AT-commands and as a peripheral from my Arduino Uno, I wanted to try out the built-in GPIO pins and use the ESP-module as a standalone microcontroller.

A simple google search revealed plenty of tutorials on how to do it but almost all of them used some kind of USB to serial converter. I don’t own any dedicated USB to serial converter but hey, my Arduino can do anything! And it’s actually quite simple. I use the ESP-01 version of the WiFi-module but the process should be identical for other ESP8266 modules aswell.

Preparing the Arduino IDE

To install the board start the Arduino IDE and go to File > Preferences and add the following link under “Additional Boards Manager URLs”.

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

Now go to Tools > Board: “[current board]” > Boards Manager… where you can search for “esp8266” and click install on the esp8266 by ESP8266 Community.

You should now see some extra boards from Tools > Board: “[current board]”. Since I have the ESP-01 module and no fancy breakout board I select the “Generic ESP8266 Module”.

Connecting the pins on the ESP8266

First of all the ESP8266 needs to get powered. VCC to 3.3 V and GND to GND. The ESP8266 and the Arduino need to have a common ground for signal reference purposes. Be carefull not to give it to high voltage (i.e. not 5 V). The ESP8266 can draw a significant amount of current. More than the Arduino is rated for so it is recommended to use a separate power supply. However I use the 3.3 V power from the arduino with a 470 μF capacitor between 3.3 V and GND to absorb some of the current spikes. This works fine for me but do it at your own risk.

CH_PD needs to be pulled high to enable the chip so just connect it to VCC/3.3 V.

When it comes to the RX and TX pins there are a few things to say. First of all the Arduino outputs 5 V and the ESP8266 wants 3.3 V. I just connect the RX from the Arduino to the TX of the ESP8266 and feed it 5 V signals. It works fine for me but it might damage the ESP8266 so do it at your own risk. If you want to be careful the correct way is pretty easy aswell. To do it the correct way take three resistors of a value between roughly 1 kΩ and 10  kΩ. The important thing is that they have equal values. Connect the resistors in series between RX on the Arduino and GND. Between the first and second resistor the signal should be 3.333 V which is close enough so connect that node to RX on the ESP8266. Arduino can receive 3.3 V signals so just connect TX to TX.

But shouldn’t RX go to TX and vice versa? Normally yes, but not in this case. If you want to know why continue reading, otherwise you can skip to the next paragraph. The RX from the ESP8266 needs to go to the TX on the USB interface on the Ardunio. The labels however are for the ATmega328. Since the USB interface is used to communicate with the ATmega328 the TX of the USB interface is connected to the pin named RX on the Arduino board. If it sounds complicated just have a look at the picture below. RX on the ESP8266 should go to the TX on the USB interface and vice versa.

path5393
TX on the ESP8266 connects to RX on the USB interface by connecting it to TX on the Arduino (green connection). Labels on the Arduino is for the ATmega328, not the USB interface.

To get the ESP8266 into programming mode GPIO0 need to be pulled down to GND while resetting the chip. So connect wires to GPIO0 and RST that you can easily touch to GND. But leave them unconnected (floating) for now.

To sum up the connections should now be as in the table below.

ESP8266 pin Connected to
VCC 3.3 V of your choise
GND Common GND with the Arduino
CH_PD VCC/3.3 V
RX RX on the Arduino (direct or through a voltage divider)
TX TX on the Arduino
GPIO0 Loose wire
RST Loose wire

Connecting the pins on the Arduino

Most of the connections on the Arduino is between the ESP8266 and the Arduino and they are already discussed above. The only connection made on the Arduino board itself is to connect RESET to GND. This will continuously reset the ATmega328 which means it will never start and it will not interfere with the serial communication.

When everything is connected it should look something like this:

 

easy connections_bb2
The Arduino Uno and the ESP8266 all wired up.

 

Uploading a sketch

When installing the new boards some new example sketches are included, specifically for the ESP8266. To upload one of these or one of your own sketches do the following steps.

  1. Connect the wire from GPIO0 to GND
  2. Touch the wire from the RST momentarily to GND. These two steps will restart the ESP8266 into programming mode.
  3. Press upload in the Arduino IDE

After the sketch has compiled it should start uploading to the ESP8266 as in the image below. If it didn’t work try resetting the ESP8266 again. If it still don’t work check the power supply to the ESP8266. The power is a common bug source on this module.

ESP8266_uploading
Arduino IDE is uploading a sketch to the ESP8266.

One thought on “How to program the ESP8266 from an Arduino Uno

Add yours

Leave a comment

Website Built with WordPress.com.

Up ↑