In this video tutorial we show you how you can use a Raspberry Pi Pico PIO Statemachine to control the position of a servo. For your convenience, the code from this lesson is presented below. Enjoy!
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 | from machine import Pin import rp2 @rp2.asm_pio(set_init=rp2.PIO.OUT_LOW,out_shiftdir=rp2.PIO.SHIFT_RIGHT) def servoSet(): set(x,0b11111) in_(x,5) set(x,0b0100) in_(x,4) #set(x,0b00000) #in_(x,1) mov(osr,isr) mov(isr,null) set(y,0b10011) in_(y,5) set(y,0b10001) in_(y,5) set(y,0b00000) in_(y,5) wrap_target() mov(x,osr) mov(y,isr) set(pins,0) label('timeLoop') jmp(x_not_y,'nxt') set(pins,1) label('nxt') jmp(y_dec,'timeLoop') wrap() sm0 = rp2.StateMachine(0,servoSet, freq=2000000, set_base=Pin(20)) sm0.active(1) |