from machine import I2C, Pin
import utime
import ds3231_port
i2c = I2C(0, scl=Pin(9), sda=Pin(8))
rtc = ds3231_port.DS3231(i2c)
csv_filename = "data.csv"
with open(csv_filename, "w") as f:
f.write("S.No,Time\n")
sno = 1
while True:
year, month, day, hour, minute, second, weekday, _ = rtc.get_time()
current_time = "{:02d}/{:02d}/{:04d} {:02d}:{:02d}:{:02d}".format(
day, month, year, hour, minute, second)
with open(csv_filename, "a") as f:
line = "{},{}\n".format(sno, current_time)
f.write(line)
print(line.strip())
sno += 1
utime.sleep(1)