Intro to IoT with the ESP8266 microcontroller board

Today we want to give you an introduction to a new module that has gotten a lot of attention in the IoT community lately. It doesn’t have a sexy name like the Particle Cores, Espruinos, LightBlue Beans and all the others out there. The name is simply ESP8266. Anyone exploring IoT components these days has probably run into one of the ESP8266 modules.
The first time I came across this little module was in August 2014 on the hackaday blog . Back then it seemed to be more of a cheap alternative to existing WiFi modules for Arduinos with a price tag of under $5, compared to the Arduino WiFi shields that run around $40. The SDK for the SoC of this module was not very mature and most of the documentation was available in Chinese language only. The only usable firmware supported AT commands.
But luckily a lot has changed since then. There are now more than 12 different variations of the ESP8266 available, multiple Firmwares, many projects are using it and it’s becoming more and more popular every day. With this post we want to give an overview on this.

 

Available module variants

ESP-01

ESP-01

  • Dimensions: 14.3mm x 24.8mm
  • PCB antenna
  • GPIO0/2/16
  • Very common module

 

ESP-02

ESP-02

  • Dimensions: 14.2mm x 14.7mm
  • U-FL connector
  • GPIO0/2/15
ESP-03

ESP-03

  • Dimensions: 17.4mm x 12.2mm
  • Ceramic antenna
  • GPIO0/2/12/13/14/15/16
  • Very common module
ESP-04

ESP-04

  • Dimensions: 14.7mm x 12.1mm
  • No antenna
  • GPIO0/2/12/13/14/15/16
ESP-05

ESP-05

  • Dimensions: 14.2mm x 14.2mm
  • U-FL connector
  • No GPIO
ESP-06

ESP-06

  • Dimensions: 14.2mm x 14.7mm
  • No antenna
  • GPIO0/2/12/13/14/15/16
  • Metal shield claims FCC
ESP-07

ESP-07

  • Dimensions: 22mm x 16mm
  • Ceramic Antenna & U-FL connector
  • GPIO0/2/4/5/12/13/14/15/16
  • Metal shield claims FCC

 

ESP-08

ESP-08

  • Dimensions: 17mm x 16mm
  • No antenna
  • GPIO0/2/12/13/14/15/16
  • Metal shield claims FCC
ESP-09

ESP-09

  • Dimensions: 10mm x 10mm
  • No antenna
  • GPIO0/2/12/13/14/1

 

ESP-10

ESP-10

  • Dimensions: 14.2mm x 10mm
  • No antenna
  • No GPIO
ESP-11

ESP-11

  • Dimensions: 19.3mm x 13mm
  • Ceramic antenna
  • GPIO0/1
ESP-12

ESP-12

  • Dimensions: 24mm x 16mm
  • PCB antenna
  • ADC + GPIO0/2/4/5/12/13/14/15/16
  • Very common module
  • Metal shield claims FCC

Here are some modules we rarely see being used, but we want to mention them here for completion.

WROOM-01

WROOM-01

  • GPIO0/2/4/5/12/13/14/15/16
WROOM-02 / ESP-13

WROOM-02 / ESP-13

  • GPIO0/2/4/5/12/13/14/15/16

 

ESP8266 ESP-12 wiring

In our exploration of the ESP8266 we have mostly focused on the ESP-12. We had a bunch of ESP-01 and ESP-12 available that we got off of AliExpress, but ESP-12 was mainly chosen because it has more GPIO pins.
The wiring for flashing a new firmware is pretty straight forward. In addition to connecting the VCC and GND you need to pull up the CH_PD and GPIO02 and pull down the pins GPIO0 and GPIO15. After running into unstable behavior of the module, we decided to add a dedicated power supply to have a constant current. The last missing part to flashing a new firmware is an FTDI USB-serial adapter. Connect the TX to RX, RX to TX and the GND. We don’t need the VCC since we already have a power supply. With the wiring as shown below, we should be ready to get our firmware on the ESP8266.

Wiring of ESP8266 ESP-12

Wiring of ESP8266 ESP-12

 

Available Firmwares

Espressif’s Official Firmware

The official firmware from Espressif gives you the best performance and control of your implementations with more memory available for code than the others below. There are many projects using this firmware, the most popular is probably esp_mqtt. The downside with this firmware though, is that you have set up a full toolchain on your development machine which can take some time. Even though some of the libraries were not open sourced there are very frequent releases at the moment. This helped us to get the ESP8266 connected to the hybris-as-a-Service offering over HTTPS as the older firmwares have a broken SSL library.

NodeMCU

The NodeMCU firmware was initially released at the end of 2014 and allows you to write your application code in Lua. This firmware is also very popular and allows quick prototyping. Unfortunately the NodeMCU is based on an older version of the official firmware. Due to memory restrictions this base can’t easily be upgraded as the remaining memory for custom code would be too low to do any serious coding. This also means that the recent fixes made to the SSL libraries etc. are not available in NodeMCU.

Frankenstein

This Firmware, as the name suggests, consists mostly of different bits and pieces that are publicly available. It is meant mainly as an alternative to an AT Firmware and has a limited control of GPIOs.

Sming

An open source and native firmware that allows you to work with GPIO in Arduino style. Comes with great built-in modules but is also compatible with Arduino libraries. But unfortunately based on an older version of the official firmware.

 

Other firmware projects in progress

Micro Python Port for ESP8266

  • highly experimental
  • Python REPL over UART0
  • Garbage collector

Espruino Port for ESP8266

  • Port of Espruino JavaScript engine
  • Slow progress

 

Toolchain set up on Mac OS X Yosemite

As mentioned above we would need to set up the toolchain in order to be able to compile the firmware and flash the ESP8266. In the following walk-through we’ll assume you have the drivers installed for the FTDI USB serial adapter. In most cases it should be pretty straight forward.

 

Essentials

First we need to install some essential tools that we would need to build the toolchain. We are mostly using homebrew to install additional software but you will also find same packages on MacPorts.

 

Toolchain and SDK

In the next step we need to create a case-sensitive filesystem, clone the sep-open-sdk repository and build it.

Once we have a successful build we need to add the toolchain path to our environment. Edit your profile with

and add this at the bottom

Don’t forget to reload your terminal

 

Flashtool

The last missing piece for the setup is a tool for flashing the compiled firmware onto the ESP8266. We’ve used ESPTool in most cases. It’s using a Python library PySerial that you can install with pip.

For the ESPTool itself you can simply git clone the repository and

 

First build

To verify that we set up the toolchain correctly we can compile a sample project. As I mentioned above, esp_mqtt is a very popular project. So let’s just compile that.

Now we can compile our own projects, too. It would be cool to integrate the toolchain into an IDE. We would have code highlighting, code completion and would also be able to build and flash the firmware in one single tool.

 

Eclipse set up

Download Eclipse IDE for C/C++ Developers and install it. Once done, you can import the esp_mqtt project into Eclipse as shown on the screens below.

To allow building and flashing of the firmware we can simply add the make targets (all, clean, flash) on the rights as shown here.

One last important part is still missing. We need to add the PATH variable to Eclipse to help it find the toolchain. Add in the Preferences under C/C++ → Build→ Environment a PATH variable with Value /esptools/esp-open-sdk/xtensa-lx106-elf/bin and we should be ready to develop our application.

 

First request to YaaS

We had successfully used MQTT with the ESP8266, but the upcoming hybris-as-a-Service platform yaaS is following the micro services architecture and is all RESTful Webservices over SSL. As mentioned earlier the SSL libraries were broken in earlier versions of the SDK. The latest official SDK though has proper SSL support. We got the ESP8266 to talk to yaaS with the sample code from Espressif. Just configure the WiFi SSID and password in the user_set_station_config function. Replace at the top the NET_DOMAIN and TLSHEAD with your server address and HTTP request.

Compile and flash the firmware onto the ESP8266. Restart the ESP8266 module to let it run your custom code that we flashed.

There it is! The ESP8266 got it’s first token from yaaS!

2 thoughts on “Intro to IoT with the ESP8266 microcontroller board

Comments are closed.