Analog clock with the Wemos D1 Mini
FunduinoLast updated on
Die Uhrzeit per NTP aus dem Internet holen
You need this
0.96-inch OLED display - 128x64 pixels, I2C, SSD1306
4,19 € *Item no. FUN-1010561About the product — 0.96-inch OLED display - 128x64 pixels, I2C, SSD1306
WeMos D1 Mini ESP8266 - development board with Wi-Fi, 3.3 V
5,95 € *Item no. F23106678About the product — WeMos D1 Mini ESP8266 - development board with Wi-Fi, 3.3 V
All 2 parts together 10,14 € *
* All prices include statutory VAT, plus shipping costs.
Wemos D1 Mini and NTP
What should be displayed
Install the board
1 / 4
Install the libraries
1 / 2
The circuit diagram
The program
Display the date and time via NTP on the OLED
// Include libraries
# include <ESP8266WiFi.h>
# include <NTP.h>
# include <WiFiUdp.h>
# include <NTP.h>
# include <U8g2lib.h>
/*
Type designation with screen size in pixels
1 = page buffer mode
Hardware I2C
OLED name
Rotation R0 (none)
*/
U8G2_SSD1306_128X64_NONAME_1_HW_I2C oled(U8G2_R0, U8X8_PIN_NONE);
// Router SSID and password
char Router[] = "SSID_des_Routers";
char Passwort[] = "xxxxxxx";
// Start NTP
WiFiUDP wifiUdp;
NTP ntp(wifiUdp);
// Time until the next measurement
static unsigned long GesicherteStartZeit = 0;
unsigned long Startzeit;
// 30-second interval, can be adjusted
int Intervall = 30000;
void setup()
{
Serial.begin(9600);
delay(500);
// Start WiFi with DHCP
WiFi.begin(Router, Passwort);
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
}
// Display the router SSID in the serial monitor
Serial.print("Connected to ");
Serial.println(WiFi.SSID());
// Display IP
Serial.print("IP: ");
Serial.println(WiFi.localIP());
/*
Time zone
CEST: Central European Summer Time
Start of European daylight saving time: last Sunday in March at 2 a.m. GMT + 2 hours
*/
ntp.ruleDST("CEST", Last, Sun, Mar, 2, 120);
// CET: Central European Time
// Start of standard time: last Sunday in October at 3 a.m. GMT + 1 hour
ntp.ruleSTD("CET", Last, Sun, Oct, 3, 60);
// Start NTP
ntp.begin();
// Start OLED
oled.begin();
// Font
oled.setFont(u8g2_font_courB24_tf);
// Draw color white
oled.setDrawColor(1);
// Horizontal text
oled.setFontDirection(0);
// Display date and time on startup
ntp.update();
oled.clearDisplay();
oled.firstPage();
do
{
oled.setCursor(2, 15);
oled.setFont(u8g2_font_t0_22_te);
// Day: add leading 0
if (ntp.day() < 10) oled.print("0");
oled.print(ntp.day());
oled.print(".");
// Month: add leading 0
if (ntp.month() < 10) oled.print("0");
oled.print(ntp.month());
oled.print(".");
// Year
oled.print(ntp.year());
// Horizontal line
oled.drawHLine(1, 22, oled.getDisplayWidth());
oled.setCursor(2, 63);
// Time
// Hours: add leading 0
oled.setFont(u8g2_font_logisoso32_tf);
if (ntp.hours() < 10) oled.print("0");
oled.print(String(ntp.hours()) + ":");
// Minutes: add leading 0
if (ntp.minutes() < 10) oled.print("0");
oled.print(String(ntp.minutes()));
}
while (oled.nextPage());
}
void loop()
{
// Set start time
Startzeit = millis();
// If the specified interval has elapsed
if (Startzeit - GesicherteStartZeit > Intervall)
{
// Update time
ntp.update();
oled.clearDisplay();
// Reset start time
GesicherteStartZeit = Startzeit;
// Display date and time on the OLED
oled.setCursor(3, 20);
oled.firstPage();
do
{
oled.setCursor(2, 15);
oled.setFont(u8g2_font_t0_22_te);
// Day: add leading 0
if (ntp.day() < 10) oled.print("0");
oled.print(ntp.day());
oled.print(".");
// Month: add leading 0
if (ntp.month() < 10) oled.print("0");
oled.print(ntp.month());
oled.print(".");
oled.print(ntp.year());
// Horizontal line
oled.drawHLine(1, 22, oled.getDisplayWidth());
oled.setCursor(2, 63);
// Time
// Hours: add leading 0
oled.setFont(u8g2_font_logisoso32_tf);
if (ntp.hours() < 10) oled.print("0");
oled.print(String(ntp.hours()) + ":");
// Minutes: add leading 0
if (ntp.minutes() < 10) oled.print("0");
oled.print(String(ntp.minutes()));
}
while (oled.nextPage());
}
}Rate the instructions