Git Product home page Git Product logo

pi_pico_neopixel's Introduction

pi_pico_neopixel

a library for using ws2812b and sk6812 leds (aka neopixels) with Raspberry Pi Pico

example

Detailed documentation can be found on Wiki page.

Quick start guide

You'll first need to save the neopixel.py file to your device (for example, open it in Thonny and go file > save as and select MicroPython device. Give it the same name). Once it's there, you can import it into your code.

Initialization

You create an object with the parameters number of LEDs, state machine ID, GPIO number and mode (RGB or RGBW) in that order. So, to create a strip of 10 leds on state machine 0 and GPIO 0 in RGBW mode you use:

from neopixel import Neopixel

pixels = Neopixel(10, 0, 0, "RGBW")

Mind that you can use whichever order of RGB / RGBW you want (GRB, WRGB, GRB, RGWB ...). This only represents order of data sent to led-strip, all functions still work with RGBW order. Exact order of leds should be on package of your led-strip. (My BTF-lights sk6812 has GRBW).

Usage

This class has many methods, two main ones being show() which sends the data to the strip, and set_pixel which sets the color values for a particular LED. The parameters are LED number and a tuple of form (red, green blue) or (red, green, blue, white) with the colors taking values between 0 and 255.

At the moment, this isn't working with the interpreter, so you have to run it from a file. Looks like it's running just too slow to keep up with the PIO buffer from the interpreter. The key methods are set_pixel(n (r,g,b)), set_pixel_line(p1, p2, (r, g, b)) which sets a row of pixels from pixel p1 to pixel p2 (inclusive), and fill((r,g,b)) which fills all the pixels with the color r, g, b. If you want to use the library for RGBW, each function works the same just with last parameter being "white": set_pixel(num, (r, g, b, w))

Examples

pixels.set_pixel(5, (10, 0, 0))
pixels.set_pixel_line(5, 7, (0, 10, 0))
pixels.fill((20, 5, 0))

rgbw1 = (0, 0, 50, 0)
rgbw2 = (50, 0, 0, 250)
pixels.set_pixel(42, (0, 50, 0, 0))
pixels.set_pixel_line(5, 7, rgbw1)
pixels.set_pixel_line_gradient(0, 13, rgbw1, rgbw2)

For new settings to take effect you write:

pixels.show()

For more examples, check examples folder and documentation.

HSV colors

Library also supports HSV colors. For example you can look at smoothRinbow.py. To use HSV colors, call colorHSV(hue, sat, val) function with hue, saturation and value as parameters. The function returns rgb tuple that you can then use in all other functions.

Hue should be between 0 and 65535. When it becomes larger it just rolls over (65536 -> 0). Saturation and value must be in range from 0 to 255. 255 saturation means just hue, and 255 value is maximum brightness. For more info about HSV colors you can check out Adafruit NeoPixel library documentation and scroll down to HSV section.

color = pixels.colorHSV(32000, 255, 200)
pixels.fill(color)
pixels.show()

Library is extended verison of https://github.com/blaz-r/pico_python_ws2812b, originally forked from https://github.com/benevpi/pico_python_ws2812b.

pi_pico_neopixel's People

Contributors

andrewdazotus avatar blaz-r avatar footleg avatar mathemmagician avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pi_pico_neopixel's Issues

Pico W Errno 12 ENOMEM

I'm running a Pico W with firmware 1.19.1 and I'm getting this error when running the rainbow.py example after about 8 or 9 times of running it through Thonny without detaching the PI.

MicroPython v1.19.1 on 2022-10-05; Raspberry Pi Pico W with RP2040
Type "help()" for more information.

%Run -c $EDITOR_CONTENT
Traceback (most recent call last):
File "", line 5, in
File "neopixel.py", line 97, in init
OSError: [Errno 12] ENOMEM

Multiple outputs

I'm interested in running 3 or 4 PIO channels at the same time driving WS2812 chains. I have seen the article about using one PIO and a shift register to drive up to 8 chains; I'd prefer to avoid the extra hardware and code to 'slice' the LED data.
Has anyone run multiple PIOs to drive individual I/O pins?

No module rp2

I am getting error with import rp2
says there is no module named rp2

Neopixel not working

Hello, I have a raspberry pi pico clone that has an integrated neopixel (WS2812) on pin GPIO23.

I tried using this library in order to control it but it doesn't turn on at all.

The first thing I tried was the example "rainbow.py" and that example happens to have the mode as "RGBW".
Now from what I can tell, an WS2812 neopixel supports only RGB so that is my only clue as to what went wrong.

Is it the case that I blew the neopixel because of the RGBW mode or am I doing something wrong with my code?

RGB shows as GRB

Running the library on my computer in "RGB":
RED = (0,10,0) instead of (10,0,0)

Reading Neopixel data

Well, I know this is a bit offtopic but since the code of the neopixel class looks so gorgeous I thought I might just give it a try:

I'm desperately looking for a way to read the first 3 RGBW pixels (3x 32 bit) of a Neopixel datastream with the pico using micropython and PIO. I'd love to use the data to drive stepper motors.

Could someone give me a hint if this is even possible?

Thanks a lot in advance :-)

RGB WS2812 problem: must init with GRB in stead of RGB

I'm using a RGB ES2812 in an Elektor Pi Pico experimenting kit with 8 leds and while using your library I get wrong colors when using RGB. Using GRB solves this. As example I use rainbow.py.
The init is done as : strip = Neopixel(numpix, 0, 16, "GRB") numpix is 8.

Fast Clear

Not really an issue, more of a question.

What is the fastest way to clear the led lights?

Tried 2 things so far:

  • strip.fill( ( 0, 0, 0) ) - very slow
  • strip.pixels = array.array("I", [0 for _ in range(strip.num_leds)]) - much faster, but seems hacky

Sometimes on .show() the lights are all set wrong?

This is a great project. I'm using it as the light controller for LEDs around my bed.
One thing I've seen though that I haven't been able to solve is sometime when I update the lights. They seem to get the wrong data. Usually it's like the data is offset. Often it manifests as the entire strand goes to full white for just the one frame.

When I use the examples I don't see the problem. It only seems to be when I'm doing a lot of manual setting of pixels using slices. One reason why it hasn't been such a big deal is because I'm using Home Assistant to send MQTT commands to the Pico, and that's usually just one update at a time. But it's become clear that the problem happens like 1 in 200 updates, roughly. So, when I'm updating manually I almost never see it. But when I'm trying to use a custom animation with a fair amount of complexity, I see lots of wrong updates.

I suppose it's possible it may not be a software thing. But I'd like to know if you've seen something like this before. (Also, everything is sharing a ground correctly)

Sorry if this isn't the right place for this.

Clear()

Strip.clear does not seem to be defined and throws up an error in my code on a Pico running under Thonny. All other commands seem fine

Not working on Pi Pico with version 1.91 UF2 Micropython

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.

Very buggy for 35762-OP LED - help needed

I'm trying to run the examples on a Pi Pico W with an array of 10 LEDs (https://www.mpja.com/download/35762opdata.pdf) .
I thought these are compatible with this library. Maybe they aren't?

When I run the rainbow.py example , it runs OK the first time, then all leds bug out, flicker and for some reason stay red.
The brightness function also seems not to work at all.

Congratulations on the project, really cool idea.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.