Raspberry Pi LESSON 11: Understanding and Using a RGB LED

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys this is paul mcquarter with toptechboy.com and we're here today with episode number 11. in our incredible new tutorial series where you're teaching your raspberry pi who's boss what i'm going to need you to do is pour yourself a nice tall glass of ice cold coffee that is straight up black coffee poured over ice no sugar no sweeteners none needed and as you're pouring your coffee as always i want to give a shout out to our friends over at sun founder sun founder is actually sponsoring this most excellent set of video tutorials on the raspberry pi and in these lessons we will be using the sun founder ultimate raspberry pi kit hopefully most of you guys have your gear already if you don't have your gear look down in the description there is a link over to amazon where you can pick up one of these really cool kits but enough of this shameless advertising let's jump in and talk about what i am going to teach you today and what i'm going to teach you is i'm going to teach you how to use the rgb led that is the red green blue led now up until this point we have learned quite a bit already on the simple red led we have learned how to turn it on and off with the gpio pins we've learned how to use pulse width modulation to make it brighter or dimmer through the gpio pins and then we've learned how to read input from an input gpio pin and like hook it to a button and have the button either turn the led on and off or use the button to con use several buttons to control the brightness of the led so we've done a lot but it's time for us to start branching out to some components that are a little bit more fun so the first thing we are going to need to do is find our most excellent rgb led and i think i'll come over drop my mouse but no harm done okay we'll come over here to the studio view and i think that is pretty cool and i will get out of your way and then you will look here get out your sun founder kit and we're going to need a couple of different things here what we are going to need is first of all you see here i have my breadboard so get out your breadboard of course you'll need to get your raspberry pi out and get it booted up and then you're going to need these three male and male to female jumper wires you're going to need the red one the green one and the blue one you could use any color wire the color wire doesn't matter but if i'm going to be using rgb on an led an led that can turn red an led that can turn green or an led that can turn blue it kind of makes things easier if i control the rgb channels using wires that are r g and b and then of course you're going to need a ground wire so you will need wire number four which i like to use black for ground wire so you don't have to you can use whatever color wires you want but i just find it kind of helpful in troubleshooting and debugging if i kind of put a little thought into the color wires that i use now what you're going to do is open up your most excellent sun founder uh raspberry pi ultimate starter kit and then here on the first level we have this wonderful little bag of leds you can see there's red there's green there's blue there's some white ones in here okay but if you look there is one special led and only one and so you want to be very careful with it because you only have one and that is the one that is white and has four legs okay you see you have one that is white and has four legs you need to get that one okay and now we're going to be neat and we're going to put this back you're also going to need three 330 ohm resistors and so we have been playing with these resistor packs now if you are like me and have been taking this class then you've already been using 330 ohm resistors and hopefully number one hopefully you just didn't throw them back in the bag unlabeled and then also hopefully every time you need a 330 ohm resistor that you don't go back you don't go back and just pull off new ones what i do is after i've used them i like to label them like you can see here 330 ohm with a piece of masking tape and then just tape them tape them all together and so i'm going to pull out for my little taped label once i think when we did the the led counter we used five and so i've probably got five pulled off but i only need three today so i'm going to pull those three off and then put them down here in my build area and then the rest of these 330 ohms i'm going to put back in the most excellent kit and i think for day for today that is what we're going to need out of the kit don't you like just kind of looking in here and seeing all this amazing goodness we're going to be playing with this kit for a long time in this class there is a lot of neat stuff and we're going to be building a lot of fun projects but we're always starting with the fundamentals and we like to do the fundamentals on simple components so that if we do make a mistake we don't really hurt anything these leds don't cost very much although like i say you only have one rgb led so you want to make sure that you don't damage it okay so let's come in and i need to move over to a different view here and i think this is a good view you've got a live view of my build area and then you've got a schematic of what we are trying to build here okay the rgb led has four legs and what i'm holding here in my hand you can see here above me and yours might not be exactly like this will it will have four legs okay that's good and sometimes though if you look at the r the g and the b sometimes they're not like that but you'll figure that out soon enough like if you think you're turning it red and it turns blue you know that your pins might be a little different but always as far as any led i have ever seen that's an rgb led the long leg is always ground okay the long leg is ground and now the leg that is by itself is shown above that's to the left of the long leg that is usually red and then to the right of the long the long long leg the one that is almost as long that leg is green and then the little short leg to the right is blue and so the thing is hold your led in that same configuration where the little short leg by itself is to the left okay that's how i have it and now we're going to come down and we're going to plug that in and i'm going to just plug it into a convenient spot here and of course one leg goes in each hole in different columns if that makes sense so i've got to get each leg in a different column and it actually is a little bit a little bit tricky to try to do live here but uh i think if you're not having to worry with the camera you can get it closer to your face and you can do it okay so let's take a look there do you see how i have each leg in a different column and i've got them kind of lined up and that second to the left one that's my ground that second to the left one that is my ground and so what i'm going to need is i am going to need to go ahead and i'm going to start i'm going to start by hooking the ground pin up so the ground pin is the second to the left that's the long one and as in the diagram up there i'm going to run that down to my ground rail and so i'm going to go the second to the left one and i am going to run that down to my ground rail which i'm making here i'm making it the second to the bottom row as shown in the diagram there okay now if that is going to be my ground rail i need to make it my ground rail by connecting that row to the raspberry pi and so i'm going to go ahead and put this in that second to the bottom row and now i need to find a good ground well how can we do that we can come over here to our diagram and you can see that the lower left pin that's pin 39 the lower left pin here indeed is a ground so i'm going to take that to the lower left pin and that is going to go down here to the most excellent pin 39 okay and then boom now i have a ground rail and i have my led grounded now i am going to need three current limiting resistors i'm going to need a current current limiting resistor for the red channel for the green channel and for the blue channel now some people oftentimes will come in and say well can i just put one current limiting resistor and put it on the ground wire and that will be in series for r for g and for b no that won't work if you only turned r on or g on or b on at a time that might work but if you're starting to mix and match colors then you're going to cause great problems so really you need a 330 ohm current limiting resistor in each channel and i'm going to do that as i show above here by jumping over that center trench where things uh the connection is broken and so i will come in here to my b channel and i am going to come into my b channel the one on the right the rightmost leg and i have my current limiting resistor in now i'm going to come to my g channel which is the second to the right you see you really want to get your face right down on your work and since i'm filming i can't do that so it's a little harder for me to see so i've got those two in and now finally the red channel is on the left and i will put that current limiting resistor in like that now we'll tip it up that all looks good guys make sure that when you're packing things in close like this make sure that you don't have like two legs of the resistor touching each other like you don't want this resistor touching that resistor because you would be shorting out your channels and so be kind of neat and careful in your in your builds okay be kind of neat and careful in your builds like that okay now what do i have i have if you look up here 39 is the ground the lower left pin now the pin above that would be 37 and i'm going to make that the red channel so i'm going to come in with my red wire i'm going to go from pin 37 on the raspberry pi like that and i'm going to come over and put it in that same column that same column as the lower leg of my r channel current limiting resistor now what's next the next is going to be g and g green is going to go to pin 35 and then b is going to go to pin 33. so we've got 30 we've got 39 is ground 37 is red and now i've got 35 is 35 is g and then 33 is going to be b okay so 37 39 37 35 33 are the pins we're using and now i need to come over here so i've got r connected now i'm going to connect g to the middle leg and then b blue to the right leg okay so now down here i have connected as i have it in the schematic there okay so that was a pretty easy circuit that was a pretty easy circuit to hook up now again kind of the the sad thing here is these rgb leds are really quite brilliant and quite beautiful but the colors just don't pick up very well on these studio cameras and so when you do this it's going to look a lot better in real life it's going to look a lot better in person than it is when you look at my camera view here but this is kind of like we're going to do the best we can so let me get this all properly aligned okay and then we've got this all right now what we need to do is we need to i believe come over to my code view let's see if i've got a good code view here yes we do and then i think what i will need to do is just move this up like this so now you can see everything and you can be watching as i am coding okay so you've got your raspberry pi up and now what we're going to need to do is we are going to need to start a terminal and man i love just running from the command line on the terminal i just love doing this and in fact i love just opening up a python shell and just banging things out on the shell and then you can come back later and write a program but i just kind of want to i want to show you how this thing works and so what should i do well i want to operate from the command line so i want to type python no what would happen i would be in python 2.7 we don't want that right we got to remember what python 3 and then boom we are in python 3.7.3 if you are on the buster operating system like i am okay now what are we going to want to do well the first thing we're going to want to do is import who our friend mr uppercase r uppercase p little i dot g p i o and we're going to import that as gpio you can import it it's whatever you want you could import it as kitty litter box but that's not very descriptive so i'm going to import it as gpio one day i'm going to do a lesson where i import rpi gpios kitty litter box and show you that that will in fact work boom okay we've got the library now what i'm going to want to do is i got to tell it gpio i've got to do the set mode and what's that i am telling it that i am using the the physical pin numbering system so we do that with saying the board that means the board numbering system the physical pin numbering system okay now what we need to do is a gpio let's let's go ahead and do like an r pin i'm going to say our pin is what our pin is 37 okay and then i'm going to do a g pin is equal to 35 and then a b pin is equal to 33 all right now i guess i could have just used the numbers but this way i only have to think about it once and now i just do our pin g pin b pin as i uh as i want you know i don't have to ever think about what's what again [Music] okay now i need to set up those pins so i'm going to do a g p i o dot set up and what am i going to set up i'm going to set up our pin and it is a what gpio i better put a comma it is a gpio dot what it isn't out like that okay now we're going to take advantage of the wonderful little up arrow and then instead of our pin this is going to be g pin is an out and then this is going to be rg what b b pin is an out so now we have everything set up okay we have everything set up now we're gonna see can we turn can we turn the led red how would we do that we would go gpio dot what gpio dot uh output okay and then what do we want to turn we want to turn our pin and then what do we want to turn it we want to turn it we could turn it true we could turn it one let's just uh let's just let's just make it a one okay so all eyes all eyes on the led okay i will need everyone to hold their breath [Music] oh what what is that output i swear i typed a t and it's this dinky doofus little keyboard that isn't recording my keystrokes so let's put the t in there the real reason is one of you guys didn't hold your breath and i think you know who you are so this time i need everyone to hold their breath boom shazam look at that bright red rgb led bright red just like we wanted okay now man and i just wish that you could see it more clearly like i'm seeing it that is just a beaming beautiful bright red color okay now if i can turn red on what else can i do i can turn it off with a zero shazam okay well it's rgb so i might want to do what i might want to turn green on so i'm going to say gpio output and i am going to turn green on with a one there and that did not work okay so we have a problem here let's see yeah okay i didn't have the little resistor let me get this plugged in good okay for some reason you know one little thing that i notice is these legs on these resistors are very small and you've got to be they're a little thin and you've got to be a little deliberate to make sure that you've really got them down in there good okay so that was a little bit of a disappointment that that resistor wasn't in there but now i'm going to make g0 and just so that we want to get the full effect here we're going to come up with a 1 again boom look at that all right we will turn it off like that okay now what we will do is we will come in and we are going to [Music] do blue so i'll do b [Music] and that is going to be a one like that and it comes on a beautiful lovely blue and then we'll turn it off shazam who's the magic man i just thought you had to use an rgb led using the gpio pins from the command line and so i think that is just pretty cool i want to play with a little bit more i want to go turn the green on okay turn the green off turn the red on turn the red off and so you see we are controlling this we are controlling this from we are controlling this from the python shell which is just really fun and i think green is really pretty so i'll kind of leave it there i'll kind of leave it there at green okay so i think i need to give you all guys a homework so i've shown you how to do this from the command line and so this is your homework okay this is your homework if you will look in your most excellent if you will look in your most excellent sun founder ultimate raspberry pi starter kit and let's see i think maybe i think maybe i'll go back here to the studio view because uh studio view looks like it's locked up but let me uh let me come back over here to an overhead view all right like this and what i will show you guys is over here in this bag of components in the upper left okay if you look in there what you will find is you will find four large switches okay and let me see if i can i had them out already but now i've got them okay so i guess these things don't don't pop off they are four uh large switches okay like this little buttons okay and then in a separate bag in a separate little bag in this area you'll see the little the little button that goes on top of it so the bottom button switch the black part is in this bigger bag of goodies and then there's a separate bag that has the little color the little color tops on them and there's four of those switches there are four of those little buttons but i only need you to use three of them and those three are going to be the r the g and the b the red the green and the blue okay and then what your homework is going to be what your homework is going to be is going to be to come in here okay it's going to be to come in here and add these switches to your circuit okay and then to write a program and what that program is to do is if i press the red button the the uh the l uh the rgb led turns red if i press red again red turns off if i press green it turns green if i press green again the green turns off if i press this one the it the led turns blue and if i press it again the blue goes off so i can sit here blue on blue off green on green off and red on and red off so that you have a little circuit that will set the color based on which button you press okay does that sound like fun i hope it does and this should really i am hoping that most of you guys i'm hoping that most of you guys will be able to do this because this isn't a very hard lesson this is really just kind of taking what we've already learned and applying it together at the same time to do something that's kind of new and something kind of cool so i think most of you guys will be able to do it now when you do it make sure that you do a screen capture and then you post your homework solution to youtube and then in your description link back to this video so anybody watching your video has context of what you're trying to do and then on my video down below put a comment with a link over your homework solution and when you guys do that i look at every single one of your homework solutions and usually comment because i want to see are you understanding it are there people actually doing the homework and so make sure that you uh make sure that you do that okay guys i hope that you are having as much fun taking these lessons as i am making them as always i want to give a shout out to my patreons it is your support and your encouragement that keeps this great content coming you guys that are not helping out yet look in the description there is a link over to my patreon account think about hopping on over their hand hooking a brother up okay uh also if you like this video make sure that you give it a thumbs up if you've not already make sure you subscribe to the channel when you do ring that bell and you'll get notifications when my future class uh my future videos and lessons are released and share this with other people because the world needs more people coding in doing engineering work and fewer people sitting around watching silly cat videos paul mcquarter from toptechboy.com i will talk to you guys later
Info
Channel: Paul McWhorter
Views: 10,326
Rating: undefined out of 5
Keywords:
Id: nkFw1JfdLLo
Channel Id: undefined
Length: 25min 53sec (1553 seconds)
Published: Thu May 19 2022
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.