import machine
i2c = machine.I2C(0, scl=machine.Pin(21), sda=machine.Pin(20))
print('Scan i2c bus...')
devices = i2c.scan()
if len(devices) == 0:
print("No i2c device !")
else:
print('i2c devices found:',len(devices))
for device in devices:
print("Decimal address: ",device," | Hexa address: ",hex(device))
print()
import ds1307
import time
ds = ds1307.DS1307(i2c)
ds.halt(False)
# Set initial datetime (year, month, day, weekday, hour, minute, second, subsecond)
now = (2023, 10, 27, 1, 5, 16, 3, 0, 0)
def format_datetime(datetime):
year, month, day, weekday, hour, minute, second, subsecond = datetime
return f"{year}-{month:02d}-{day:02d} {hour:02d}:{minute:02d}:{second:02d}"
while True:
current_datetime = ds.datetime()
formatted_datetime = format_datetime(current_datetime)
print(formatted_datetime)
time.sleep(1)