QUERY · ISSUE
machine.RTC.init throws exception on Pyboard 1.0
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
[ports/rp2] new machine_rtc.c module
Hi
Although I was delighted to see micropython support in the new Raspberry Pi Pico, I as a bit surprised that there was no machine.RTC class for this port. So I took the plunge and began writting a basic machine_rtc.c module and learning in the process a bit about how to make an extension C module. This module is very basic for the time being (no interrupt handling) and conforms (I hope) to the interface documented in the MicroPython 1.14 official documentation.
The python test code is this:
from machine import RTC
from utime import sleep, sleep_ms
def test_main():
rtc = RTC(0)
print(rtc)
print(rtc.now())
remaining = rtc.alarm(0, 5000, repeat=False)
while (remaining >0):
print("{0:d} ms. left".format(remaining))
sleep(1)
remaining = rtc.alarm_left()
print("done")
def test_cancel():
rtc = RTC(0)
print(rtc)
print(rtc.now())
remaining = rtc.alarm(0, 5000, repeat=False)
while (remaining >0):
print("{0:d} ms. left".format(remaining))
sleep(1)
remaining = rtc.alarm_left()
rtc.cancel()
def test_1sec():
rtc = RTC(0)
rtc.init((2015, 1, 1, 1, 0, 0, 0, None))
sleep_ms(1002)
print(rtc.now())