How to use WS2812B RGB LEDs with Raspberry Pi

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
g'day if you've got some addressable LED strip and you don't know what to do with it and a Raspberry Pi this tutorials for you we're just going to quickly show you how to get some example code running to power your strip of ws2812 B LEDs these are also known as mere pixels let's get started just before I get too ahead of myself this tutorial assumes that you're comfortable using the Raspberry Pi in its desktop environment or as a desktop computer so if you're not you can check out chapter 1 of our Raspberry Pi for beginners workshop which is a free online course ok now let's get started so the first thing you'll need to do is wire up your Raspberry Pi as shown in the diagram here what we have is our Raspberry Pi at the top with ground and power connections coming onto this bus and that's just feeding the low-voltage side of a logic level shifter we have our signal coming from the PI and that's going into the logic level shifter we need this because the PI is a 3.3 volt device but our LED strip down the bottom is a 5 volt device so we need to translate between those voltage levels and then on the other side we just have the signal coming out which is now at 5 volts going into the data for the LED strip and then we're just powering the strip from what's pictured here is a DC barrel Jack I'm actually running it from a lab power supply today but there's no difference so the first thing we need to do is install some packages so what we're going to do is just scroll down and I have this this convenient little one-liner here that we can paste into our terminal so you can go up to the top and open the terminal from this button and then just right click to paste so what's going on here is our raspberry PI's in tech package indexes are being updated and then some some Python wrappers are being downloaded so that we can drive LED strips that's also going to come with a few example scripts that we're going to be able to run so we'll just wait for that to complete so those packages have finished downloading and if we execute the LS command we'll be able to see the contents of the current directory and what we're interested in is this package that was just downloaded here so what we can do is CD into that with our partners going to use tab completion and I'll just double tap tab again to remind me what's in that directory so I want to go into Python double tab again and I wanna navigate into examples double time so I've changed into a nested subdirectory and in this subdirectory we have our example Python scripts so the one that I want to run is this strand test top py so what I can do is I have to run this with sudo by the way I see you do Streatham strand test up py and hit enter so this is worked for me straightaway if you are getting some erratic behavior he like the LEDs are kind of flickering in an unpredictable way and it's just kind of nonsense looking I'll show you how to rectify that now so we can just admire this this demo for a little while but it's quite neat if you didn't get this result that I'll show you one way that seems to work for fixing it so I'm going to press ctrl C to quit the script and what we need to do is modify a certain file so I need to run sudo nano I need to edit the file / boot slash config dot txt this is a config file that affects how the raspberry pi starts and operates so if I hit enter we're now editing the file from within the Nano text editor and the changes that I need to make are documented just down the page a little bit so I need to add these two lines HDMI force hot-plug equals 1 and HDMI force something to do with the audio so I'm going to copy that and over in Nano I'm just going to scroll down to about where it should go it doesn't matter where it goes I'll just find the right group so you can see we have here we go so this line says uncomment if HDMI display not detected yadda yadda but this is this is one of the lines that we have paste in but it's just commented out here so what I'll do is press the Delete key to just uncomment that so it's now an active piece of code and I'll right-click and paste the arrest so now I've got two entries for that pop like I can't use the mouse to navigate I have to use the key so I'll just go up and delete that line so now that we have those two lines that exist in our boot config text file you can press ctrl X to save and then you're prompted do you want to save and you just say Y for yes and we absolutely don't want to change the name so I'm just going to press ENTER for this so now that we've edited our config text file to what it needs to be we can just execute sudo thumbnail even have to be sudo it's just us execute reboot now if you execute reboot your ass or power will boot up again and then you can just have another crack at running that pseudo pythons strand test command and you should get something that looks pretty similar to this so now that what everyone hopefully everyone has their LED strip working what I might try is to modify that file to see if we can make it do something a little more interesting so what I can execute is Nana and it was called strand test and here's our Python script so straight away the very first parameter that's quite important is the LED cap this is how you set the length of strip that you have so if you were working with only one LED this would be a pretty uninteresting demo but I'm working with a whole roll of LEDs so what I can do is backspace that and I'll just put in a hundred for now before ready wired up to P 19 that's why it's working in the first place and the rest of these parameters I can forget about is there anything that's worth changing in here oh I've got something for some functions where's the main piece of code I might just speed things up a bit I think here we go this is the main piece of code so this is just executing and it seems to be executing about as fast as it can so I might just save that now with the control X and they yes to safe strand test and now if I run strand test again I should see that going all the way down the role and in date you can see that spiraling all the way into the center of the strip until it's only filled 100 le days so I could have made you push that to like 150 160 I'm not quite sure how many LEDs are on this roll that'd be pretty easy to calculate so there you have it a quick stop guide to getting your addressable LEDs working with your Raspberry Pi I'll catch you next time [Music] [Applause] [Music]
Info
Channel: Core Electronics
Views: 206,071
Rating: undefined out of 5
Keywords: ws2812, ws2812b, raspberry pi, led, rgb, tutorial, guide, how to
Id: Pxt9sGTsvFk
Channel Id: undefined
Length: 7min 16sec (436 seconds)
Published: Thu Sep 14 2017
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.