I feel like I should be able to use the RTC example provided (http://docs.micropython.org/en/v1.9.3/p ... b.RTC.html) to set up a clock and be able to unplug the pboard (v1.1) and still have it keep time (provided that a CR2032 is connected to VBACK & GND). Then, after some time passes, plug in the board and be able to recall the clock via REPL or my main program and have the clock give me the correct time within +/- 1-2 hours (Depending on the length of time the board is unplugged and unpowered).
Part of my problem is knowing where and how rtc is being stored since rtc is an object (if rtc = pyb.rtc()). If its stored in ram, then I feel like the rtc object would be wiped as soon as the board is unpowered and I would need to rebuild the rtc object in boot.py. Any thoughts on how to do this and what is going on with the rtc object?
Thanks!
How does the onboard RTC work?
Re: How does the onboard RTC work?
The RTC object created by pyb.RTC() is in fact in RAM and is lost at power off. However, when you re-construct it you can just read the current time from the RTC (using rtc.datetime()) and it should be correct.
The CR2032 keeps the clock ticking on the underlying RTC hardware. Constructructing the RTC object doesn't affect the underlying hardware. Calling rtc.datetime with arguments to set the date and time will, of course, wipe out the current time stored in the RTC.
The example shows how to set the RTC. Remove the middle line to just read and print the time. i.e.
The CR2032 keeps the clock ticking on the underlying RTC hardware. Constructructing the RTC object doesn't affect the underlying hardware. Calling rtc.datetime with arguments to set the date and time will, of course, wipe out the current time stored in the RTC.
The example shows how to set the RTC. Remove the middle line to just read and print the time. i.e.
Code: Select all
rtc = pyb.RTC()
print(rtc.datetime())
Re: How does the onboard RTC work?
Thanks for the reply! So here is my next question. Is there a way for me to reconstruct the clock object without having the user reinitialize the clock. My thought is if I know when I first activated the RTC circuit then I would just have the board find out how long the RTC circuit has been in operation and then add that time to the initial activation time to give me current time. Is this possible? if so, how do I find out how long the RTC circuit has been in operation for?
Re: How does the onboard RTC work?
You only need to set the RTC once. Once its set, it will maintain the correct time until your CR2032 battery runs out. Even when the pyboard is powered down, as long as the CR2032 is still powering the RTC, then it will continue to tick along and keep the current time.
Re: How does the onboard RTC work?
Sorry, I did understand what you were saying but when I tried your instructions I received this as a response from the controller.
>>> print(rtc.datetime())
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'rtc' is not defined
If it is supposed to work could it be that I have a bad board?
>>> print(rtc.datetime())
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
NameError: name 'rtc' is not defined
If it is supposed to work could it be that I have a bad board?
Re: How does the onboard RTC work?
You still need the line to create the rtc object.
Code: Select all
rtc = pyb.RTC()
Re: How does the onboard RTC work?
Thank you so much! That was the problem! RTC is working beautifully now that I understand what I was doing wrong.