Master GPIO with Raspberry Pi Pico & MicroPython - Part 2

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Applause] welcome back to part two this is  lesson 8 ADC so ADC stands for analog to digital   conversion let's have a look at an analog waveform  to see what this is all about this is a kind of   typical sinusoidal waveform that you would see  generated from something that's an analog device   if we overlay that with a digital conversion  of that same waveform you can see there it's   a little bit more choppy the number of samples per  second is how many slices you take per second and   the bit resolution is how many steps there are to  each of those different levels let's understand a   bit more about how those bit levels work binary  is a number of representation format that uses   ones and zero to represent every number and if  we look at this on the screen now you can see   that if we have a 16-bit number that means that  we can store a maximum of 65 535 numbers within   that 16-bit number and see that the value of  each number doubles with each extra bit that's   been added to it we wanted to store the number  one it's basically 15 zeros and then a one if   we want to store 65 535 then it's all the ones  now if we want to use signing we want to say we   have a negative and a positive number we have  to essentially split the value in half and we   have a special sign bit on the very end so you  can see the very leftmost bit there that's our   sign bit one would mean positive zero would mean  negative for example and that means that we can   only store a maximum of 32 767 numbers  but we can say whether they're minus 32   000 or positive 32 000 and every number in between  this video is sponsored by PCB way your ultimate   destination for all things PCB manufacturing and  assembly whether you're a hobbyist a startup or   a seasoned professional PCB way has got you  covered PCB way offers an impressive range of   services they provide high quality custom designed  printed circuit boards for any application you   can imagine from single layer to multi-layer  flexible and even rigid Flex pcbs they have   the expertise to bring your designers to life PCB  way ensures fast turnaround times and affordable   prices without compromising on quality with  their state-of-the-art facilities and advanced   manufacturing techniques they can handle small  prototype orders up to large-scale production   runs with equal precision and efficiency PCB  way offers additional value-added services   such as PCB assembly component sourcing and even  functional testing you can trust them to deliver   the fully assembled and tested boards ready  for integration into your project objects or   the best parts of PCB way is a user-friendly  online platform it allows you to easily upload   your designs get instant quotes and track the  progress of your orders in real time plus their   dedicated customer support team are ready to  assist you with any questions or concerns so   whether you're working on an Innovative Internet  of Things device a robotics project or anything   in between PCB way is your go-to partner for  Reliable and affordable PCB manufacturing and   assembly head over to pcbway.com today and turn  your ideas into reality with PCB way your trusted   PCB manufacturing and assembly partner so an ADC  device will convert an analog waveform into its   digital counterpart and that means that we get  a number back rather than having to understand   what the actual waveform is so if we wanted to  get the value of say a potentiometer then we can   basically do the ADC conversion and the the value  that we will get back will be a value between say   0 and 65 535 analog input is used to measure  the continuous range of values of a physical   quantity such as light sound or temperature to use  a pin on the Raspberry Pi P code for analog input   you need to configure it for analog to digital  conversion and this is done using the ADC class   in micropython once the pin has been configured  for analog input you can read an analog value   from it to read the value of an analog input pin  you need to use the read underscore u16 method   of the ADC class and this means read an unsigned a  16-bit integer let's take a look at potentiometers potentiometers are variable resistors  that can be used to control the voltage   in a circuit they're often used as volume  controls or to adjust the brightness of an   LED to get started you'll need a potentiometer  some jumper wires and a Raspberry Pi Pico board now that we've got everything set  up we can write some simple code to   read the potentiometer's values first  let's import the necessary libraries and now let's set up the potentiometer potentiometer to GPL 26 on the Raspberry  Pi Pico which is this yellow cable just   here finally let's read the values from  the potentiometer and print it to the   console we'll do this in a wild true  Loop and we'll simply read the value   into variable that's called value print it  to the screen and then sleep for an amount   of time this code will continuously read the  value of the potentiometer and print it to the   console every half second we can also monitor  this on the plotter as you can see the values   printed to the console change as we turn the  potentiometer knob and that's all there is to it temperature sensors are used to measure the  temperature of their surroundings they're   an essential component in many projects for  home automation to weather stations let's get   started by connecting a temperature sensor to the  Raspberry Pi Pico for this demonstration I'm using   a monk makes sensorboard version one we'll use the  code from the previous project as a starting point   using the ADC to read in from pin 26 so we're  going to have another wild true Loop and we'll   grab the readings like before but we calculate  what the temperature is in degrees Celsius foreign stands for universal asynchronous receiver  transmitter is a common serial communication   protocol used to connect microcontrollers to other  devices such as sensors displays and GPS modules   it's an asynchronous protocol which means that the  transmitter and receiver are not synchronized by a   clock signal instead they rely on a predetermined  baud rate to synchronize and transmit reception   of data to use you out on your Raspberry Pi  Pico you'll need to configure the uart pins   and the baud rate first you'll need to identify  the uart pins on the Raspberry Pi Pico board   note that there are only five uart pin pairs  on the Pico and you can only use two of these   pairs at a time which have different IDs 0 or 1.  you can't use two uart pairs with the same ID we   then configure the uart pins using the machine dot  uart module and set the desired board rate once   you've configured you out on the Raspberry Pi Pico  board you can use it to send receive data to other   devices it is a bit fiddly if you haven't got the  ground connected between the two devices you may   get garbage coming out because the level of the  signals is not the same now have recorded another   show about how to do picot to Pico communication  and you can find the link to it just up here I squared C is a community locations protocol used  to connect microcontrollers to other devices such   as sensors displays and input and output boards  it uses two wires for communication the serial   data SD and serial clock scl it's also common that  you'll need to provide three Volts for the board   as well as a ground pin now pimmer only do a great  range of I squared C devices if you go to their   breakout garden section on the website you'll  find all kinds of sensors input devices cameras   and so on I'll use that same I squared C device  and if we just pick one of these for example this   bme688 four in one air quality sensor you can see  if we go down to the library section and then if   we go into micropython and examples you can find  there the breakout bme688 this is how we would   then use that board in our code we would have  to use the helper function that's provided in   the batteries included pimroni micropython which  we can also get from the pimarroni website but   you can see here that they've they've got the SDA  pin connected to pin 4 on the Pico the scl for the   clock connected to pin five and in this particular  exam sample they're using a Pico Explorer which   has a separate set of pins so depending which  kind of board you're using you can Define which   set of pins you're going to use for this and then  to initiate the I squared C use it in our code we   simply create a variable that's called I squared  C and then we make the pimroni I squared C and   then pass it in which kind of board that we're  using you can see here that the BME variable this   represents that Center itself so that will get all  the different air quality sensors for us it can   pull them back very very simply so it depends on  which type of ball that you're going to be using   depends on what kind of features and functionality  you will have in this particular sensor SPI stands for serial peripheral interface  and it's another Communications protocol   that is used to connect to microcontrollers  to other devices such as sensors displays and   memory cards it is a synchronous protocol which  means that the transmitter and the receiver are   synchronized by a clock signal it uses four wires  to achieve this there is the master out slave in   or mozzie who is miso which is the master in  the slave out because the serial clock sclk   and then there is the slave select SS this is an  example of a piece of software I created called   pie chart and it enables you to create little  tiles on a very small screen and you can show   sensor data and do font things like that you can  even make images display on the screen so if you   want to know how I did this then check out this  video in the card up here these are little SPI   screens like this one I've got here this is from  pimarroni this is a tiny little screen 1.54 inch   and it's 240 by 240 pixels you can see all the  little pin outs there at the bottom we've got   the voltage got the ground and all the other  pins as well some other screens such as this   one here they have a built-in s SD card reader  on the back because also that uses SPI so you   can see this screen is 128 by 160 pixels it's  1.8 TFT and this one also has SPI connections   on it and other sensors that require very fast  transfer of data such as this Optical flow   sensor this is another pimarroni sensor this is  a near Optical floor sensor and this one allows   you to effectively create your own Optical my  spy tracking the XYZ position changes foreign S A Servo is a small device that rotates  to a specific position making it ideal for   controlling movement of robots drones and other  projects it has three wires power ground and   Signal the power wire provides all the power  to the servo while the ground wire provides a   common ground for the servo to the Raspberry Pi  Pico the signal wire is used to send a signal a   pulse width modulation signal that we looked at  earlier to control the position of the servo to   connect the servo to your Raspberry Pi Pico  you'll have to connect the power wire to an   external 5 volt Supply and the ground wire  to a pin on the Raspberry Pi Pico board and   will connect the signal wire to a pulse width  modulation enable pin on the board the signal   wire is typically connected to pin gp18 on the  Raspberry Pi P Core board this is because this   pin has pulse width modulation enabled to control  the servo with micropython you'll need to use the   machine.pwm module to generate the pulse width  modulation signal that controls the server's   position I've created a quick demo here the  code is very very simple we're simply just   setting up on pin 18 a server which is using  the pwm module you can see that it's sweeping   through all the different positions and it's  simply doing that by just adjusting the duty these are ultrasonic rangefinders they have  a microphone and a speaker and when they send   out a signal we can measure the time it takes  for it to hit an object and then return that   signal back if we have that we'll get the exact  distance now these two look exactly the same but   they're actually very different and one of them  works with 5 volts which the Pico is 3.3 volts   so that that's no good for us the other one is  actually 3.3 tolerant so if I show you these two   side by side so you can see these side by side  the one on the right hand side where it says   Echo transmit SDA trigger RX and SEL that one  is 3.3 volts tolerant the one on the left hand   side is a 5 volt one they look exactly the same  apart from that but the chip on the rightmost one   the u3 chip that's the thing that enables it to  work with the Raspberry Pi Pico you can also get   I squared C ultrasonic rangefinders here's one  from M5 stack and that contains everything you   need inside there to get connect this up using  the groove connector to connect the ultrasonic   Rangefinder to the Raspberry Pi Pico you need  to connect the voltage and the ground pins to   an appropriate power and ground on the board and  then the trigger and Echo pins are connected to   GPA or pins on the board this animation you  can see a sound signal will generate from our   robot and it's approximately 30 centimeter  away from an object once it hits the object   the sound wave will bounce back and then we can  measure the distance that was traveled which can   be calculated by taking the sound measurement  how long it took for the sound signal to come   back to the robot dividing that by two and  then multiplying it by the speed of sound   here's a snippet of code that will  show you how to do this in micropython [Music]   i o pin that's used to complete an electrical  circuit they provide a low resistance path for   the electrical current to flow back to the  power source without ground pins circuits   would not work properly or at all there are  eight ground pins on the Raspberry Pi Pico   they have a sort of squarish head connector  as opposed to the round one for the regular   gpos and they're all connected together so it  doesn't matter which ones that you use I've   created a simple demo of making an LED flash  on and off and you can see that we have to use   the ground pins to complete the circuit for  the LED so if I run this little program it'll   simply just turn the LED on and off to run that  you can see that it's flashing on and off every   second so what's happening here is the LED has  two legs this is an LED you can see that one leg   is slightly longer than the other a long leg is  the live leg that's how I remember it and that   means that we need to send a voltage 3.3 volts is  fine to the live to the long leg and then for the   short leg we need to then connect that to one of  the ground pins on the P code it doesn't matter   which one they're all interconnected and that  will complete the circuit so then if we send a   signal we make that go 1 and if the value go  high and it will send 3.3 volts through that   circuit and then the ground pin will complete  that circuit and the light will go on the code   is simply making that voltage go high or low  depending on what part of the code it's in let's take a review of what we've learned in  this course so in this course we'll learn what   micropython is why you should use it where to  download it from what type of software to use   to develop micropython code we've also looked at  how to connect various different components to   the Raspberry Pi Pico using the different types of  gpio pin we covered what gpio pins are and all the   different types including digital i o pulse width  modulation analog 2 digital conversion I squared C   SPI we also looked at how to write micropython  code to control various different things like   LEDs Motors servos and ultrasonic rangefinders as  well we also looked at how to use potentiometers   temperature sensors with Raspberry Pi Pico we  wrap that up by looking at what ground pins are   and how to use them on our circuits so now that  you completed this course you're ready to take   your skills to the next level so you'll be able to  do things like robotics which is my favorite thing   you'll be able to build more advanced circuits  use more Advanced Micro python code and work on   even more complex projects so hope you enjoyed  this course I went on holiday halfway through   regarding this which is why I've got slight bit  of a tan as I've come back I've put hope and I've   also changed my hat as well because we didn't  like the red color for some reason so I've gone   with the the black hat so I hope you enjoyed this  video and I shall see you next time bye for now
Info
Channel: Kevin McAleer
Views: 2,297
Rating: undefined out of 5
Keywords: Kevin McAleer, Small Robots, raspberry pi, raspberry pi projects, small robots, micropython, gpio, adc, i2c, spi, servos, motors, temperature sensor, learn micropython, gpio pins explained, raspberry pi pico gpio, pinouts, voltage levels, pwm, leds, pico, pico w, raspberry pi pico, pi pico, raspberry pi pico tutorial, raspberry pi pico projects, raspberry pi pico w, raspberry pi robot, robotics, robot, robots
Id: NlybkEO_2iU
Channel Id: undefined
Length: 15min 7sec (907 seconds)
Published: Sun Jun 25 2023
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.