pi_pico_neopixel icon indicating copy to clipboard operation
pi_pico_neopixel copied to clipboard

Not working on Pi Pico with version 1.91 UF2 Micropython

Open tonygo opened this issue 2 years ago • 4 comments

Kept getting this error message with UF2 v1.91 - It worked as expected with v 1.16: ImportError: can't import name Neopixel

I think Micropython have reserved the name Neopixel and have implemented basic RGB Neopixels on ESP microprocessors but not Pi Pico.

Good news - I've found a work round and it works for RGBW Neopixels. Rename the library argbled_lib.py (addressable RGB LEDs) Change the class name from Neopixel to Argbled and call from main program with:

from argbled_lib import Argbled

Thank you for providing this library - really useful.

tonygo avatar Jul 02 '22 13:07 tonygo

Thanks for this information. I'm not quite sure what to do in this case. As you said, an option would be to rename the class, but that'd mean users will need to change existing code. I'll see what I can do, but most likely rename will be required.

blaz-r avatar Jul 05 '22 15:07 blaz-r

@tonygo I finally got the chance to test this out and it works fine for me. I tested with latest version of UF2 file (v1.19.1) and I had no problems with importing. Are you sure you saved the file as "neopixel.py" on PiPico?

blaz-r avatar Jul 10 '22 10:07 blaz-r

I've been away and just tried this again. Thanks for getting back to me.

I download the latest UF2 for Pi Pico, your neopixel.py and the Rainbow demo. Using an Adafruit 16 Ring RGBW. I saved it in the lib folder with neopixel.py as the file name. I still get a fail to import Neopixel

MicroPython v1.19.1 on 2022-06-18; Raspberry Pi Pico with RP2040

Type "help()" for more information.

%Run -c $EDITOR_CONTENT Traceback (most recent call last): File "", line 2, in ImportError: can't import name Neopixel

Its the name, Neopixel, it does not like. It find the library but it objects to the Neopixel name.

I'm happy with my work-around and cannot see why I get this error, which I've not seen before.

Best wishes Tony

tonygo avatar Jul 16 '22 08:07 tonygo

So, I get this error if library file is not correctly saved on pi pico.

%Run -c $EDITOR_CONTENT
Traceback (most recent call last):
  File "<stdin>", line 3, in <module>
ImportError: can't import name Neopixel

So since you say changing the name works, it can be either problem in how micropython searches for files and classes or that you'll need to save the library on pico as shown in Initialization wiki page.

I hope this helps resolve the situation, in other case I guess renaming the file if needed can work.

blaz-r avatar Jul 22 '22 12:07 blaz-r

Closing due to inactivity.

blaz-r avatar Apr 17 '23 10:04 blaz-r

I got the same error you mention. You can keep the name neopixel.py, just don't save it in /lib, for some reason micropython doesn't like that name in that folder.

neopixel_lib_err

Kyuchumimo avatar Jun 23 '23 09:06 Kyuchumimo

V1.20.0 is out and this contain a neopixel library. It is much easier. Have a look here for a tutorial: https://thepihut.com/blogs/raspberry-pi-tutorials/maker-advent-calendar-day-12-rgb-led-strip Hope this helps Tony

tonygo avatar Jun 23 '23 11:06 tonygo

https://thepihut.com/blogs/raspberry-pi-tutorials/maker-advent-calendar-day-12-rgb-led-strip

Look here to find a tutorial. The latest version uf2 v1.20.0 contains a Neopixel library built in with the same name. It is very easy to use.

tonygo avatar Jun 23 '23 11:06 tonygo

@tonygo You're right, this explains why the error when importing the library:

neopixel_lib_err-1

https://docs.micropython.org/en/latest/library/neopixel.html https://raw.githubusercontent.com/micropython/micropython-lib/master/micropython/drivers/led/neopixel/neopixel.py

Kyuchumimo avatar Jun 23 '23 19:06 Kyuchumimo

Hello. So the issue only occurs if code is out inside /lib? If that's the case I'll mention that in documentation.

blaz-r avatar Jun 23 '23 20:06 blaz-r

@blaz-r Correct, but only occurs on ESP8266, ESP32 and Raspberry Pi RP2xxx boards.

Kyuchumimo avatar Jun 23 '23 21:06 Kyuchumimo