machine.RTC().datetime() gives incorrect hours, minutes, and day of the week
machine.RTC().datetime() gives incorrect hours, minutes, and day of the week
Upon setting the datetime with machine.RTC().datetime(), the hours, minutes, and day of the week appear to be reading incorrect values:
Does anyone know why this happens?
Does anyone know why this happens?
Re: machine.RTC().datetime() gives incorrect hours, minutes, and day of the week
I know rshell has a bunch of code to deal with the various RTC's:
https://github.com/dhylands/rshell/blob ... in.py#L951
It looks like the arguments to datetime are expected to be in the following order:
(year, month, day, weekday, hour, minute, second, subseconds)
https://github.com/dhylands/rshell/blob ... in.py#L951
It looks like the arguments to datetime are expected to be in the following order:
(year, month, day, weekday, hour, minute, second, subseconds)
Re: machine.RTC().datetime() gives incorrect hours, minutes, and day of the week
Got it, thanks. There appears to be a discrepancy between utime.localtime() and machine.RTC().datetime() then:dhylands wrote: ↑Wed Jan 20, 2021 9:07 pmI know rshell has a bunch of code to deal with the various RTC's:
https://github.com/dhylands/rshell/blob ... in.py#L951
It looks like the arguments to datetime are expected to be in the following order:
(year, month, day, weekday, hour, minute, second, subseconds)
- pythoncoder
- Posts: 5956
- Joined: Fri Jul 18, 2014 8:01 am
- Location: UK
- Contact:
Re: machine.RTC().datetime() gives incorrect hours, minutes, and day of the week
There is. utime.localtime matches CPython's time module. Unfortunately RTC.datetime() - which isn't even documented - adopts a different convention which is based on STM hardware and the pyb module. The nearest you'll get to docs may be found here.
Peter Hinch
Index to my micropython libraries.
Index to my micropython libraries.
Re: machine.RTC().datetime() gives incorrect hours, minutes, and day of the week
I have started to notice that the call to the function:
utime.localtime() is now reporting the following value:
>>> utime.localtime()
(2015, 1, 1, 0, 44, 11, 3, 1)
I am not sure why it reset itself to the first day of the year in 2015. Do you have any idea why this is happening?
utime.localtime() is now reporting the following value:
>>> utime.localtime()
(2015, 1, 1, 0, 44, 11, 3, 1)
I am not sure why it reset itself to the first day of the year in 2015. Do you have any idea why this is happening?
Re: machine.RTC().datetime() gives incorrect hours, minutes, and day of the week
Through trial and error, I've found that removing power to the pyboard and then plugging it back into the computer via microUSB is what is causing the time to reset. Simply hitting CTRL-D does not cause that to happen. Do either of you have any idea why this is occurring?
Re: machine.RTC().datetime() gives incorrect hours, minutes, and day of the week
When you remove power then the the RTC will reset.
You need to provide power to VBAT (typically using a coin cell or simialr) if you want the RTC to keep ticking while power is removed.
You need to provide power to VBAT (typically using a coin cell or simialr) if you want the RTC to keep ticking while power is removed.
Re: machine.RTC().datetime() gives incorrect hours, minutes, and day of the week
Got it. So is there any way to get the actual datetime then in between power cycles (outside of providing VBAT power with a coin cell or equivalent)? Due to other constraints, I don't have the ability to include an additional coin cell just to power VBAT. I could add code to the boot.py which would rewrite a hardcoded time to the RTC on boot up, but that value is constantly changing as time passes so there would be no way of knowing what to write there.
Re: machine.RTC().datetime() gives incorrect hours, minutes, and day of the week
Yeah - there is no RTC that I'm aware that can keep time when not powered. This is also why external RTC devices (like: https://www.adafruit.com/product/4282) require a battery.
I have rshell synchronize the time on the device with the time on the PC whenever it connects. If you have a network connection you can query an NTP server to get the current time, but otherwise there really isn't anything you can do.
I have rshell synchronize the time on the device with the time on the PC whenever it connects. If you have a network connection you can query an NTP server to get the current time, but otherwise there really isn't anything you can do.
Re: machine.RTC().datetime() gives incorrect hours, minutes, and day of the week
That makes sense, thanks!