Computing stuff tied to the physical world

Meet the esp8266

by Thorsten von Eicken

The ESP8266EX System-On-a-Chip (SoC) was introduced by Espressif Systems at the end of 2013 and has started to gain the attention of open-source IoT hobbyists during the second half of 2014 as more and more software and documentation became freely available and hardware modules also became readily available. There are many sources of information about the esp8266, including a good 1-page overview at nurdspace, the ESP8266 community forum, and the official Espressif documentation. The relevant features of the esp8266 for this project are:

  • 32-bit processor running at 80Mhz providing enough oomph to manage WiFi encryption as well as SSL for higher-level protocols
  • an integrated WiFi radio supporting 11b, 11g, and 11n modulations
  • 80 KB of RAM: enough to buffer a good amount of data which is essential to support internet communication protocols
  • a built-in UART (actually two) which makes connecting to a JeeNode or Arduino easy
  • a number of GPIO (general purpose I/O pins) that can be controlled to reset an attached microcontroller and initiate a flash upload
  • a 512KB flash program and data memory, which allows for interesting firmware to be written and programmed into the esp module

Technically speaking, the ESP8266EX is just one chip that includes all of the above except for the flash memory. The chip comes in a tiny QFN package that is hard to work with by hand, but fortunately a number of small modules are available that integrate the ESP8266EX SoC with a flash chip and a few required additional components such as a crystal, capacitors and resistors. Of the available modules the one that fits most nicely into the JeeNode form factor is the esp-03:

DSC 5134

(from left to right: original RFM12B, RFM69CW, esp-03)

In addition to the tiny form factor, the esp-03 module has a ceramic antenna and enough I/O pins to drive the AVR or ARM reset and ISP pins, to output the UART TX and RX, and to drive a couple of indicator LEDs so one can tell whether things are working or not. On the software side there are a number of options for programming the esp8266. The excellent NodeMCU firmware provides a Lua interpreter and is the easiest to get started with. An early attempt to use it for this project failed due to a combination of bugs in the networking code used by NodeMCU at the time (not the project’s fault) and the lack of flash space left after loading NodeMCU itself.

This lead to the lower-level C/C++ programming environments that all consist of a networking stack built on common open-source projects, including LwIP, net80211, wpa_supplicant, and a multi-tasking “kernel” consisting of FreeRTOS.

But the packaging of all this varies. Espressif provides an official SDK which has binary, non-open-sourced versions of most of the above software stack plus a rapidly growing custom library that adds functionality useful to manage WiFi in particular. The Espressif library is not open source and writing against it is not very portable to any other device.

An alternative is the more open esp_iot_rtos_sdk, which exposes FreeRTOS and LwIP more fully. Unfortunately this library does not include all the helpful functions that are available in the standard SDK. Another alternative is to use one of the reverse engineered software stacks but they also lack the proprietary library’s value added features.

In the end, using the Espressif standard SDK seemed like the safest approach and the fact that it has been updated by Espressif at a rapid pace to fix issues and add new functionality makes it look like the right decision at this time.

The esp-bridge

The goal of the esp-bridge is to use the above pieces and deliver some simple core functionality, acting as a TCP-serial bridge. The two main use cases are:

  • In order to debug and troubleshoot a JeeNode the user opens a terminal client and points it at the telnet port (23) of the esp-bridge . The user is then connected transparently to the JeeNode’s AVR processor through the UART: everything printed by the AVR is printed in the terminal and anything typed by the user is transmitted to the AVR.
  • In order to reprogram a JeeNode the user points avrdude (the software used to program AVR processors) to the same telnet port 23 of the esp-bridge. The esp-bridge’s software recognizes the reprogramming attempt and toggles the JeeNode’s reset line in time for the bootloader to enter programming mode.

While this is sufficient to use the esp-bridge it turns out to be insufficient to bootstrap it in the first place. In many ways tackling the esp-bridge configuration problem turns out to be much more complex than making the TCP-serial bridge function work.

From an ease-of-use point of view the best approach for bootstrapping the esp-bridge is to add a web interface. Of course this catapults the complexity of the esp-bridge’s software to a whole different level!

In the end, the requirements for the esp-bridge grew to the following:

  • A small PCB with an esp-03 module and the relevant pins hooked up to an FTDI connector that is ready to mate with a JeeNode, or other Arduino, or the Tinker Pico LPC824 introduced on the weblog a few weeks ago.
  • Firmware for the esp8266 that implements a transparent TCP-serial bridge that can be used to watch the JeeNode’s output and also reprogram it using avrdude (or the same functions for one of the LCP800 series or other ARM processors).
  • More firmware to provide a web interface so the esp-bridge can be configured with WiFi parameters and serial port parameters.

Next, we’ll start with the hardware, more specifically, the circuit that houses the esp8266 module and hooks it up to an FTDI connector.

[Back to article index]