Note: the code has been (again) updated in Dec 2022 thanks for some nice feedback. Now the code should work for both ESP8266 and ESP32 (although it runs smoother on ESP8266 - WeMos D1, NodeMCU, etc.).
Originally I use WiFiMulti so that users can set multiple APs (hence the clock will work in different places) but it has been proved to be problematic on ESP32.
Another simple project. Since the main font is big enough, you can use it as a real clock on your desk. Set the WiFi AP name, password and timezone offset (hour) before uploading.
The ESP8266 board will update its board time every 15 minutes via the NTP (Network Time Protocol) server and constantly display date and time on a "0.96 SSD1306 OLED display. The libraries I used are NTPClient and u8g2.
u8g2 (U8x8lib) is actually an interesting OLED library, which has a lot of fonts in different sizes. The sizes are a bit confusing though; the smallest size are 8x8 pixels per character, so "1x2" means 8x16 pixels, "3x6" is 24x36 pixels, etc. The x and y parameters of u8x8.drawString method are referring to the characters, hence x is 0-15 and y is 0-7.
u8g2 also works for a lot of different OLEDs and LCDs, including those Chinese-made OLEDs which don't return I2C ACK signals (which may cause other drivers non-working). This is exactly how I found this library - I got one of these from other people a while ago.
Comments