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 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 nodemcu-firmware-esp32
cd nodemcu-firmware-esp32/
sudo apt install flex bison
make flash

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

configsip: 0, SPIWP:0xee
mode:DIO, clock div:1
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.


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:
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);

 digitalWrite(16, LOW); // set GPIO16 low to reset OLED
 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, polished the code and you can see the result here:

If you are interested in the source, you can find it here:

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

25 thoughts on “ESP32 NTP OLED clock”

  1. I tried this but for some reason the screen just says “CONN”. What does this mean and how might I fix it?

    1. CONN means no wifi connection, you need to update wifi network name and password to suit your settings.

      1. Thanks – the problem was with my particular WiFi network, it works with my mobile hotspot.

        Couple of observations – my microcontroller gets extremely hot; my thoughts immediately to remedy this are to decrease the update frequency of the clock. Can you think of something else that might cause this.

        Another general observation is the display is nice and bright but at night time it’s probably too bright – is there a way to decrease the brightness, and moreso is there a way to decrease the brightness according to the time of day?

        Love the design, I also 3D printed a case for this board so that you can use it as a desktop clock or whatever.

        1. The link is not working… I’ll check the temperature when I get home. You are right with the brightness, maybe this function can handle this: void setContrast(char contrast); ?

          1. Yeah sorry about the link, thingiverse requires that you have an account for 24 hours before you can publish things – check back tomorrow!

            I’ll give that function a try.

          2. OK so I added “void setContrast(char contrast);” and “display.setContrast(0);” to the “void display_text” section. It does seem to have an effect on screen brightness somewhat, but less than I expected.

            See details here:

        2. I measured my module today with IR thermometer: display about 40 degC, ESP32 about 35degC, rest of the board less.

          1. Interesting, I don’t have access to a thermometer but just from putting my finger on the heat sink, it seems a lot hotter than 35C. Wonder what that could be!

  2. Hi there,

    I have installed PlatformIO but,

    I got :
    *** [.pioenvs/lolin32/src/main.cpp.o] Error 1

    for this line :

    How can I install that library ?

  3. Compiling .pioenvs/lolin32/src/main.cpp.o
    src/main.cpp:5:25: fatal error: ESP8266WiFi.h: No such file or directory

  4. Hi Danman
    thanks for response for my last problem. It work so easy.

    I dont know why, i have to comment this line:
    cause it make a error code: (unsigned char*}’ [-fpermissive])

    so the display font is very small …
    Can you help me to correct my problem please.

  5. Awesome !

    Thanks so much for this update, it solve my problem (no need to keep glass to see clock at night)

Leave a Reply

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

This site uses Akismet to reduce spam. Learn how your comment data is processed.