← index #5545PR #5553
Duplicate · high · value 1.091
QUERY · ISSUE

machine.RTC.init throws exception on Pyboard 1.0

openby peterhinchopened 2020-01-16updated 2021-02-07
docsport-stm32

The code example in the docs fails with a surprising traceback.

rtc = machine.RTC()
rtc.init((2014, 5, 1, 4, 13, 0, 0, 0))

Outcome:

MicroPython v1.12-61-g0f16eeab2 on 2020-01-16; PYBv1.0 with STM32F405RG
Type "help()" for more information.
>>> 
>>> from machine import RTC
>>> rtc = RTC()
>>> 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
CANDIDATE · PULL REQUEST

docs/library/machine.RTC.rst Fix example code, document datetime method.

closedby peterhinchopened 2020-01-21updated 2023-01-25
docs

This is the minimum change to fix the example code so it actually runs.

Unfortunately documenting the RTC class is difficult because it has been implemented differently for each platform. I checked STM, ESP8266 and ESP32. All implement datetime. Implementation of init is platform dependent: STM accepts no args. ESP8266 does not implement it while ESP32 requires a datetime tuple. Further, each platform implements a different set of methods and some documented methods are not implemented on any of these platforms: for example the now method.

Methods such as calibrate are inherently hardware dependent but where a method is implemented across platforms its calling signature should (in my view) be consistent.

There are other platforms where I don't own hardware so can't test. I'm stumped as to how properly to document this class.

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied