from machine import RTC
import ntptime
from machine import Pin, I2C
import ssd1306
from time import sleep
from i2c_lcd import I2C_LCD
ntptime.settime() # Fetches the current UTC time from an NTP server and sets the ESP32’s system clock.
rtc = RTC() # Creates an RTC object to access the current time.
while True :
year, month, day, wday, hrs, mins, secs, subsecs = rtc.datetime()
hrs = (hrs + 3) % 24
t = "Time: " + str(hrs) + ":" + str(mins) + ":" + str(secs)
d = "Date: " + str(day) + "/" + str(month)+"/" + str(year)
print(t)
print(d)
# using default address 0x3C
i2c = I2C(scl=Pin(22), sda=Pin(21))
oled_width = 128
oled_height = 64
oled = ssd1306.SSD1306_I2C(oled_width, oled_height, i2c)
LCD = I2C_LCD(i2c,0x27)
oled.text(t, 0, 10)
oled.text(d, 0, 30)
oled.show()
LCD.print_all(t + "\n" + d)
sleep(1)
Loading
esp32-devkit-c-v4
esp32-devkit-c-v4
Loading
ssd1306
ssd1306