Raspberry Pi Pico W LESSON 100: Using Multiple PIO State Machines at the Same Time

preview_player
Показать описание
This is a link to the Oscilloscope I was using in today's lesson. It is not required for the class, but is a pretty cool piece of lab gear to have:

(Affiliate Link)

You guys can help me out over at Patreon, and that will help me keep my gear updated, and help me keep this quality content coming:

In this class we will be using the Sunfounder Raspberry Pi Pico W Keppler Kit. It will make things a lot easier if we are working on identical hardware. the link below is to amazon, and is for the identical hardware I will be using in this entire class.

In this video, I will show you how to work with more than one state machine. I will show you how you can use more than one state machine at the same time to control multiple servos. In theory, we should be able to control 8 different servos, with each one using its own state machine. Enjoy!

More great content at:

#raspberrypipicow
#statemachine
#micropython
Рекомендации по теме
Комментарии
Автор

100 🌞😘
Thank you Mr Paul, we all like your knowledge 🙏

zorabixun
Автор

once again Paul, what a such informative lesson. Thank you for all your effort.
Also want to wish you a merry Christmas and all the best for the coming year.

andrelecoultre
Автор

I Loved this Great Lesson! Will enjoy more state machine lesson and other lessons!

mychrome-mthq
Автор

I've made another video after watching this lesson. It makes my PIO Servo a bit more useful and use inherited classes as well as a generator function encapsulated within the servo class. It's called 'My video for Paul McWhorter's Pico W Lesson 100 - Using a PIO Servo properly with more functionality'.

charlotteswift
Автор

Thank you Paul. You're the best!

scottwait
Автор

Thanks Paul! Great Lesson!!! My homework did not have your '3000-pw', nor the '4th " SM. In retrospect, being new at this makes it exciting being exposed to some unique way of doing things. Loves it! Now onto the homework.... : (

edSabio
Автор

Great Session. I think you should add some comments to differentiate the different State machines.

BerndRenzing
Автор

Paul, just a note, the kit only has one servo. I was able to scrounge a servo from the Arduino kit which is bigger but worked just fine...

edSabio
Автор

Paul! Before I start the lesson, I submit that I was able to program two servos using two PIOs...Not the best but interested in knowing how it is done the right way.

edSabio
Автор

Good day Mr. MsWhorter!
I'm glad you're here. You're a great guy!
I apologize but I'm using a translator.
I have a question, if one statemachine (sm0.) reads pulses from an encoder, can the results be sent to another statemachine(sm1) directly or do the results have to be passed through the main python program?

In the future, can you make a tutorial with an encoder and a display?
Best wishes from Bulgaria

miroslavapostolov
Автор

Thank you, Paul. Just a simple comment, I think that because the code of the state machines is the same you can still use state machine 0 and state machine 1 up to 32 lines of code, meaning that if the servoSet method has maximum 32 lines of code you can use sm 0 and sm 1 if both are linked to the same method. Something like this:

import time
from machine import Pin
import rp2
@rp2.asm_pio(set_init=rp2.PIO.OUT_LOW, out_shiftdir=rp2.PIO.SHIFT_RIGHT)
def servoSet():
nop()
nop()
nop()
nop()
nop()
nop()
nop()
nop()
nop()
nop()
nop()
nop()
nop()
nop()
nop()
nop()
nop()
nop()
nop()
nop()
nop()
nop()
nop()
nop()
nop()
nop()
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, set_base=Pin(20))
sm0.active(1)
sm0.put(20000)
sm0.exec("pull()")
sm0.exec("mov(isr, osr)")
sm1 = rp2.StateMachine(1, servoSet, set_base=Pin(21))
sm1.active(1)
sm1.put(20000)
sm1.exec("pull()")
sm1.exec("mov(isr, osr)")
while True:
for angle in range(0, 180, 1):
pw=int(500+angle*2000/180)
sm0.put(pw)
sm0.exec("pull()")
sm1.put(3000-pw)
sm1.exec("pull()")
time.sleep(5)
for angle in range(180, 0, -1):
pw=int(500+angle*2000/180)
sm0.put(pw)
sm0.exec("pull()")
sm1.put(3000-pw)
sm1.exec("pull()")

ricardoboza
Автор

The class should have a counter, keeping track of the statemachines that were instantiated, and gives a warning when going over the limit (8 on 2040. 12 on 2350)

jyvben
Автор

I found out what the problem was with my solution so I've made a short video in case anyone else makes the same mistake. I doubt that anyone else will because it was very stupid. My video is called 'My final video for Paul McWhorter's Pico W Lesson 100 that actually works properly.'

charlotteswift
Автор

Excellent series! Any interest in the future of revisiting your AI series with the just released $249 NVIDIA Jetson Ori Nano Super Developer Kit?

quaternion-pi
Автор

Homework solution posted. My solution only handles one servo per class and only shows one servo. Still working on the problems I'm having trying to power more than one servo.

johnganci
Автор

It would be better if you number state machines as 1, and 2 .. not 0, and 1
Your code can easily does mistakes numbering once 0, 1 .. and 1, 2

zorabixun