GithubHelp home page GithubHelp logo

pico_python_ws2812b's Introduction

Retired

This library is now retired and won't be getting updates. There's an improved version here: https://github.com/blaz-r/pi_pico_neopixel This version extends the code here and includes support for RGBW LEDs as well as RGB leds with the R, G and B components in a different order.

I'll leave the code here for the foreseeable future, so feel free to use it, extend it or modify it as you see fit, but the above library is an improvement.

pico_ws2812b

a library for using WS2812b leds (aka neopixels) with Raspberry Pi Pico

neopixels in action

You'll first need to save the ws2812b.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.

You create an object with the parameters number of LEDs, state machine ID and GPIO number in that order. so, to create a strip of 10 leds on state machine 0 and GPIO 0, you use:

pixels = ws2812b.ws2812b(10,0,0)

This object has two methods, show() which sends the data to the strip, and set_pixel which sets the colour values for a particular LED. The parameters are LED number, red, green, blue with the colours 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(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 colour r,g,b.

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

Pull requests are open if you'd like more features!

pico_python_ws2812b's People

Contributors

benevpi avatar oliverdew avatar the-spirit avatar timmillwood 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

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

pico_python_ws2812b's Issues

ws2812b

Hi, which array lib is the ws2812b lib using?
Thank you.

No Module 'array'

I'm getting an error indicating that I need a module 'array' to import.

Where do I locate the appropriate 'array' module to load on the pico?

I did a little bit of playin around

I'm sorry, I'm VERY new to all this git hub stuff (I only recently rediscovered coding) so, if this is an inappropriate way to share my experiment, I'm sorry, send assassins to my home.

Anyway, I'm getting better at Python and thought I'd have a look at your library.

https://github.com/IanSMoyes/SpiderPi/blob/master/Lights/RPi_Pico/code/NeopixelPIO.py

I ported a couple of lines for CircuitPython instead of MicroPython (I prefer it), added support for GRB and RBGW LEDs, added support for autoshow & some general personal preference stuff.

I'm not sure if you can pass "pull_thresh" to "rp2.asm_pio" as a variable. If so, it would take out a LOT of repetition I added to accommodate the 4 colour lights.

I haven't been able to try it yet but. I'd love to hear your comments & feedback.

Thanks for all your hard work.

Add .fill in the Readme

Add in the Readme that pixels.fill(r,g,b) will fill the whole Strip!

But i really Love the Work. Only working with PIO seems so useless with micropython ;)

No output on GPIO when using this lib, but okay when using a simple test program

I have tried your library, but there is no output (checked with a scope) on the GPIO pin, however all is fine when using this test program:

from machine import Pin
from rp2 import PIO, StateMachine, asm_pio

@asm_pio(set_init=PIO.OUT_LOW)
def square():
    wrap_target()
    set(pins, 1)
    set(pins, 0)
    wrap()
    
sm = rp2.StateMachine(0, square, freq=2000, set_base=Pin(2))

sm.active(1)

The test program for your library looks like this:

import ws2812b
import time

i = 0
di = 1
pixels = ws2812b.ws2812b(64,0,2)
while True:
    if i > 20 or i < 0:
        di = -di
    pixels.fill(i,i,i)
    time.sleep(0.05)
    i = i + di

Attaching a 8x8 LED array leads to nothing, probing GPIO2 with my scope also shows nothing, in contrast to the first test program. I had a look at the library code, but it looked fine to me, however I am new to the Pico, so can't really say much about it.

Brightness?

Brilliant library - is there an example of how to use brightness?

Ignore me!

pixels.brightness()

Only 1 led working

the code seems to be only updating 1 led @ present - will break out my scope later to see if I can see any thing obvious with my setup

Weird results in interactive mode

Sometimes I'm getting weird results when using the interactive REPL. No idea why. I'm investigating. I've just put this issue here incase anyone else comes across it.

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.