2015-03-24

Like many others in the Maker Community I've spent a lot of time playing with the dirt cheap ESP8266 wifi chip. It is the cheapest way to add wifi to your project and it's easy to get hold of. My hope was that it would be solid enough that I could use it to build permanent installations and fun Internet Of Things (IoT) devices with it, but the darn thing keeps crashing. I've been testing it since the 0.91 firmware and all the way up to the current 1.0 version and it's not possible to keep it running for a prolonged period of time.

I've spent maybe a weeks worth of time getting it to not crash at random intervals, so I thought I'd share my experiences and lessons learned in case others find it useful. For solid details on the hardware/software side, forget the official datasheets. They're poorly written, outdated and lacks detail. Instead, check the ESP8266 wiki that explains a lot more.

Setting up for development

To communicate with the ESP, you could hook it up to a microcontroller and update it via serial input, but I recommend use the ESPlorer software (java) and getting a USB to Serial converter. Note that some of the cheapest of these converters on Ebay use clone IC's, so your milage may vary. It's always safe to pick up a proper one from Adafruit or a well known source. Also, make sure you power the ESP from a 3.3V power source such as a LM1117. The Serial pins (RX/TX) are supposedly 5V tolerant, but the power must be 3.3V or you fry the chip.

There's many guides to hooking up the various development boards, so I won't detail that part, but lets look at the software side of things! When you buy the ESP-01 breakout boards from ebay, you never know what version of the firmware it comes with. Most likely it will be an old one so you'll most likely want to update it. But - what firmware should you use?

NodeMCU

This seems to be the most stable firmware you can currently use. NodeMCU is a firmware that adds a LUA layer on top of the (somewhat stable) 0.95 Espressif SDK. As for alternative firmware's, this is also the one that is the easiest to get started with. It is well documented and offers good tools. Rui Santos has a great guide for hooking up an ESP-01, burn the NodeMCU firmware and setting it up as a webserver.

Briefly said, you hook up the ESP directly to a USB to Serial converter (3.3V!), download the NodeMCU Flasher tool, select the COM port and hit the Flash Button.

When that is done, download the ESPlorer software to talk to it. LUA is a very straightforward language to learn and if you're used to closures like in Javascript, you'll feel right at home. NodeMCU has a nice, documented API and several libraries that you can add for special hardware like LCD's, WS2812/2811 LEDs, sensors and more.

The NodeMCU firmware is based on the original Espressif SDK and thus inherits all the bugs in this. This means that the hardware will crash just as often, but since it always restarts after a crash, it will re-run your LUA script on startup. This makes NodeMCU good enough for devices that should just send some sensor data to a webservice such as Thingspeak. It will not work well as an access point doubling as a webserver though. It'll crash and hang just as often as with the original firmware, so for me this is a showstopper. I want to make IoT gadgets that offer a web interface to use it as well as an open API.

Stock firmwares

My initial idea was to use the UART in the ESP boards. Most my projects are based around the Teensy 3.1 and it has 3 serial ports, so it's a breeze to do UART communications with. No matter how hard I tried, I couldn't make this 100% stable. After an hour or two, it just crashed and restarted. If there was more traffic, it would crash more often and my intent was to basically bombard it with data continuously. I tried all the different versions of the firmware and even the official 1.0 version that was released this week is buggy beyond repair.

Building the toolchain yourself is quite easy if you have a Ubuntu VM. Just follow the instructions outlined here, but it won't really solve all your problems. Some of the software is Open Source, but other parts are provided as "binary blobs" so you can't really know what bugs hide inside. It's thus just easier to use a prebuilt firmware in the form of the precompiled .bin files unless you really want to program the chip from scratch. If you DO want to do that, check this neat guide on Hackaday.

Updating the firmware is quite easy if you use the NodeMCU Flasher. I tried a couple other solution before that and they were rather cumbersome. It's Windows only though, so if you like Python, check out the esptool. All the officially Espressif SDK's contain a "bin"-folder that has the files and a text description of what memory addresses to copy each .bin file into.

ESP8266-transparent-bridge

This "Transparent Bridge" is the current solution I'm experimenting with. It's a completely dumbed down firmware that can take a TCP connection on any port and relay it to the Serial port (RX/TX). Just apply power, connect to the WiFi access point that it sets up, Telnet to the default 192.168.4.1 address and you can set it up to join your local network / access point. You can then up the BAUD rate to whatever you want/need and change the Port to for example 80 to make it work easily with browsers.

Anything sent to the ESP will then show up on the Serial connection and when you write back to the connection, you can return data (like a webpage). Currently, this seems to be the most promising solution, but it requires some more testing. The basic idea is to use as little as possible of the buggy Espressif SDK as possible. To get the ESP Transparent Bridge firmware onto the device, the easiest is to just load the premade .bin files with the NodeMCU Flasher tool:

I'll post back here when I have further results on this setup.

But why care if it's buggy?

You might ask yourself - why on earth should one care about this chip if it is so buggy the creator hosts a competition to find all the bugs? The thing is - at $2 you can put wifi into ANYTHING! A typical wifi-shield for an Arduino will cost you from $30 and up to $90. Just a plain breakout board from Adafruit will cost you $35 and the CC3000 that it's based on isn't exactly stable either. A $2 chip that works would open up so many possibilities, so that's why I still care after fiddling this much with it.

A little about the hardware

The ESP8266 is a small powerhouse and this is a small 101 on the hardware. It's an ARM processor that runs at 80Mhz and can be overclocked to the double. It has up to 16 GPIO pins available and it does SPI, I2C, UART & more in hardware (fast!). It offers great range and you can get one for as low as $2 on ebay. Physically, it is a tiny 5 x 5 mm Integrated Circuit that needs a little supportive components around it to be useful. There is a series of dev-boards that offers this: ESP-1, ESP-2, ESP-3, ESP-4, ESP-5, ESP-6, ESP-7 and so on, all the way up to ESP-12. They differ with regards to pin spacing, internal/external antenna and the number of GPIO pins broken out. It was hard to locate all the pinout diagrams, so I've gathered them all in a github repository that I'll fill with useful code and resources.

The ESP-1 is typically the cheapest and most available. It only has 2 I/O pins broken out and uses 2.54mm headers. They are however clumsily combined into a 2x4 arrangement making them impossible to breadboard. It's not hard to make an adapter, but the ESP-2 is more practical for breadboard use. This also has a third I/O pin broken out, but requires an external antenna. The different versions all offer useful features, but the ones to avoid are ESP-5 and ESP-10. These do not have the pins required for updating the firmware exposed.

The version that seems to attract the community is ESP-12. It has FCC certification, RF-shielding, ADC and 9 GPIO's. It is included in the NodeMCU devkit that you can now get from TronixLabs and several other Open Hardware vendors. I'm looking forward to getting a couple of these to play around with. Other devboards that look interesting are the new one's from Olimex.

Show more