Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 14 additions & 6 deletions enviro/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -127,12 +127,6 @@ def stop_activity_led():

# intialise the pcf85063a real time clock chip
rtc = PCF85063A(i2c)
i2c.writeto_mem(0x51, 0x00, b'\x00') # ensure rtc is running (this should be default?)
rtc.enable_timer_interrupt(False)

t = rtc.datetime()
# BUG ERRNO 22, EINVAL, when date read from RTC is invalid for the pico's RTC.
RTC().datetime((t[0], t[1], t[2], t[6], t[3], t[4], t[5], 0)) # synch PR2040 rtc too

# jazz up that console! toot toot!
print(" ___ ___ ___ ___ ___ ___ ")
Expand Down Expand Up @@ -237,6 +231,19 @@ def sync_clock_from_ntp():
logging.info(" - rtc synched")
return True

def init_rtc():
i2c.writeto_mem(0x51, 0x00, b'\x00') # ensure rtc is running (this should be default?)
rtc.enable_timer_interrupt(False)

if not is_clock_set():
sync_clock_from_ntp()

t = rtc.datetime()
RTC().datetime((t[0], t[1], t[2], t[6], t[3], t[4], t[5], 0)) # synch PR2040 rtc too


init_rtc()

# set the state of the warning led (off, on, blinking)
def warn_led(state):
if state == WARN_LED_OFF:
Expand Down Expand Up @@ -498,3 +505,4 @@ def sleep(time_override=None):

# reset the board
machine.reset()