---
title: ESP8266 Wi-Fi Module with Teensy and Arduino
date: 2014-12-02T21:29:39+00:00
modified: 2014-12-02T22:14:13+00:00
image:: https://kaspars.net/wp-content/uploads/2014/12/esp8266-pinout.jpg
permalink: https://kaspars.net/blog/esp8266-teensy-arduino
post_type: post
author:
  name: Kaspars
  avatar: https://reverse.kaspars.net/gravatar/avatar/92bfcd3a8c3a21a033a6484d32c25a40b113ec6891f674336081513d5c98ef76?s=96&d=mm&r=g
category:
  - Electronics
post_tag:
  - ESP8266
---

# ESP8266 Wi-Fi Module with Teensy and Arduino

Recently I ordered two [Espressif ESP8266](https://espressif.com/en/products/esp8266/) breakout modules labeled “ESP8266 Version 01” from [hermann\_shopp on ebay](http://www.ebay.co.uk/itm/321588117662). It is one of the coolest little chips for makers to have these days — it connects to the internet, has an [open SDK with complete toolchain](https://github.com/pfalcon/esp-open-sdk), multiple third-party firmware options such as [Micro Python](https://github.com/micropython/micropython/tree/master/esp8266) and [NodeMcu (LUA)](https://github.com/nodemcu/nodemcu-firmware). Even [Hackaday loves it](http://hackaday.com/tag/esp8266/).

Here is a quick overview of what I have learned so far.

## ESP8266 Breakout Module Pinout

There are [multiple breakout modules](https://github.com/esp8266/esp8266-wiki/wiki/Hardware_versions) available for this chip. Here is the pinout for the version (possibly ESP-01) that I got:

![ESP8266 module pinout](https://kaspars.net/wp-content/uploads/2014/12/esp8266-pinout.jpg?strip=all&quality=90&resize=800,379)

- **TX** (UART TX)
- **RX** (UART RX)
- **CH\_PD** (chip power down, should be pulled high to start the chip)
- **RST** (reset)
- **GPIO0** and **GPIO2** (general purpose input/output pins)
- **VCC** (power supply 3.3V, [max. ~300mA](http://wiki.iteadstudio.com/ESP8266_Serial_WIFI_Module))
- **GND**

Please note that ESP8266 requires 3.3V power supply and a lot of current (up to 300mA) during wireless transmission. I used two AA batteries in series to power the module.

Secondly, remember that UART pins are marked with respect to the device itself, therefore `TX` pin from the module should be conntected to the `RX` pin on Arduino, like so:

```
TX (ESP8266) to RX (Arduino)
RX (ESP8266) to TX (Arduino)

```

## Interfacing with ESP8266

The default serial baud rate for talking to these modules is `9600` while most of the other guides online tell you that the baud rate is `115200`. It depends on the firmware so be sure to try out different baud rates. A good indication of correct wiring and incorrect baud rate is when you see garbled text returned from the module in the serial monitor.

I decided to use the awesome [Teensy 3.1](https://www.pjrc.com/teensy/teensy31.html) to talk to ESP8266 since I no longer had my USB-to-UART cable available. The idea is to have a very simple program on Teensy that relays all the Serial data from the module attached to `Serial1` pins RX1 (pin 0) and TX1 (pin 1) to the `Serial` interface that Teensy uses for communicating with your computer:

![ESP8266 with Teensy 3.1 (Arduino)](https://kaspars.net/wp-content/uploads/2014/12/esp8266-teensy-arduino.jpg?strip=all&quality=90&resize=600,792)

Using the following Arduino sketch we’re able to use almost any Arduino-compatible microcontroller that supports UART and serial interface as an UART-to-USB module for communicating with ESP8266 instead of an FTDI chip.

We simply pipe all bytes from ESP8266 connected at `Serial1` (note the `1` at the end) interface to `Serial` which is available from the Arduino serial port monitor.

```
void setup() {

    // Setup computer to Arduino serial
    Serial.begin(9600);

    // Setup Arduino to ESP8266 serial
    // Use baud rate 115200 during firmware update
    Serial1.begin(9600);

}

void loop() {

    // Send bytes from ESP8266 to computer
    if ( Serial1.available() ) {
        Serial.write( Serial1.read() );
    }

    // Send bytes from computer back to ESP8266
    if ( Serial.available() ) {
        Serial1.write( Serial.read() );
    }

}

```

Once everything is wired up correctly you should see the following message in the Arduino serial monitor sent by the module during the boot process:

![ESP8266 output on Arduino serial monitor from Teensy 3.1](https://kaspars.net/wp-content/uploads/2014/12/esp8266-arduino-serial-monitor.png?strip=all&quality=90&resize=571,317)

```
[Vendor:www.ai-thinker.com Version:0.9.2.4]

ready

```

Now you are able to interact with the module using <a>a set of AT commands</a>. Here is the version information as reported by `AT+GMR`:

```
AT+GMR
0018000902-AI03

OK

```

where `0018` is supposedly the SDK version and `000902` is the AT version. I have no idea what `AI03` stands for.

## Firmware Updates

ESP8266 supports firmware updates over the same serial interface with a few changes to the setup — you need to pull the `GPIO0` pin to ground and use a 115200 baud rate from Teensy to the module.

There are several tools available for updating the firmware:

- Windows only [ESP8266 Flash Downloader](http://blog.electrodragon.com/cloud-updating-your-wi07c-esp8266-now/) and
- Cross-platform [esptool](https://github.com/themadinventor/esptool) (Python)

The [protocol for uploading the firmware binaries](https://github.com/themadinventor/esptool#protocol) is well known:

> The bootloader protocol uses SLIP framing. Each packet begin and end with 0xC0, all occurrences of 0xC0 and 0xDB inside the packet are replaced with 0xDB 0xDC and 0xDB 0xDD, respectively.
> 
> Inside the frame, the packet consists of a header and a variable-length body. All multi-byte fields are little-endian.

### Cloud Updates

Espressif has enabled [over-the-air updates for all chips with firmware version greater than 00170901](http://blog.electrodragon.com/cloud-updating-your-wi07c-esp8266-now/). Make sure your module is running this firmware version by executing the `AT+GMR` command before trying to do the cloud update.