Download Print this page

Ws2812 Led (Neopixel) - Raspberry Pi Pico Python SDK Manual

A micropython environment for rp2040 microcontrollers

Advertisement

Raspberry Pi Pico Python SDK
10
11
import
12
from
13
import
14
15
16 @rp2.asm_pio()
17
def
wait_pin_low():
18
wrap_target()
19
20
wait(0, pin, 0)
21
irq(block, rel(0))
22
wait(1, pin, 0)
23
24
wrap()
25
26
27
def
handler(sm):
28
# Print a (wrapping) timestamp, and the state machine object.
29
print(time.ticks_ms(), sm)
30
31
32
# Instantiate StateMachine(0) with wait_pin_low program on Pin(16).
33 pin16 = Pin(16, Pin.IN, Pin.PULL_UP)
34 sm0 = rp2.StateMachine(0, wait_pin_low, in_base=pin16)
35 sm0.irq(handler)
36
37
# Instantiate StateMachine(1) with wait_pin_low program on Pin(17).
38 pin17 = Pin(17, Pin.IN, Pin.PULL_UP)
39 sm1 = rp2.StateMachine(1, wait_pin_low, in_base=pin17)
40 sm1.irq(handler)
41
42
# Start the StateMachine's running.
43 sm0.active(1)
44 sm1.active(1)
45
46
# Now, when Pin(16) or Pin(17) is pulled low a message will be printed to the REPL.

3.9.2. WS2812 LED (NeoPixel)

While a WS2812 LED (NeoPixel) can be driven via the following program,
Pico MicroPython Examples:
 1
# Example using PIO to drive a set of WS2812 LEDs.
 2
 3
import
 4
from
 5
import
 6
 7
# Configure the number of WS2812 LEDs.
 8 NUM_LEDS =
 9
10
11 @rp2.asm_pio(sideset_init=rp2.PIO.OUT_LOW, out_shiftdir=rp2.PIO.SHIFT_LEFT, autopull=True,
 
pull_thresh=24)
12
def
ws2812():
13
T1 =
14
T2 =
15
T3 =
3.9. PIO Support
time
machine
import
Pin
rp2
https://github.com/raspberrypi/pico-micropython-examples/tree/master/pio/pio_ws2812.py
array, time
machine
import
Pin
rp2
8
2
5
3
Lines 1 - 52
21

Advertisement

loading
Need help?

Need help?

Do you have a question about the Pico Python SDK and is the answer not in the manual?

This manual is also suitable for:

Pico seriesPico 2