Closed tonygo closed 1 year ago
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.
@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?
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
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.
Closing due to inactivity.
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.
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
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 You're right, this explains why the error when importing the library:
https://docs.micropython.org/en/latest/library/neopixel.html https://raw.githubusercontent.com/micropython/micropython-lib/master/micropython/drivers/led/neopixel/neopixel.py
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 Correct, but only occurs on ESP8266, ESP32 and Raspberry Pi RP2xxx boards.
Same error on my "Tiny2040". Tonygo's fix seems to have worked. Thank you.
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.