Skip to content

Conversation

hoihu
Copy link
Contributor

@hoihu hoihu commented Feb 4, 2021

Example did run when copy&pasting in REPL, but did not when importing the file

@aallan aallan added the invalid This doesn't seem right label Feb 4, 2021
@aallan
Copy link
Contributor

aallan commented Feb 4, 2021

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?

@aallan aallan closed this Feb 4, 2021
@hoihu
Copy link
Contributor Author

hoihu commented Feb 4, 2021

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
>>> 

@lurch
Copy link
Contributor

lurch commented Feb 4, 2021

@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.

@aallan aallan reopened this Feb 4, 2021
@aallan aallan added bug Something isn't working and removed invalid This doesn't seem right labels Feb 4, 2021
@aallan
Copy link
Contributor

aallan commented Feb 4, 2021

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.

@aallan aallan merged commit 16c0439 into raspberrypi:master Feb 4, 2021
aallan pushed a commit that referenced this pull request Feb 4, 2021
Missing import, see comments in #14
@lurch lurch mentioned this pull request Feb 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants