today's beer is the Quick Fix from bookstore Brewing they describe it as a coffee cream ale
this is another brewing company that I haven't heard of before so as usual
I figured I'd give it a try so today I'm going to do a bit more tinkering
with the Raspberry Pi Pico that I got in this starter kit a few weeks ago
um I'm going to start from one of their lessons and then Veer off in my own Direction
um I think I'm going to play with the servo and there's a couple of lessons in the uh
in the documentation that's linked from their sale page that have the servo but then I'm
going to try a few other things as well so I'm going to need that I'm going to need the pi Pico
I think I'm going to use a bigger breadboard uh one of the ones I've already got and
I'm going to need I think I need that and I'm going to need a bunch of wires which I'll grab
as I need them so Servo Motors are fairly cool little devices you can control them just with a
single data pin and low current connection and they will rotate to a specific degree that you
uh that you specify that data connection isn't and technically a data connection what it is is
pwm and if you vary the duty cycle of the pwm that will cause it to move through its rotation
the one limitation is you've only got 180 degrees of rotation from most common servos
but uh for a lot of applications that can be more than enough for uh for what you want because you
can control the angle of it very precisely so as I mentioned they've got a couple of projects and
they use a Servo library to uh to abstract most of the coding so that it's not that complex for
somebody which is excellent for beginner project and there's their basic code to get the servo
to just swing through its uh 180 degrees and then go back again I am going to use the more advanced
one though that uses the joystick which as we discussed in an earlier video is basically just
two potentiometers and a push button arranged in a specific mechanical Arrangement so I am going
to go and throw this together on the breadboard they suggest connecting the servo Motors power
supply to 3.3 volts it'll work on 5 volts as well but just to get started I'm going to do it on 3.3
as they suggest so one thing I've discovered about connecting stuff up to this pipe Pico is
the labels are all printed on the bottom side of the board so find any website that's got a
good picture of it including the Raspberry Pi website themselves and just print this out so
that you can find where all the pins are that's no that's not power that's ground there are lots of
grounds scattered all around the thing so that's easy the power pins are up in the corner here
um the 3.3 out is pin 36 which is where I've got the servo motor connected I just picked
one of many grounds and vs is the 5 volts so I'll plug that up there that's pin 39 and that should
do it and also just so it's easier to see I'm going to put one of these Servo horns on there
um normally if you're going to connect this to a linkage or something you'd put one of these on
and there's several different types come in the package and that would allow you to connect the
linkage up to it just to drive whatever so now then if we give it power foreign stay standing
that's annoying it's the Twisted wires are kind of holding that so if we do this
then we can control it so two directions allow you to just go right to the ends
just tap it and it goes right to the ends the other direction
there we go you can move it somewhat and by clicking it sends it back to its midpoint
so that's what that piece of code does which is fairly cool but one
thing that I learned in reading about this board is it can have up to 16 pwm outputs
and they can be assigned to any pin and that means to me that we can use up to 16 servos
so I am going to try and add another one from my collection
because you know I've got a bunch I don't know whether I got 16 or not but that should be
enough to play with anyway so to accomplish this I've just added a couple of things to their demo
code I've created I've changed it they were just calling it s before so I've changed it
to be S1 for the first one that was already in the code and I've copied that and added an S2
so I've got a server one and a Servo two and this definition tells it which pin to use so Servo zero
or the first server server one is on pin zero and Servo two the second one is on pin one and
then down here is the other reference again I've changed the original one to S1 and added an S2
and this basically just sets the angle based on the reading the input value which it calculates
down here from various things uh based on where the potentiometers are and stuff
so that's simple enough it makes the library calls it does everything else in their code exactly the
same that's the only two things that I've had to change so let's load that onto the board
and see what happens so there we go both Servo was hooked up that's you know this one to uh
gpio zero and this one to gpio one and they should both respond to the joystick doing the same thing
push the button to re-center them so that makes sense and we should be able to just
keep on going like that modifying the code and adding and adding and adding servos to it but
that's not the only way the library does make it convenient but you can do it without the library
just by directly talking to the pwm well let me show you so here's some code that I found on on
the internet on a few different places I'll put a link to at least one of them down below this one
is not using the servo Library it is using the pwm function directly so we are defining a pwn device
as pwm the type on pin one we're telling it the pwm frequency is 50 hertz which is the frequency
that the these servos tend to expect you can use others but this is kind of what they're designed
around so we'll go with that and then this little function down here is setting a range
so basically it is changing the the position variable between one thousand and nine thousand
in 50 steps in 50 unit steps and what the one thousand and nine thousand is is microseconds
um of duty cycle there's a bunch of math and again it's on the page that I link to but essentially
that is setting the duty cycle between what the servers need for zero degrees and 180 degrees
and it's just stepping it in 50 microsecond uh steps then it just sets the duty cycle of the pwm
um in a six as a 16 bit value don't ask me to explain that again it's on the web page I'm
going to link and puts that position into there then it sleeps for you know 0.1 of a minute and
does that little bit of loop this bit here over and over and over until it gets up to
nine thousand then it drops down into this one and does the same thing exactly only it starts
at 9000 and counts down to one thousand and then does that same pwm thing and as you can see with
that code running because it's only addressing one of the servos it is just rotating through
its motion back and forth just like that simple little bit of code said now I don't know if using
the library or using it directly like this is easier one way or the other that's up to you to
decide but there's a couple of different ways to do it but now comes the fun or maybe silly Part
I have modified that one to be a 16 Servo version so basically just duplicated everything
um yes you could do a loop to create an array and all that stuff if you were a little bit
more advanced programmer than me but I think this is easier to see without obscuring stuff in Loops
so I'm just defined 16 of them onto the first 16 pins from pin one up to pin 16. and then I've just
duplicated this part as well for Servo one Servo 2 all the way up to zero 16. and because these
things are going to be drawing a fair amount of power not on their data pins but on the power rail
I'm going to disconnect the power from the picot and I'm going to use this little tick station
power supply that I got a while back to generate a 5 Volt Bus up there which I can link and power it
so I won't power it through the USB and a 3.3 Volt Bus down here which I can plug all the servos into
so allow me to just get busy doing that and I'll get back to you in a while once I've got my
massive servos I've got to you know get wires and stuff onto these and put Servo ones on them so you
can see them I will come back in a few minutes and show you this monstrosity in all its Glory
behold the Majesty of what I have created I present to you the Raspberry Pi Pico controlling
16 uh 15 because I can't count and I don't have 16 servos yeah controlling 15 servos one two
and the other crashing into each other four
five some of these are mechanically a little bit rough six
right seven over there no eight okay what's wrong with seven off we'll figure that out nine
ten hello
yeah that guy goes okay so some of them like I said are mechanically a bit rough
that guy goes I don't know what happened over here
and then 16 if it existed would go there so some of them are a little bit mechanically
compromised because these are the cheapest servers in the world and that's what you get
but they are all doing their thing except for number 16 of course which
I forgot that I couldn't count or didn't have that many
the important part is the pi Pico can do it and my janky software which I'm sure almost everybody
watching can tell me a better way to do it or six or seven better ways to do it but whatever the
point is that this is an amazing little board that can control up to 16 Servo Motors simultaneously
yes I didn't write it so that they will run simultaneously but that will be fairly easy
to change if I chose to but for this demonstration there you go I hope that was interesting gave you
some ideas got your brain juices flowing I had fun doing this even though this spaghetti mess
over here was uh lesson fun and it's going to be interesting to put it all back all these wires
minus you know the servos but all these jumper wires came from that same starter kit so that's
kind of cool that there's enough to make a fairly big project in there anyway uh thanks for watching
questions and comments and I'm sure there will be comments down below um I will talk to you later