My first post about waiting for some ESP8266 based boards was back in 2016, and I’ve mentioned the use of an ESP8266 in various home automation posts. However I’ve never actually written up what I did with that first board. Hopefully you’ve figured it out from the title of this post.

I had an actual need/desire for a new beside clock. Previously I had a Sony Clock Radio cube, which set itself via the MSF signal. However it ended up with drift - I’m guessing it did a set on power on, but then failed to regularly sync up. I don’t need an alarm clock - my phone provides a much more flexible set of options for that - but I do like to be able to easily tell when I wake up in the night if I’ve got 5 minutes until the alarm or several hours. This seemed like a perfect (if unimaginative) first project for the ESP8266 - build something standalone that would get the time via NTP and have a night-time visible time display.

I purchased a bare ESP-03 module and an ESP-12E on a breakout board (i.e. with a bunch of pin headers soldered on, a 5V→3.3V voltage regulator, the appropriate boot resistors) to experiment with. I figured the 12E would be a good board to prototype with and I’d use the cheaper 03 in the final implementation. For the display I bought a 4 module MAX7219 based 8x8 LED matrix - I could have gone for a 7-segment LED based thing, but I wanted the option of being able to display text.

Initially I installed MicroPython on the board; the ability to interactively try things out helped me to figure out the ESP8266 hardware, and how to drive the MAX7219s using the SPI interface. I’m really impressed with it as a prototyping tool in conjunction with the ESP8266. However I decided it wasn’t what I wanted to do my final implementation in. Although I was just building a basic clock I was using the project as a basis to learn about how to do more complicated things, and I wanted features like Over-The-Air updates, and the potential for displaying custom messages. So I turned to the ESP8266 NONOS C SDK via Paul Sokolovsky’s excellent esp-open-sdk. Richard Antony Burton has some great resources as well, and Espressif have a decent amount of SDK documentation these days. With all of this info I was able to move my code from Python to C.

One of the limitations I hit was trying to fit my code into the available flash on the 03 module. The 12E came with a massive 4MB flash chip, but the 03 was a much more limited 512kB. To allow OTA upgrades that mean I had just under 256kB to work with. Even with a pure C implementation until I made sure I was using all the ROM functions available, and only including the pieces I really needed, I was regularly exceeding this. (As it happened, ultimately the cheap flash on the 03 died during my experimentation and I ended up fixing the flash using a larger 2M chip. Trimming my code down to fit within the 256kB limitation was still an interesting exercise.)

The code’s not the prettiest, but it does what I need and I’m really glad I built in the OTA functionality - it makes testing much, much easier than having to do the serial flash dance on every change. Available locally or on GitHub.

The final piece was to find a suitable case. I suck at this. Lucky we had a small glass topped wooden box in the house which was about the right side. A piece of paper in front of the glass provided a suitable filter and while I’m not going to win any awards for design the whole thing ends up looking reasonably well on my beside table.

ESP8266 Clock

(As an aside, if you’re interested in seeing a toolchain for the ESP8266 hit Debian then I’ve already uploaded binutils-xtensa-lx106 + gcc-xtensa-lx106 and am just waiting on binutils to exit NEW - there’s been some discussion about the correct naming in #917546 that I think is making ftp-master a bit more cautious.)