I'm trying to port the Pico C/C++ SDK example on PIO FIFOs into micropython. I'm unable to get the out() instruction to work as intended. I've tested the generic micropython pio_blink.py sample, which use set(), and of course, it works without any issue. But my attempts to port the C sample program hello pio failed to light the LED.

Can anyone figure out how to port the hello pio C example to micropython? Here's my attempt, which ran without error, but didn't blink the LED.

import time
import rp2
from machine import Pin

# Define the blink program.  It has one GPIO to bind to on the out instruction, which is an output pin.
@rp2.asm_pio(out_init=rp2.PIO.OUT_LOW, out_shiftdir=rp2.PIO.SHIFT_RIGHT)
def blink():
    out(pins, 1)

# Instantiate a state machine with the blink program, with out bound to Pin(25) (LED on the Pico board)
sm = rp2.StateMachine(0, blink, out_base=Pin(25))

# Run the state machine.  The LED should blink at 1 Hz
while True:

Anyone see where I went wrong here?

  • According to this reference, docs.micropython.org/en/latest/library/rp2.html , the second argument of out() is the number of bits to shift out. However this reference, docs.micropython.org/en/latest/library/rp2.StateMachine.html , indicates that put() pushes words onto the state machine's TX FIFO. Should the out() specify a count for the number of bits in a single word? Commented Oct 4, 2023 at 3:32
  • 1
    @RichardChambers turns out the missing out_shiftdir was the problem (since corrected). The out_init tuple must have a size >= your largest out bit argument. Since both are 1, I'm ok, but there is no clear documentation on what the default shift dir is, So apparently that is where I was off base.
    – Dan
    Commented Oct 17, 2023 at 23:12

1 Answer 1


Turns out the bug was in the absence of an out_shiftdir argument. It can be named either in the StateMachine object or the pio_asm object, but they should always be named.

I updated the question to include it. As a rule of thumb... And pio_asm blocks that have an out must define out_base, out_init, and out_shiftdir. These are declared either in the pio_asm, StateMachine or sometimes either.

Your Answer

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

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