Simplest ESP8266 Local Time Internet Clock With OLED
Intro: Simplest ESP8266 Local Time Internet Clock With OLED
I was looking for a straightforward clock to use with a 128x64 OLED I got from Adafruit but found that a lot of the implementations were too cumbersome, involved a ton of code, weren't clear on what NTP servers to use and how, and basically offered very little in terms of making a clock with the LOCAL time (not UTC, which is easy enough to get). So I set about doing my own research and ended up with this simple clock that leverages already made libraries to minimize the code footprint, while offering some interesting tweaks in displaying the time (like AM/PM, 12-hour format, names for months, days, etc). This instructable assumes you have some experience programming ESP-01s but if not, there are a ton of wonderful tutorials available on Instructables! Enjoy!
STEP 1: Components
For this instructable you will need:
- ESP8266-01 module
- 128x64 OLED with I2C interface
- 3.3V power supply
- A way to program the ESP-01
STEP 2: Wire It Up!
The wiring is simple. Just follow the diagram above and connect the wires. Then get a 3.3V power supply (I used a step-down module to go from 12V to 3.3 but you can use whatever you have in your arsenal as long as it outputs 3.3V and at least 0.5 A).
STEP 3: Program the ESP-01
This step can be frustrating if you haven't done it before, but once you get the hang of how the ESP boards work and have the correct drivers and libraries installed in Arduino, you can go ahead and use the following code. But first, you will need to download and install the following libraries:
- Time.h & TimeLib.h: https://github.com/PaulStoffregen/Time
- Timezone.h: https://github.com/JChristensen/Timezone
- SSD1306.h & SSD1306Wire.h: https://github.com/squix78/esp8266-oled-ssd1306
- NTPClient.h: https://github.com/arduino-libraries/NTPClient
- ESP8266WiFi.h & WifiUDP.h: https://github.com/ekstrand/ESP8266wifi
You may need to modify some of the code according to what OLED you're using (as long as it's SSD1306 it'll work but you may need to update the hex I2C address) and then you may have to change some of the Timezone rules depending on your timezone and daylight savings time rules. Then upload the code attached and you should be done!
STEP 4: See It Go!
Once you have programmed the ESP, plugged everything in, make sure you have 3.3V going into the setup and then power it on and see your correct time on the tiny display!
66 Comments
Germain76 9 months ago
I try the sketch with Arduino 1.8.19 and with Arduino 2.0 and esach tile I get the following error:
class SSD1306 has no member named init for the line : display.init();
Thank's in advance for your help
pingsinoca 8 months ago
maurice-meister 1 year ago
pingsinoca 1 year ago
pingsinoca 1 year ago
Remarks: I created a new 3D printing shell (STL format, which can be put into your printer to print, if you want STL, please leave a message for your
我已經做好這個項目,也含創建新的3D打印殻体,我組裝完成裝入日期(顯示):5月1日2023年
備註:我創建新的3D打印殻体(STL格式,可以投入你的打印機來打印,如果你要你要STL請留言你的@信箱,可以分享給大家
pingsinoca 2 years ago
giecuk 6 years ago
jandmgatza 3 years ago
Xuan TruongH 5 years ago
timg11 5 years ago
Compiler gives: "WARNING: library Timezone claims to run on (avr) architecture(s) and may be incompatible with your current board which runs on (esp8266) architecture(s)."
Does this mean anything?
michail1 3 years ago
Look for a file in the library directory in the Timezone folder called...
library.properties
open as a text file and change...
architectures=avr
to
architectures=avr,esp8266,esp32
DaniilZ 5 years ago
No
Edward_ 4 years ago
Or do you have a 24 Hr version?
yoavaba1 4 years ago
t += ":";
if(minute(local) < 10) // add a zero if minute is under 10
t += "0";
t += minute(local);
t += " ";
t += ampm[isPM(local)];
to:
t += hour(local);
t += ":";
if(minute(local) < 10) // add a zero if minute is under 10
t += "0";
t += minute(local);
t += ":";
if(second(local) < 10) // add a zero if minute is under 10
t += "0";
t += second(local);
you can delete the seconds
Scotthus2 4 years ago
TimeChangeRule usCDT = {"CDT", Second, Sun, Mar, 2, -300}; //UTC - 5 hours - change this as needed
TimeChangeRule usCST = {"CST", First, Sun, Nov, 2, -360}; //UTC - 6 hours - change this as needed
Timezone usCentral(usCDT, usCST);
local = usCentral.toLocal(utc);
MichaelB247 4 years ago
Scotthus2 4 years ago
nanoprof 4 years ago
parisa2000 4 years ago
leonardtsai22 4 years ago
TimeChangeRule usPDT = {"PDT", Second, Sun, Mar, 2, -420}; //UTC - 7 hours - change this as needed
TimeChangeRule usPST = {"PST", First, Sun, Nov, 2, -480}; //UTC - 8 hours - change this as needed
Timezone usPacific(usPST, usPDT);
local = usPacific.toLocal(utc);
However, it seems that the time is showing PST instead of PDT (currently it is June so should be daylight saving PDT time instead).
Where may I have missed it?
Thanks in advance.