from machine import Pin, ADC, I2C
import oled
import utime
from rtc import RTC
# This code contains 2 issues.
# I2C Port
i2c = I2C(scl=Pin(22), sda=Pin(21), freq=400000)
utime.sleep(2)
addresses = i2c.scan()
print(addresses)
# First issue solved. There was a connection issue. Both SDA and SCL were
# mixed up on the RTC connection.
# I2C OLED
oled = oled.SSD1306_I2C(128, 64, i2c, addr=int(addresses[0]))
# Second issue solved. It was an address issue. Scan couldn't detect it because
# according to ChatGPT, some addresses are reserved to specific tasks, so I
# decided on changing the address to a suitable one. Additionally, I used scan
# to detect and assign the address to the OLED, if change is needed.
# I2C Real time clock - DS1307
rtc = RTC(i2c)
oled.fill(0)
oled.text("Welcome!", 35, 20)
oled.show()
utime.sleep(2)
while True:
# Read date and time from RTC
date = rtc.get_date_string()
time = rtc.get_time_string()
# Show date/time in screen
oled.fill(0)
oled.text(date, 22, 20)
oled.text(time, 30, 40)
oled.show()
utime.sleep(0.1)Loading
ssd1306
ssd1306