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

Overview

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!

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

    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.

    opened by root42 4
  • num_leds not referenced for i and j

    num_leds not referenced for i and j

    In the following file, instead of referencing num_leds, the value for i and j is fixed to 30: https://github.com/benevpi/pico_python_ws2812b/blob/226330d7b1b140c7d462da958809714384ffb3fb/examples/flash.py#L4-L9

    Thanks! Martin

    opened by Martin-HiPi 2
  • Add .fill in the Readme

    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 ;)

    opened by P-C-R 1
  • mixed Green and Blue in leds1.set_pixel(x,a,b,c)

    mixed Green and Blue in leds1.set_pixel(x,a,b,c)

    When I use leds1.set_pixel it is leds1.set_pixel(x,Red,Blue,Green) instead of usual and documentred Red, Green Blue. In leds1.fill(i,i,i) is OK.

    opened by lamasek 2
  • I did a little bit of playin around

    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.

    opened by IanSMoyes 0
  • Weird results in interactive mode

    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.

    opened by benevpi 3
Owner
null
A rubiks cube timer using a distance sensor and a raspberry pi 4, and possibly the pi pico to reduce size and cost.

distance sensor cube timer A rubiks cube timer using a distance sensor and a raspberry pi 4, and possibly the pi pico to reduce size and cost. How to

null 3 Feb 21, 2022
A Python class for controlling the Pimoroni RGB Keypad for Raspberry Pi Pico

rgbkeypad A Python class for controlling the Pimoroni RGB Keypad for the Raspberry Pi Pico. Compatible with MicroPython and CircuitPython. keypad = RG

Martin O'Hanlon 43 Nov 11, 2022
Raspberry Pi Pico development platform for PlatformIO

Raspberry Pi Pico development platform for PlatformIO A few words in the beginning Before experimental please Reinstall the platform Version: 1.0.0 Th

Georgi Angelov 160 Dec 23, 2022
Raspberry Pi Pico support for VS Code

Pico-Go VS Code Extension Pico-Go provides code auto-completion and allows you to communicate with your Raspberry Pi Pico board using the built-in REP

Chris Wood 114 Dec 28, 2022
A Raspberry Pi Pico powered Macro board, like a Streamdeck but cheaper and simpler.

Env-MCRO A Raspberry Pi Pico powered Macro board, like a Streamdeck but cheaper and simpler. (btw this image is a bit outdated, some of the silkscreen

EnviousData 68 Oct 14, 2022
Raspberry Pi Pico and LoRaWAN from CircuitPython

Raspberry Pi Pico and LoRaWAN from CircuitPython Enable LoRaWAN communications on your Raspberry Pi Pico or any RP2040-based board using CircuitPython

Alasdair Allan 15 Oct 8, 2022
A Raspberry Pi Pico plant sensor hub coded in Micropython

plantsensor A Raspberry Pi Pico plant sensor hub coded in Micropython I used: 1x Raspberry Pi Pico - microcontroller 1x Waveshare Pico OLED 1.3 - scre

null 78 Sep 20, 2022
Raspberry Pi Pico Escape Room game.

Pico Escape Room Raspberry Pi Pico Escape Room game. Parts Raspberry Pi Pico Set of 2 x 20-pin Headers for Raspberry Pi Pico 4PCS Breadboards Kit Incl

Kevin Thomas 5 Feb 2, 2022
An open source operating system designed primarily for the Raspberry Pi Pico, written entirely in MicroPython

PycOS An open source operating system designed primarily for the Raspberry Pi Pico, written entirely in MicroPython. "PycOS" is an combination of the

null 8 Oct 6, 2022
New armachat based on Raspberry Pi PICO an Circuitpython code

Armachat-circuitpython New Armachat based on Raspberry Pi PICO an Circuitpython code Software working features: send message with header and store to

Peter Misenko 44 Dec 24, 2022
Turn your Raspberry Pi Pico into a USB Rubber Ducky

pico-ducky Turn your Raspberry Pi Pico into a USB Rubber Ducky Install Requirements CircuitPython for the Raspberry Pi Pico adafruit-circuitpython-bun

Konstantinos 5 Nov 8, 2022
Play music on Raspberry Pi Pico Without CPU involvement

MicroPython_PIO_Music_DMA Play music on Raspberry Pi Pico Without CPU involvement This is based on PIOBeep (https://github.com/benevpi/pico_pio_buzz)

null 3 Nov 27, 2022
A simple portable USB MIDI controller based on Raspberry-PI Pico and a 16-button keypad, written in Circuit Python

RPI-Pico-16-BTn-MIDI-Controller-using-CircuitPython A simple portable USB MIDI controller based on Raspberry-PI Pico, written in Circuit Python. Link

Rounak Dutta 3 Dec 4, 2022
Raspberry Pi Pico as a Rubber Ducky

Raspberry-Pi-Pico-as-a-Rubber-Ducky Kurulum Raspberry Pi Pico cihazınız için CircuitPython'u indirin. Boot düğmesine basılı tutarken cihazı bir USB ba

Furkan Enes POLATOĞLU 6 Dec 13, 2022
A circle of LEDs

This repository contains all the design files, production files and example code for a simple circular LED display.

Pim de Groot 15 Aug 21, 2022
This application works with serial communication. Use a simple gui to send and receive serial data from arduino and control leds and motor direction

This application works with serial communication. Use a simple gui to send and receive serial data from arduino and control leds and motor direction

ThyagoKZKR 2 Jul 18, 2022
Hourglass on the pi pico using circuitpython

hourglass-on-pico "Hourglass" on the raspberry pi pico using circuitpython circuitpython version 7.0.0 Components used: Raspberry Pi Pico ADXL345 acce

null 4 Jul 18, 2022
USB Rubber Ducky with the Rasberry Pi pico microcontroller

pico-ducky Install Install and have your USB Rubber Ducky working in less than 5 minutes. Download CircuitPython for the Raspberry Pi Pico. Plug the d

AnOnYmOus001100 3 Oct 8, 2022
A modular sequencer based on Pi Pico & EuroPi

PicoSequencer A modular sequencer based on Pi Pico & EuroPi by Zeno Van Moerkerke / Keurslager Kurt For now it is 'only' a trigger sequencer, but I si

null 5 Oct 27, 2022