Skip to content

Instantly share code, notes, and snippets.

@danielwilczak101
Last active May 8, 2023 21:33
Show Gist options
  • Save danielwilczak101/17d86834faed3aa1b3feeff1a8991808 to your computer and use it in GitHub Desktop.
Save danielwilczak101/17d86834faed3aa1b3feeff1a8991808 to your computer and use it in GitHub Desktop.
Raspberry PI Pico PIO tutorial
from machine import Pin, ADC
import utime
import time
step = Pin(17)
direction = Pin(16, Pin.OUT)
# To control speed just modify the amount/value of nop[dely amount 0-31].
@rp2.asm_pio(set_init=rp2.PIO.OUT_LOW)
def move():
wrap_target()
set(pins, 1) [31]
nop() [31]
nop() [31]
set(pins, 0) [31]
nop() [31]
nop() [31]
wrap()
"""Instantiate a state machine with the move
program, at 100000Hz, with set base to step pin."""
motor = rp2.StateMachine(0, move, freq=100000, set_base=step)
# Set direction
direction.value(0)
# Start your motor!
motor.active(1)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment