Code Monkey home page Code Monkey logo

rpi-pico-ws2812's Introduction

Raspberry Pi Pico WS2812B Ring Light Control

Raspberry Pi Pico RGB LED (WS2812) Ring Light Control with MicroPython

Get your 16-Pixel RGB LED Ring Light at: https://makersportal.com/shop/16-pixel-rgb-led-ring-light
Follow Along with the full tutorial at: https://makersportal.com/blog/ws2812-ring-light-with-raspberry-pi-pico

JUMP TO:

- Wiring Diagram
- MicroPython State Machine
- WS2812 Algorithm Examples
- Google Home and Amazon Alexa LED Emulator

The RPi Pico WS2812 library can be downloaded using git:

git clone https://github.com/makerportal/rpi-pico-ws2812

- Wiring Diagram -

The wiring diagram between the Raspberry Pi Pico and a 16-pixel RGB LED ring light is shown below:

Wiring Diagram

The pinout wiring is also given in the table below:

Power Supply Pico Ring Light
+ N/A 5V
N/A GPIO13 DI
- GND GND

Most of the GPIO pins can be used to control the WS2812 LED array, thus, the specification of GPIO13 for controlling the light is arbitrary. Be sure to change the pin in the codes as well, if using another pin for wiring.

- MicroPython State Machine -

The 16-Pixel RGB LED ring light array will be controlled using the scheme outlined in the Raspberry Pi Pico MicroPython getting started document, where we can get started with the tutorial entitled “Using PIO to drive a set of NeoPixel Ring (WS2812 LEDs).” The tutorial contains a script that will be used to create a state machine on the RPi Pico. The state machine will be used to control the LEDs on the ring light using a single pin on the Pico (GPIO13 in the wiring above). The full MicroPython example script can also be found at the Raspberry Pi Pico’s NeoPixel Ring repository.

The code to start the state machine on the Pico's GPIO pin #13 is given below:

import array, time
from machine import Pin
import rp2
#
############################################
# RP2040 PIO and Pin Configurations
############################################
#
# WS2812 LED Ring Configuration
led_count = 16 # number of LEDs in ring light
PIN_NUM = 13 # pin connected to ring light
brightness = 0.5 # 0.1 = darker, 1.0 = brightest

@rp2.asm_pio(sideset_init=rp2.PIO.OUT_LOW, out_shiftdir=rp2.PIO.SHIFT_LEFT,
             autopull=True, pull_thresh=24) # PIO configuration

# define WS2812 parameters
def ws2812():
    T1 = 2
    T2 = 5
    T3 = 3
    wrap_target()
    label("bitloop")
    out(x, 1)               .side(0)    [T3 - 1]
    jmp(not_x, "do_zero")   .side(1)    [T1 - 1]
    jmp("bitloop")          .side(1)    [T2 - 1]
    label("do_zero")
    nop()                   .side(0)    [T2 - 1]
    wrap()


# Create the StateMachine with the ws2812 program, outputting on pre-defined pin
# at the 8MHz frequency
state_mach = rp2.StateMachine(0, ws2812, freq=8_000_000, sideset_base=Pin(PIN_NUM))

# Activate the state machine
state_mach.active(1)

The snippet of code given above will be used for each algorithm used to test the 16-pixel WS2812 LED ring light.

- WS2812 Algorithm Examples -

Example output for: -/tests/ws2812_simple.py

LED Array Loop Demo

Example output for:

LED Array Loop Demo

- Google Home and Amazon Alexa LED Emulator -

In the final example script, routines for emulating Google Home's quad-color rotating routine is given, along with the rotating LED and zipped off routine used by Amazon Alexa devices.

Example output for:

Google Home Display

Find video demonstration at: https://youtu.be/teSNSrO1jcE

rpi-pico-ws2812's People

Contributors

josh-hrisko avatar

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.