[Solved] RTC module behaving differently in REPL and main.py

General discussions and questions abound development of code with MicroPython that is not hardware specific.
Target audience: MicroPython Users.
Post Reply
User avatar
thoralt
Posts: 11
Joined: Wed Jul 02, 2014 11:22 am
Location: Germany

[Solved] RTC module behaving differently in REPL and main.py

Post by thoralt » Fri Mar 04, 2016 8:48 am

Dear forum users,

I need your help. I stumbled across an issue which I'm not able to sort out. I'm trying to use the RTC module and therefore visited its documentation page. When I type the example code into the REPL console, everything works as expected:

Code: Select all

>>> rtc = pyb.RTC()
>>> rtc.datetime((2014, 5, 1, 4, 13, 0, 0, 0))
>>> print(rtc.datetime())
(2014, 5, 1, 4, 13, 0, 4, 26)
If I copy the lines to main.py:

Code: Select all

import pyb

rtc = pyb.RTC
rtc.datetime((2014, 5, 1, 4, 13, 0, 0, 0))
print(rtc.datetime())
and try to run it using the serial console and Ctrl+D, I get the following, somewhat unsatisfying result:

Code: Select all

PYB: sync filesystems
PYB: soft reboot
Traceback (most recent call last):
  File "main.py", line 4, in <module>
TypeError: argument has wrong type
MicroPython v1.6-126-gf70873d on 2016-03-04; PYBv1.0 with STM32F405RG
Type "help()" for more information.
>>>
MicroPython complains about a wrong type, but since the exact same code worked in REPL, I cannot figure out what I need to fix. This might not even be related to the RTC module, could be a general fault of mine, but I'm not yet able to see where I'm wrong, so please give me a hint.

I first tried with MicroPython v1.5.2 and then upgraded to latest v1.6-126, but behaviour is the same.

Thanks for any help.
Thoralt
Last edited by thoralt on Fri Mar 04, 2016 9:45 am, edited 1 time in total.

User avatar
dhylands
Posts: 3821
Joined: Mon Jan 06, 2014 6:08 pm
Location: Peachland, BC, Canada
Contact:

Re: RTC module behaving differently in REPL and main.py

Post by dhylands » Fri Mar 04, 2016 9:33 am

Your main.py example is missing the parenthesis on the call to pyb.RTC It should be pyb.RTC()

User avatar
thoralt
Posts: 11
Joined: Wed Jul 02, 2014 11:22 am
Location: Germany

Re: RTC module behaving differently in REPL and main.py

Post by thoralt » Fri Mar 04, 2016 9:45 am

dhylands wrote:Your main.py example is missing the parenthesis on the call to pyb.RTC It should be pyb.RTC()
Now that is embarrassing :oops:

Fixed it, works as expected. Thanks a lot, Dave!

Thoralt

Post Reply