1

I am trying to get some WS2812b LEDs to run with my Pico. Before actually attaching them I am trying out this library: https://github.com/benevpi/pico_python_ws2812b/blob/main/ws2812b.py

It is using a state machine to drive the LEDs:

    self.sm = rp2.StateMachine(state_machine, ws2812, freq=8000000, sideset_base=Pin(pin))

When I noted that the LEDs do not change, I hooked up my 200MHz Oscilloscope and probed the GPIO pin that I set up (Pin0). The program I am running looks like this:

import ws2812b
import time

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

The scope shows Pin0 to be low all the time. When I use the simple LED toggle program, the scope shows 490 Hz on Pin0 (as expected due to it being Python code, so a bit less than the actual 500 Hz I would like to see).

import machine
import utime

led_external = machine.Pin(0, machine.Pin.OUT)

while True:
    led_external.toggle()
    utime.sleep(0.001)
    

So I am thinking that something is wrong with the state machine. How can I debug that?

EDIT: I have written a minimal program inspired by the getting started with MicroPython on the Pico book. This will toggle the output with 500 Hz, ideally. However I still see no change on the GPIO0:

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

@asm_pio(set_init=PIO.OUT_LOW)
def half_duty():
    set(pins, 0)
    set(pins, 1)

sm = StateMachine(0, half_duty, freq=1000, sideset_base=Pin(1))
led = Pin(0,Pin.OUT)

sm.active(1)

while True:
    led.value(1)
    utime.sleep(0.001)
    led.value(0)
    utime.sleep(0.001)

The scope shows this image, yellow is the manual GPIO0 toggling, the blue one shows the output on GPIO1, the state machine.

Scope showing output

1 Answer 1

0

Two thingsI see is that the minimum frequency for a state machine is 2000 Hz and you only define side-set pin for instruction.side(XX) not normal pins.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.