machine.RTC documentation

Discussion about programs, libraries and tools that work with MicroPython. Mostly these are provided by a third party.
Target audience: All users and developers of MicroPython.
Post Reply
hlovatt
Posts: 62
Joined: Thu Aug 15, 2019 3:52 am
Location: Sydney

machine.RTC documentation

Post by hlovatt » Sun Apr 11, 2021 11:22 pm

Using the latest build on a PyBoard:

Code: Select all

MicroPython v1.14-68-gd4b45898f on 2021-02-18; PYBv1.1 with STM32F405RG
I'm having trouble with `machine.RTC`, the example given in the documentation doesn't work:

Code: Select all

>>> import machine
>>> rtc = machine.RTC()
So far so good, but:

Code: Select all

>>> rtc.init((2014, 5, 1, 4, 13, 0, 0, 0))
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
TypeError: function takes 1 positional arguments but 2 were given
and:

Code: Select all

>>> print(rtc.now())
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: 'RTC' object has no attribute 'now'
also the available methods don't match the documentation by quite some margin:

Code: Select all

>>> dir(rtc)
['__class__', 'calibration', 'datetime', 'info', 'init', 'wakeup']
`calibration`, `datetime`, `info`, and, `wakeup` aren't in the documentation and `init` doesn't appear to work (see above). Also the documentation mentions methods that aren't present, like `alarm`. There are no 'availability' notes in the documentation, implying that all methods in the documentation should exist.

Is there better documentation?

Thanks in advance,

Howard.

User avatar
mattyt
Posts: 342
Joined: Mon Jan 23, 2017 6:39 am

Re: machine.RTC documentation

Post by mattyt » Mon Apr 12, 2021 2:26 am

The Pyboard predates the machine API definitions; back in the day it used the original pyb API (machine evolved to be more platform agnostic than pyb). While many of the machine API's are now available on the pyboard, RTC is only half-way there. Effectively, pyb.RTC has just been aliased to machine.RTC.

So you can read the pyb.RTC docs for info on how to use the pyboard machine.RTC.

I believe the intent is, at some point, to update the pyboard machine.RTC to match the machine.RTC documentation. Any additional methods (like, say, calibrate) can move into a platform-specific module (probably stm32 or pyboard in this case).

Hope that clarifies things!

hlovatt
Posts: 62
Joined: Thu Aug 15, 2019 3:52 am
Location: Sydney

Re: machine.RTC documentation

Post by hlovatt » Mon Apr 12, 2021 6:42 am

@mattyt Thanks. Does that mean newer boards conform to machine.RTC?

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

Re: machine.RTC documentation

Post by pythoncoder » Mon Apr 12, 2021 7:10 am

My advice is to use the pyb library for the Pyboard's RTC. Its documentation is correct, unlike that of machine.rtc.

All Pyboards are compatible with pyb.
Peter Hinch

hlovatt
Posts: 62
Joined: Thu Aug 15, 2019 3:52 am
Location: Sydney

Re: machine.RTC documentation

Post by hlovatt » Wed Apr 14, 2021 4:46 am

@pythoncoder Many thanks.

Post Reply