Hi All
I am trying to run neopixels on RPI Pico and also on Waveshare RP2040 zero.
My end plan is to control pattern and brightness with push buttons.
This first piece of code comes from Paul McWhorter lesson 52 I think and works.
When copied to Thonny it runs without a problem on a Pico and the following line does not bring up an error “pix=neopixel.NeoPixel(Pin(pixPin),pixSize)”. The entire code is next
import neopixel
from machine import Pin
import time
pixPin=0
pixSize=5
pix=neopixel.NeoPixel(Pin(pixPin),pixSize)
red=(255,0,0)
green=(0,255,0)
blue=(0,0,255)
orange=(255,100,0)
white=(255,255,255)
pix[0]=red
pix[4]=orange
pix[1]=white
pix[3]=green
pix[2]=blue
pix.write()
However the following code from the Nerd Cave brings up the error I will show after the code and I have many other pieces of code to which I get exactly the same responce from Thonny, when I try and compile it.
Code from Nerd Cave
# Example showing how functions, that accept tuples of rgb values,
# simplify working with gradients
import time
from neopixel import Neopixel
numpix = 5
strip = Neopixel(numpix, 1, 1, "GRB")
# strip = Neopixel(numpix, 0, 0, "GRBW")
red = (255, 0, 0)
orange = (255, 50, 0)
yellow = (255, 100, 0)
green = (0, 255, 0)
blue = (0, 0, 255)
indigo = (100, 0, 90)
violet = (200, 0, 100)
colors_rgb = [red, orange, yellow, green, blue, indigo, violet]
# same colors as normaln rgb, just 0 added at the end
colors_rgbw = [color+tuple([0]) for color in colors_rgb]
colors_rgbw.append((0, 0, 0, 255))
# uncomment colors_rgbw if you have RGBW strip
colors = colors_rgb
# colors = colors_rgbw
step = round(numpix / len(colors))
current_pixel = 0
strip.brightness(50)
for color1, color2 in zip(colors, colors[1:]):
strip.set_pixel_line_gradient(current_pixel, current_pixel + step, color1, color2)
current_pixel += step
strip.set_pixel_line_gradient(current_pixel, numpix - 1, violet, red)
while True:
strip.rotate_right(1)
time.sleep(0.042)
strip.show()
error from Nerd Cave code
“Traceback (most recent call last):
File “”, line 5, in
ImportError: can’t import name Neopixel”
I have modified the the Nerd Cave code as seen below to try and make it similar to the Paul McWhorter code but I still get the same error
# Example showing how functions, that accept tuples of rgb values,
# simplify working with gradients
import time
import neopixel #import Neopixel
from machine import Pin
#import rp2
# NUM_LEDS = 8
pixPin = 1
brightness = 0.5
pixSize = 5
pix = neopixel.Neopixel(Pin(pixPin),pixSize)
#pixSize = neopixel.Neopixel(numpix, 0, 28, "GRB")
# strip = Neopixel(numpsix, 0, 0, "GRBW")
red = (255, 0, 0)
orange = (255, 50, 0)
yellow = (255, 100, 0)
green = (0, 255, 0)
blue = (0, 0, 255)
indigo = (100, 0, 90)
violet = (200, 0, 100)
colors_rgb = [red, orange, yellow, green, blue, indigo, violet]
# same colors as normaln rgb, just 0 added at the end
colors_rgbw = [color+tuple([0]) for color in colors_rgb]
colors_rgbw.append((0, 0, 0, 255))
# uncomment colors_rgbw if you have RGBW strip
colors = colors_rgb
# colors = colors_rgbw
step = round(pixSize / len(colors))
current_pixel = 0
strip.brightness(50)
for color1, color2 in zip(colors, colors[1:]):
strip.set_pixel_line_gradient(current_pixel, current_pixel + step, color1, color2)
current_pixel += step
strip.set_pixel_line_gradient(current_pixel, pixSize - 1, violet, red)
while True:
strip.rotate_right(1)
time.sleep(0.15)
strip.show()
I expect the explanation is fairly simple for most , but I sure can’t see it .
Any assistance greatly appreciated
cheers
Nick