micropython / micropython

MicroPython - a lean and efficient Python implementation for microcontrollers and constrained systems
https://micropython.org
Other
19.06k stars 7.63k forks source link

Any sample for Raspberry Pi Pico RTC? #6831

Closed pankaj-nikam closed 3 weeks ago

pankaj-nikam commented 3 years ago

Hi team,

Thank you for porting Micropython for Pico. Is there any sample for using RTC with Pico?

Thanks.

davehylands commented 3 years ago

For the time being, machine.RTC() doesn't seem to be implemented on the Pico. This means that you need to access the registers directly. There is a forum post on doing this: https://forum.micropython.org/viewtopic.php?f=15&t=9706 and I just updated rshell (in the pico branch) to take do this as well: https://github.com/dhylands/rshell/commit/cd1b5522a9991bcc83e01eb4ddc6f5146b0a980c

pankaj-nikam commented 3 years ago

Thanks for the update :) Let us hope that machine.RTC gets implemented soon 😄

aivarannamaa commented 3 years ago

@dpgeorge, can you tell us whether machine.RTC is coming soon for Pico? (If not, then I'll implement the work-around described at https://forum.micropython.org/viewtopic.php?f=15&t=9706 in the next Thonny version, but a standard solution would be so much nicer.)

kadamski commented 3 years ago

@aivarannamaa I've created a preliminary support for machine.RTC in https://github.com/micropython/micropython/pull/6928. Do you need anything else than a datetime() method?

aivarannamaa commented 3 years ago

@aivarannamaa I've created a preliminary support for machine.RTC in #6928. Do you need anything else than a datetime() method?

@kadamski, .datetime(...) would suffice for Thonny. Thank you!

Currently Thonny calls it like this

rtc.datetime(now.tm_year, now.tm_mon, now.tm_mday, now.tm_wday + 1, now.tm_hour, now.tm_min, now.tm_sec, 0)

where now is computed by CPython's datetime.datetime.now().timetuple(). Hopefully this matches your implementation :)

kadamski commented 3 years ago

@aivarannamaa wait, do you use 8 separate arguments? My implementation expects 1 argument that is a tuple of 8 integers, just like the esp32 port..

aivarannamaa commented 3 years ago

@aivarannamaa wait, do you use 8 separate arguments? My implementation expects 1 argument that is a tuple of 8 integers, just like the esp32 port.

Sorry, I got it wrong. Thonny actually also sends these components as an 8-tuple. If your method is like the one in esp32 port, then Thonny will be happy with it.

kadamski commented 3 years ago

@aivarannamaa good. I've created a precompiled version of my branch with this change, if you would like to easily test it with Thonny. See https://github.com/kadamski/micropython/releases/tag/v1.14-67-gcf6a01588%2Brp2_rpc_7cc6412

kadamski commented 3 years ago

For the time being, machine.RTC() doesn't seem to be implemented on the Pico. This means that you need to access the registers directly. There is a forum post on doing this: https://forum.micropython.org/viewtopic.php?f=15&t=9706 and I just updated rshell (in the pico branch) to take do this as well: dhylands/rshell@cd1b552

@davehylands you're also welcome to test it for your case. I would be glad to get some feedback about it. See my comment above for the details.

aivarannamaa commented 3 years ago

@kadamski, with your uf2, Thonny seems to set UTC without problems. Good work!

kadamski commented 3 years ago

@aivarannamaa thanks, could you put this info to my pull request https://github.com/micropython/micropython/pull/6928 to show it was verfied by somebody else than me? :)

kadamski commented 3 years ago

@aivarannamaa thanks, could you put this info to my pull request https://github.com/micropython/micropython/pull/6928 to show it was verfied by somebody else than me? :)

The-Bow-Hunter commented 3 years ago

hey, just asking but did someone put it in the documentation befor it was on the corresponding stable build? https://docs.micropython.org/en/latest/rp2/quickref.html#real-time-clock-rtc states taht it is there, but i can not import it there

robert-hh commented 3 years ago

Try the daily update of the firmware.

The-Bow-Hunter commented 3 years ago

in 1.16. it works fine now. There seems to be a bug that when you are on the docu page for 1.15. you can not see that there is a 1.16. so i got confused. Thanks

The-Bow-Hunter commented 3 years ago

Maybe this issue should get closed then

zzzbatmand commented 1 year ago

The RP2 machine.RTC.datetime() function, returns the wrong order of time. The function returns (year, month, day, day_of_the_week, hour, minute, second, 0) Where normally "day_of_the_week" is second-to-last. The correct format should be as follows (year, month, day, hour, minute, second, day_of_the_week, day_of_the_year) As shown in the RP2/modutime.c module.

robert-hh commented 1 year ago

The format of rtc.datetime() and time.localtime() is indeed different, and that's true for all ports. That may be irritating. And there are quite a few inconsistencies between the ports and documentation with the RTC module.

zzzbatmand commented 1 year ago

The format of rtc.datetime() and time.localtime() is indeed different, and that's true for all ports. That may be irritating. And there are quite a few inconsistencies between the ports and documentation with the RTC module.

Is there a reason for this? Otherwise I have made the changes as a pull request here.

robert-hh commented 1 year ago

Is there a reason for this?

No. Just history. I made an issue report, and that should be fixed for all ports. But the only consistent thing between all ports is the rtc.datetime() format as it is now. And therefore it should be kept.

jonnor commented 3 weeks ago

I believe this issue can be closed, as the associated PR have been merged.