from machine import I2C, Pin, ADC
from time import sleep
import math
import random
# very important
# this modules needs to be saved in the Raspberry Pi Pico in order for the RTC to be used
import ds1307
# I2C Initialisation:
# creating I2C objects, specifying the data (SDA) and clock (SCL) pins used in the Raspberry Pi Pico
# any SDA and SCL pins in the Raspberry Pi Pico can be used (check documentation for SDA and SCL pins)
i2c_rtc = I2C(0, scl=Pin(9), sda=Pin(8), freq=100000)
# I2C object
# creating an DS1307 RTC object using I2C
ds1307rtc = ds1307.DS1307(i2c_rtc, 0x68)
def get_date_string():
dt = ds1307rtc.datetime
return str(dt[2]) + "." + str(dt[1]) + "." + str(dt[0])
def get_time_string():
dt = ds1307rtc.datetime
return str(dt[3]) + ":" + str(dt[4])+ ":" + str(dt[5])
def main():
while True:
print("\n")
print(get_time_string())
print(get_date_string())
sleep(5)
if __name__ == "__main__":
main()