Master GPIO with Raspberry Pi Pico & MicroPython - Uncover the Secrets!

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hey robot makers are you ready to bring your  micropython projects to life in today's video   we'll learn how to control Motors servos and LEDs  using gpio pins and by the end of this tutorial   you'll be able to build your own mini robot or  automated light show so let's dive straight in   and have some fun with micropython welcome to  the Raspberry Pi Pico with micropython gpio   Mastery course in this video we'll be covering the  basics of using micropython to control gpio pins   on the Raspberry Pi Pico to follow along with this  course you'll need a few things first you'll need   a computer tablet or phone to read the course  materials from you'll also need a Raspberry Pi   Pico board some jumper wires and a breadboard for  some Hands-On practice and of course you'll need   some different components to connect to the board  such as LEDs Motors sensors and other electronic   components this course is divided into 16 lessons  each covering a different aspect of using micro   python with a Raspberry Pi Pico and the first  lesson we'll be covering the basics of micropython   and gpio pins we'll look at the different types  of gpio pin on the Raspberry Pi Pico their basic   functions and how they can be used in various  applications we'll also take a closer look at the   Raspberry Pi Pico's pin numbering system and learn  how to identify each pin by the end of this lesson   you'll have a solid understanding of the basics of  micropython GPO pins and you'll be ready to start   building your own projects so are you ready to get  started let's dive into the first lesson [Music]   first let's understand the gpio numbering system  on the Raspberry Pi Pico have this poster on my   wall normally and you can see on here it has all  the different markings of all the different pins   this is a really useful reference to have to  hand when you're building something and you   want something physical you can quickly refer to  first let's understand the GPL numbering system   on the Raspberry Pi Pico the board has 26 gpio  pins in total numbering from 0 to 25 pin 0 to   21 are available for General use while pins 22  to 25 have additional functions each gpio pin   can either be configured as an input or an output  inputs receive signals from external devices and   output send signals to external devices there are  four types of gpio pin capability on the Raspberry   Pi picot digital input digital output analog  input and pulse width modulation output digital   input pins receive either a high one or low zero  signal while digital output pins can send either   a high or low signal analog input pins can measure  voltages between 0 and 3.3 volts while pulse with   modulation pins can send a pulse signal to control  the power supply to the external device not every   pin has the same capability make sure you check  the pin out diagram before you connect any pins   now that we know the different types of gpio pin  let's move on to configure them for use [Music]   let's take a look at Pin numbering so there are  two types of pin numbering system that we can look   at there's the gpio pin numbering system that's  referred to as the broadcom it's a broadcom chip   inside and if we flip it over we can also see that  there is a physical numbering of the pin starting   at one and working our way all the way around to  pin 40 at the top so there's two different ways of   referring to the pins and this can confuse people  when we're getting started so when we write code   we tend to refer to the pins as gpio pins rather  than the physical pin so just bear that in mind before we start using the gpios we need  to understand about the voltage levels   to measure the voltage levels of the pins  we can use a Multimeter like this one here foreign do that let's talk about the voltage levels that  you will encounter depends on the Raspberry Pi   picole are all 3.3 volt there are two pins which  are an exception to this which are actually 5   volts and these are the very top two the first  one is where the voltage comes in from the USB   connector it's exposed through that very first  pin there so that's 5 volts the next pin down   is also 5 volts the rest of them are 3.3 volts or  ground which we'll come to later so it's really   important that you work to the correct voltage  levels being the 3.3 volts but when you're using   the raspberry pi Pico otherwise it can damage  your pcores processor so always make sure you   check the data sheet of the component that you're  using to make sure that it's compatible with 3.3   volts before you start using it that's it for  this lesson now let's have a look at digital i o   pins on the Raspberry Pi Pico can either be  high or low high corresponds to 3.3 volts and   low corresponds to zero volts now let's move on to  digital input and output digital input means when   we read a value from the pin and digital output  is when we set the value of the pin let's set up   a simple circuit with a push button switch as  an example we'll connect the switch to one of   the digital input pins on the Raspberry Pi Pico  and then read the state of the switch using the   micropython code so I'm over here with my bench  Cam and you can see the code on the screen share   as well so let's have a look at this small program  so the first line we're going to import machine   this is how we access the gpao pins and all the  machine functionality of the board we're going   to import the sleep function from the time  module just so that we can introduce a small   delay while we're reading from our button and  what we're then going to do is we're going to   set up the button pin as this a button underscore  pin variable so we'll say equals machine dot pin   and pin represents all the gpio pins we're then  going to use gpio pin 0 which is the very first   pin on the Pico we're going to say that this  is a this is machine.pin.in and that's tells   micropython this is an input a digital input  and then we're also going to say machine.pin   dot pull up and pull up says make sure you switch  on the resistor inside the chip so that we don't   have a sort of floating value it is either  a one or a zero and that resistor helps us   do that internally we've then got this little  Loop so this says well true so run forever if   the button pin value equals zero then we want  to say print 0 to the terminal and also print   button is pressed if the button value is equal  to one that's because we're using the pull-up   resistor then that means the button isn't pressed  and then we're just going to sleep for a tenth of   a second so let's run this and see what happens so  it's saying one and button is not pressed you can   also see on the on the right hand side of the  bottom here we have this little graph showing   that we're currently at one volt and nothing  is being pressed so if I now press the button   we can see button is pressed and it's dropped  down to zero I'll let go we can see the button   is not pressed if I sort of alternate between  the two you can see the level dots and dashes   there like some kind of Morse code that's just  a simple example you can awful lot more you can   control LEDs you can read sensor data and so much  more next let's look at Pulse width modulation pulse width modulation or pwm is a technique  that allows us to control the amount of power   being delivered to a component such as  an LED or motor by adjusting the duty   cycle of the signal we can control the  average power delivered to the component   so I've got a little program here I've written it  simply creates a pull split modulation object on   pin zero which you can see is the top pin  there and we're setting the frequency to   1000 so we're also setting the duty cycle to  an unsigned 16-bit integer don't worry about   that it's just a number to 250. so let's run  this it's going to sleep for a second and then   it's going to turn off the light so if I hit the  Run button you'll see the LED flows quite dimly   at 250. let's change that and add an extra one  in front of that so it's now 1250 you can see   that's quite a bit brighter let's change that  to a two brighter again let's change that to a   three even brighter so by adjusting the pulse  width we can make the light brighter or dimmer   so let's take a look at Motors and how to  control them with pulse width modulation so   a motor is a device that converts electrical  energy into mechanical energy thank you as a rotating shaft which can be used to move  objects or drive a wheel control the speed of   the motor we can use pulse width modulation now we  will have to use some kind of driver board such as   this one here these are quite common driver boards  and very cheap these are known as l298m and they   have a couple of inputs so this one will drive  two Motors you can see int one in two in three   and four and on the other side we have more to  a and motor B which have got two outputs the   reason we need these driver boards is because the  Pico only has 3.3 volts and it's very low current   and Motors require a lot more current and possibly  more voltage so we need some kind of driver board   that will convert between the two and receive the  signals and the signals that it receives are these   pulse width modulation signals so over here on the  bench I have a kitronics robotics board and this   enables the Pico to have the driver board which  we just talked about have a battery to power the   motors and they've also included some really handy  classes to make the code a lot easier so the class   that they include is called Pico robotic 6 and  if you want to get this you'll just have to go   to their website and there's a link there to  a GitHub repository where you can download the   code and then just run it and install it onto your  pico so I only want to test one motor so in this   Loop here for motor in range you could set that  to four and all four Motors could be activated   I'm just going to use one motor this mouse rubber  I have on the bench here just has two Motors in   it on each side so what it's then going to do is  say motor on motor plus one and then the direction   and the speed so this will make it really really  easy for us to control and you can see there for   Speed and range 100 so it'll go from 0 to 100 and  then it'll sleep for 10 milliseconds and then it's   going to do the same again where it'll go from 100  down to one so it'll go faster and then slower so   let's run this and see what happens shall we  so I'm going to click on the Run button and   I need to switch on the board of course first  let's let me just do that there we go [Music]   so it's going backwards and forwards and  I've got an alternative view of this as well   as you can see here I've got some Post-it  notes holding that motor up there as well   and that's simply so it doesn't run away  I hope you enjoyed part one stay tuned   for part two coming later and I'd like to  give a shout out to some of my supporters   so we have a Michael and Matt thank you so  much for the coffees and Marion and Victor   as well and then we have Marley we have John Tom  shimmy Steve Phillips as well who are members on   buy me a coffee um on YouTube we have Dale we  have Carol we have Jose Skipper Banks Jeff for   WP body Bill we have hands from chair lights we  have Michael and we have Tom thank you so much for   supporting the channel so I hope you enjoyed this  video and I shall see you next time bye for now thank you
Info
Channel: Kevin McAleer
Views: 4,636
Rating: undefined out of 5
Keywords: Kevin McAleer, Small Robots, micropython, learn micropython, gpio, gpio pins explained, raspberry pi pico gpio, pinouts, voltage levels, pwm, motors, leds, pico, pico w, raspberry pi projects, raspberry pi, small robots, raspberry pi pico, pi pico, raspberry pi pico tutorial
Id: M-0P6ipVwNU
Channel Id: undefined
Length: 10min 2sec (602 seconds)
Published: Sun Apr 16 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.