ESP32 NTP OLED clock

As a first project with my new ESP32 module with OLED display I chose to build OLED clock. I thought I’ll just find some existing code, upload it and it’s done. There are a few such projects for ESP8266 in NodeMCU. So I started with NodeMCU upload.

First I tried NodeMCU binary from https://nodemcu-build.com/ but it was throwing strange binary streams to serial and didn’t respond to any keys. Then I found out it is probably only for ESP8266 so I decided to build esp32-dev version from sources like this:

git clone --branch dev-esp32 --recurse-submodules https://github.com/nodemcu/nodemcu-firmware.git nodemcu-firmware-esp32
cd nodemcu-firmware-esp32/
sudo apt install flex bison
make
make flash

But this was also not working, I was getting following error in loop:

rst:0x1 (POWERON_RESET),boot:0x17 (SPI_FAST_FLASH_BOOT)
configsip: 0, SPIWP:0xee
clk_drv:0x00,q_drv:0x00,d_drv:0x00,cs0_drv:0x00,hd_drv:0x00,wp_drv:0x00
mode:DIO, clock div:1
load:0x3fff0010,len:4
load:0x3fff0014,len:588
load:0x40078000,len:0
load:0x40078000,len:9768
entry 0x400789b8
ets Jun 8 2016 00:22:57

Then I decided to go different way – to build my own app as complete binary with PlatformIO.

PlatformIO

is a IoT IDE built on top of Atom editor:

It supports building Arduino projects and Arduino library supports ESP8266 and ESP32 (PlatformIO supported boards).

Starting new project is easy – just choose some ESP32 board

You are thrown into empty project afterwards

Now since I want to use NTP for getting exact time and don’t want to write own client, let’s see if there is a library available:

Let’s open Libraries

Now search for NTP

OK, let’s try one

Install it. It contains example code so I can copypaste it into main.cpp. So now I have time source. Next I need display driver. Googling “ESP OLED” gives me this library:
https://github.com/squix78/esp8266-oled-ssd1306
What attracted my attention was, that those screenshots showed exactly the same pictures my device was showing with factory firmware (which I backed up just for case). So I knew it might work. So I installed it as the README says by running

platformio lib install 562

in PlatformIO console.

Then I connected my module via USB and /dev/ttyUSB0 appeared. Next I put together some example code and hit Upload.

Unfortunately, nothing was shown, nor on serial port, nor on display. But one thing I was not sure about was display address defined by:

SSD1306  display(ADDRESS, SDA, SDC);

Because I bought very specific module with short description (because I liked it’s size), I needed to search a little bit but finally I’ve found the same one with more verbose description and WITH EXAMPLES! 🙂 The key to working display was to set right address and reset in on start:

SSD1306 display(0x3c, 4, 15);

 pinMode(16,OUTPUT);
 digitalWrite(16, LOW); // set GPIO16 low to reset OLED
 delay(50);
 digitalWrite(16, HIGH); // while OLED is running, must set GPIO16 in high

After this, I just did some fancy layout setup, generated huge font at http://oleddisplay.squix.ch, polished the code and you can see the result here:

If you are interested in the source, you can find it here:
https://github.com/danielkucera/esp32-oled-clock

Now I’m thinking what will be my next project with this module and I already have some ideas.

5 thoughts on “ESP32 NTP OLED clock”

Leave a Reply

Your email address will not be published. Required fields are marked *