GPIO Basics with LED light - Raspberry Pi and Python tutorials p.6

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
what's going on everybody and welcome to another Raspberry Pi tutorial in this tutorial what we're going to be doing is introducing the GPIO pins on the Raspberry Pi how to use them and all that so what we have here is one breadboard to male-to-female jumper wires one resistor the resistor should be somewhere between like 301 K ohms and then an LED light this one's yellow it really doesn't matter what color you choose though and basically what the GPIO pins do for us is they allow us GPIO stands for general purpose input output and it allows us to either send out a signal either high or low so just a binary signal out or receive a signal back in and there's all kinds of ways that we can manipulate that to have a lot more dynamism to it now the GPIO pins are labeled for us and I'm going to pull up this image from Adafruit and these are the GPIO pins above that kind of gray line that's the older PI's and if you have one of the more later versions you'll have all 40 pins and you can go all the way down there towards the bottom of that image now the way these are oriented if we go back to here it's as if it's the same way this pi is oriented in this image sure this video right here so that translates directly to these pins here so the top leftmost pin is 3.3 volts and then the two top right most pins or your 5 volt outputs now what we're going to do is we're going to rig up a simple LED light that will just turn on when we ask it to via our program to do that to create the circuit we're going to be using this breadboard here so this is breadboard the way that it works is basically all on these edges here sometimes you'll have like two rows and breadboards will look a little different but they're generally going to look something like this and these are connected vertically basically so by column I suppose you could say and then you've got these middle bits each of these are connected by row so for example let's say this this spot here is connected to this one is connected to this one and so on but these are not directly connected to these you'll connect them yourselves and then like this one is closest one I suppose this one is not connected to this one or this one but this one is connected to this one so to help you understand that even further I've just kind of circled or squared some examples of ones that are already connected but of course you can connect them yourself with jumper wires or will use the resistor to do it and so on and then even the LED bulb will use so what we want to do is wire this all together so here's a quick diagram of the actual wiring that we're going to do now this is not a real wiring diagram by any means but I know whenever I was first starting out the last thing I wanted to see was a wiring diagram I wanted something a little more obvious to me so basically what I've done here is this green is the Raspberry Pi The Cult the filled in boxes by color or the actual jumper wires so black to black and so on and then the resistor is this like blue blob and the LEDs right here and it's labeled and all that so it's just like super simple so coming back to our Raspberry Pi now let's go ahead and connect everything let me just pop up the diagram there so it's actually kind of a little hard to see if your screens not very big at least that yellow so the yellow here is armed basically six pins down and then three pins down for the the ground so if you want you can take a screenshot of this also you can go to the text-based version of this tutorial and save this image it's always good to have an extra one around so anyway yeah ground here the third pin down on the right and then we'll also be using GPIO pin 18 also just for the record these are the Broadcom names it's a little unfortunate the Raspberry Pi has like the board names for the pins and that's just like the physical location basically of the pin you can use the board name tens or the Broadcom names and the Broadcom that's the processor that we're using that's the actual chip that's how it recognizes those pins that's the name of that pin according to the chip so we're going to use the Broadcom names okay so let's go ahead and wire this up just going to connect here this this blue cable will be my ground so we'll go ahead and connect everything up nothing's plugged in so it doesn't really matter the order that we do this but yes so we'll go ahead connect ground here and then the female end for the actual led here and then ground we'll connect right here and then we'll use the resistor [Music] and then next to the resistor will be the LED bolt and now one thing to take note of let's see if you can see that you notice that there's one end that's longer than the other not all LED bulbs are going to have that but when you do have that the positive end is the longer end so since this is the ground and we actually want the negative end to be on that side so we'll go ahead and plug that in if for whatever reason your circuit doesn't flip them around you probably just made a simple mistake otherwise the bulb could be burnt out there's all kinds of uses 20 would work or your circuits bad or whatever okay once we've done that now we can just plug in for the actual resistors kind of touching we don't want them to be touching I don't want metal to metal there now in reality you'd actually trim that resistor down so it wasn't sticking up so much but yeah make sure the resistor isn't directly touching say the positive end of the the GPIO cord anyway or the LED rather okay so I've got everything hooked up and again it's according to this diagram if you need more pictures I've got some better pictures of the actual physical wiring of this thing in the text-based version so if you're still confused or whatever definitely check those out but yeah so now let's go ahead I'm going to plug in the Raspberry Pi we're going to fire it up and then we're going to get to the actual code to make this light turn on off all right with the Raspberry Pi all connected turned on I'm in the terminal via SSH let's go ahead and change the directory to the desktop and also let's just make sure we've got our PI GPIO chances are you already have it but let's just make sure so sudo apt - get installed Python - RPI GPIO and we already have it so it's no problems so now I'm going to go ahead and do is we're going to nano LED example dot PI and now we're regulated do is import RPI dot all caps GPIO now mine the caps let's capital R capital P lowercase I dot all caps GPIO import that gpio then we're going to also import time and then now we're going to do is GPIO to set mode GPIO GPIO dot DCM so the DCM is short for Broadcom the other option is if you wanted board names but I'm going to use the BCM Broadcom names because I just think it makes more sense and we just want to make sure we're using the same names as as we think we are anybody say you want to want to mess up the pins so now we've done that we're ready to set up the pin so like like I was saying before our pin that we connected to is pin 18 for let me pull it up here so we connected that third from the top right ground you could have connected at any of the grounds it's not a big deal which one but our actual pin that's going to send an output signal to that LED bulb to actually turn it on is going to be GPIO pin number 18 again you could have plugged it into any of the other GPIO ports it's not essential that you do the exact same port or pin rather as I do anyway what I'm going to do now is GPIO set up and we're going to set up pin number 18 and we're going to call that a GPIO dot out it can also take an input so it could be GPIO in now we're going to do is GPIO whoops all caps GPIO dot output and we're going to output the pin 18 and we're going to output a high signal it could be a GPIO too high or low those are the two signals that you can output from your GPIO so we're going to do high and then we'll go ahead and time dot sleep we'll do five seconds and then we'll do GPIO output again depend 18 GPIO dot look so it's a low signal and then when we're all done let's go ahead and run GPIO duck cleanup and that should be everything that we need so let's go ahead and exit that safe yes cool let's go ahead and run Python led example dot PI and let me just pull my screen over here so I can make sure that shows up on camera no problem go ahead and run that hard to tell with that yellow light but it is on and I think these are five seconds yeah and now it's off so hopefully yours turned on and off minded there okay so this is like a really quick basic example of using the GPIO that's one way to send out a value now what we're going to do is use that distance sensor to actually input bring back in some data from our from a sensor so that's what we're going to be doing in the next tutorial a little slightly more complex setup but it's not too bad so that's what we're going to be doing the next tutorial if you have questions comments concerns or whatever up to this point feel free to leave them below otherwise I will see you in the next tutorial
Info
Channel: sentdex
Views: 159,582
Rating: 4.8608212 out of 5
Keywords: GPIO, General Purpose Input Output, Raspberry Pi, mini computer, tutorial, Python, setup, Raspbian, robotics, arduino, LED light, light
Id: WLo5Rgvj6qo
Channel Id: undefined
Length: 10min 31sec (631 seconds)
Published: Mon Apr 03 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.