RTC refuses to set

The official pyboard running MicroPython.
This is the reference design and main target board for MicroPython.
You can buy one at the store.
Target audience: Users with a pyboard.
Post Reply
rhubarbdog
Posts: 168
Joined: Tue Nov 07, 2017 11:45 pm

RTC refuses to set

Post by rhubarbdog » Fri Sep 07, 2018 11:15 am

hi
I've been playing with the real time clock RTC.
i had this working earlier now setting the RTC with `pyb.RTC().datetime((a-tuple))` just hangs for a few seconds and fails to reset the clock.

This is my program

Code: Select all

import pyb

clock = pyb.RTC()

print("Enter date as revesed tuple (Y,M,D,0,H,M,S,0)")
get_date=input("Enter the 0's and ()'s :")

clock.datetime(eval(get_date))

while True:
    pyb.delay(1000)
    print(clock.datetime(), end="   \r")

i believe from experimentation the date is entered as a tuple Year, Month, Day, <don't know>, Hours, Minutes, Seconds, <milliseconds??>
I currently enter
(2018,9,7,0,12,13,0,0)

it hangs for a second or two and prints
(2000, 1, 1, 1, 0, 0, 0, 0)

shaoziyang
Posts: 363
Joined: Sun Apr 17, 2016 1:55 pm

Re: RTC refuses to set

Post by shaoziyang » Fri Sep 07, 2018 12:29 pm

Sometimes RTC may not initial correctly after power on, then RTC not running. You may try clock.init() to re-initial RTC.

User avatar
pythoncoder
Posts: 5956
Joined: Fri Jul 18, 2014 8:01 am
Location: UK
Contact:

Re: RTC refuses to set

Post by pythoncoder » Sat Sep 08, 2018 5:31 pm

The tuple looks good - it's documented here.

I have seen exactly that symptom and agree with @shaoziyang that it usually implies that the RTC crystal oscillator is stopped. This can occur for various reasons: the circuitry around the 32KHz crystal is quite sensitive and handling the board while powered up (or with the RTC running off a backup cell) can stop it. Check for anything untoward electrically.
Peter Hinch
Index to my micropython libraries.

Post Reply