August 24, 2018

The ESP8266 -- an introduction

The ESP8266 is a remarkable little chip, made in China and available in abundance for extremely low prices. It is the heart of many IoT (internet of things) projects because it offers WiFi connectivity. However, I find it to be an entirely useful and economical controller all on its own if you want to just turn off the Wifi section.

Many people think of it as a Wifi "add-on" for other projects, which I think is a big mistake. It can certainly be that, but is absolutely useful as a self contained microcontroller with or without Wifi.

I used to have an extensive set of notes on working with the ESP8266, but they were lost when the machine holding my website had a disk crash. I hope to redo them someday in a better form if I ever stop playing with ARM processors and go back to finish up some of my ESP8266 projects.

What to buy

My strong recommendation is to purchase some "NodeMCU" modules on AliExpress. These sell for about $3.50 (which includes shipping). You get a nice little board with the ESP8266 module, a USB to serial chip, and a built in 3.3 volt power supply so you can run the whole thing from the USB cable (which also serves as a serial console).

If you start wanting to run things from a battery, you will want to ditch the USB to serial chip and LED's and just run a bare module. You will need to give it 3.3 volts somehow, and you will need an independent USB to serial converter for debuggin and to load software. Go buy some ESP-12E modules on AliExpress. They typically sell for about $1.70.

You will wait for 2-3 weeks when ordering via AliExpress direct from China. I order in batches of 10 and am delighted that I can get 10 of these things for less than a miserable AVR controller board.

Software development options

Developing code in C using the SDK is remarkably pleasant and entirely appropriate for a device like this. I have worked up a number of projects, which you will find on my Github page. You can also find my Lua projects there as well, but you need to recognize that my experiences with Lua did not end well.

You can use the infamous "Arduino" GUI to develop code for the ESP8266, but this involves you in some horrid half baked IDE, along with some mongrel dialect of C++ they call "Sketches". I found nothing to interest me here and did not waste any of my time.

Long ago, I played around for a while with Lua and NodeMCU, but quickly discovered that the NodeMCU developers had used up almost all of memory for NodeMCU, leaving nothing for the end user. Fun for them, but not much use to somebody like me. I was unable even to load and run simple demos. Cryptic error messages indicated that there was insufficient memory. I gave up in disgust.
I was contacted in 2018 by one of the developers (Terry Ellison) who told me that the situation has changed significantly:

The current Github master typically leaves around 44Kb heap at boot. I am one of the core developers, and I have just added a patch (which is included in dev) that extends the NodeMCU Lua VM to support a modified Harvard architecture where Lua code and string constants can be moved to a Lua Flash Store (LFS), and this gives you around 256Kb for Lua code and strings, and 48Kb RAM. More than enough for most IoT applications :-)
This new situation would make taking another look at NodeMCU/Lua worthwhile.

Disassembling the bootrom

The ESP8266 has a bootrom in immutable mask rom in the chip. This is easy enough to read out and I spent some time disassembling it and annotating the resulting disassembly

The ESP32

A "big brother" (the ESP32) was announced in 2016, but has been in short supply and is significantly more expensive than the ESP8266. I have mostly lost interest in it, but I have some information here for those that are interested.