Am I not using pyb.main() properly?

The official PYBD running MicroPython, and its accessories.
Target audience: Users with a PYBD
Post Reply
User avatar
mathieu
Posts: 88
Joined: Fri Nov 10, 2017 9:57 pm

Am I not using pyb.main() properly?

Post by mathieu » Fri Sep 13, 2019 6:00 pm

On a pyboard-D with the latest firmware, my `boot.py` is:

Code: Select all

import pyb
pyb.main('main.py')
And my `main.py` is;

Code: Select all

from pyb import Timer, LED
timer = Timer(14)
timer.callback(lambda x: LED(2).toggle())
timer.init(freq = 4)
When I switch the board off and then back on, the green LED stays off, but it starts blinking as expected whenever I soft reboot from the REPL. When I reboot using the RST button, the LED also stays off.

Is this expected? Am I missing something obvious?

User avatar
Roberthh
Posts: 3667
Joined: Sat May 09, 2015 4:13 pm
Location: Rhineland, Europe

Re: Am I not using pyb.main() properly?

Post by Roberthh » Fri Sep 13, 2019 6:33 pm

It's more how the timer is set up. If I put that all into a single call, it works:

Code: Select all

from pyb import Timer, LED
timer = Timer(14, callback=lambda x: LED(2).toggle(), freq=4)
A look into the sources would reveal the reason.
b.t.w.
pyb.main("main.py")
is obsolete, because main.py is the default.

Edit: It works too if time.callback() is the last line in the sequence.
Edit2: As expected: the call to init() resets the callback. default is None.

Post Reply