Closed hoihu closed 3 years ago
Just tested in Thonny with the launch version of MicroPython, pico_micropython_20210121.uf2
. Code works as described, and the LED blinks for 3 seconds. There is an PIO issue with the latest release of MicroPython, see micropython/micropython#6837 for details. Try installing the launch version and see if that helps?
Thanks for testing, I'm aware of the issue you've linked, but this is not related to it. I'm using a local build that doesn't have this problem.
The problem really is that rp2
is not imported in the namespace of the file. It will work when copy&pasting via REPL / raw REPL (and perhaps Thonny is doing that?)
So to recreate the issue: copy over the pio_blink.py file, then issue the following on the REPL:
Type "help()" for more information.
>>> import pio_blink
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "pio_blink.py", line 7, in <module>
NameError: name 'rp2' isn't defined
>>>
@aallan I agree that this fix is "correct". All our micropython PIO examples are either using import rp2
at the top, and then referencing e.g. rp2.asm_pio
, rp2.PIO.OUT_LOW
and rp2.StateMachine
in the code; or they're doing from rp2 import PIO, StateMachine, asm_pio
at the top, and then referencing asm_pio
, PIO.OUT_LOW
and StateMachine
in the code.
This PR makes pio_blink.py
consistent with all our other examples. Also, it seems like https://github.com/raspberrypi/pico-micropython-examples/blob/master/pio/pio_spi.py is also missing an import rp2
line.
This PR makes
pio_blink.py
consistent with all our other examples. Also, it seems like https://github.com/raspberrypi/pico-micropython-examples/blob/master/pio/pio_spi.py is also missing an import rp2 line.
Okay thanks.
Example did run when copy&pasting in REPL, but did not when importing the file