Page 1 of 1

machine.RTC documentation

Posted: Sun Apr 11, 2021 11:22 pm
by hlovatt
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.

Re: machine.RTC documentation

Posted: Mon Apr 12, 2021 2:26 am
by mattyt
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!

Re: machine.RTC documentation

Posted: Mon Apr 12, 2021 6:42 am
by hlovatt
@mattyt Thanks. Does that mean newer boards conform to machine.RTC?

Re: machine.RTC documentation

Posted: Mon Apr 12, 2021 7:10 am
by pythoncoder
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.

Re: machine.RTC documentation

Posted: Wed Apr 14, 2021 4:46 am
by hlovatt
@pythoncoder Many thanks.