FastLED Basics Episode 1 - Getting started

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hi everyone and welcome to this mini series on fast lead over the next few videos my aim is to introduce programming addressable leds using the fast led library from lighting your first pixel to the more complex palette wave and noise functions after that it's up to you guys if there's an explanation of something that you'd like to see please leave it in the comments below and i might add that to the list i'll aim to get these videos out on a regular basis uh but real life unfortunately often gets in the way so i'll see what i can do today we're going to cover a number of introductory topics uh they are what fast lead is for and why you might want to use it um the hardware you need how to connect it up and a few notes on power delivery how to start your code the setup function and the fast lead loop and finally just writing your first simple pattern straight from fast lead.io which is the the website of fast load fastlade is in a fast efficient easy to use arduino library for programming addressable led strips and pixels such as the ws series neopixel and more but to start with what actually is an addressable led traditional leds are usually a single color and what you might call dumb if you wanted to control more than a few of them you'd very quickly run out of output pins on your microcontroller this is where addressable leds such as the ws2812b come in these leds are usually rgb which means that each pixel contains red green and blue leds each of which can be controlled separately combining together various amounts of red green and blue means the led can show any color you like as great as this is the real magic comes when you want to control a whole bunch of these leds instead of having a separate wire going to each led we can communicate with hundreds of leds at once from a single pin on the microcontroller the exact way data is transmitted is a bit beyond the scope of this introductory video and it's really not something you need to care about as the fast lead library handles all this complicated stuff for you once you understand fastlane you can start creating your own patterns or even progress to making a matrix or a slightly terrifying mask to get started with fastlad there are two main things we need a microcontroller such as an arduino and an addressable led strip if we want to run more than a few leds you'll also need a power supply but we won't be using one for the moment fast led supports a bunch of different microcontrollers including pretty much every arduino board i've got an uno here a nano it also supports the 80 tiny the lady tiny 85 just there and the teensy which i don't have it supports the esp8266 if you need wi-fi uh it doesn't officially support the esp32 uh i've got one of those there but um i've used these a lot for projects where we need a little bit more grunt and i haven't had any problems however other people have found issues with uh flickering with this board with their lights there is i believe a github fork of fast lead with a little bit more support for esp32 and if i can find that i will link it in the description below choosing which led strips to use can seem pretty daunting there are many different types available at greatly varying price points here are some things to consider when buying an led strip first of course make sure that the led chipset is actually supported by fast lead there is a list of supported chipsets on the fastlake github page the most common ones currently are the three wire ws2812b ws2815 and ws2811 and the four wire apa 102 amongst many many others make sure that you get an rgb strip like the led shown on the left rather than the rgbw as shown on the right so rgbw strips have red green and blue leds and an additional white led in each pixel these strips give out a much nicer white light than just um rgb by itself but unfortunately this time fast lead doesn't support these strips here's to hoping that support comes along for those eventually for the easiest start go for a 5 volt powered strip 12 volt strips are available but this complicates the power requirements you need to move to these eventually maybe if you need long led runs because you get less voltage drop across the 12 volt strips the strips also come in different densities that is the number of leds per meter the most common densities seem to be 30 60 and 144 leds per meter i tend to go with 60 leds per meter for general use remember though the more pixels you have the higher your power requirements are going to be and that is something we need to think about finally uh do you need waterproofing or not if you're not going to need it don't go for it i've got two different strips here this one is not waterproof and you can see the copper contacts there very easy to solder to on the top um this is a waterproof strip it's covered in a sort of silicone rubber coating and the problem with this is and you need to remove the coating if you need to solder to these contacts and you can solder to contacts on the back here if we peel back some of the adhesive here you'll be able to see that there are some other contacts but these are covered by this strip of adhesive so you have to remove the adhesive as well like so in order to actually get to these contacts so for make everything nice and simple i recommend if you don't need waterproofing just go for one of the non-waterproof strips much easier to do my recommendation for a basic strip to start with would be a non-waterproof 5 volt strip with something like a ws2812b chipset and about 60 leds per meter so medium density uh put a link to one of these in the description below of course you're allowed to use whatever you like i just find this one of the easiest ones to use the youtube channel the hookup tested some of the most common strips about a year ago and made a really good video about it and i've also linked that down in the description in case you want to take a look at that the final thing to think about here is how you're going to power your led strip if you only have a few leds you can just use the 5v pin on your microcontroller which is what i'll be doing in the the examples in this series because only be using a few leds and you can hook this up as seen on this diagram for anything more than a few leds however you will need a proper power supply often you also want the usb hooked up as well as you write your programs this is completely fine as long as you follow the diagram shown here it's really important that you connect the ground of the power supply to both the microcontroller and the led strip if you're done using the usb it's also fine to power the microcontroller and the strip from the same 5v power supply and this should be hooked up as shown long strips can demand large amounts of current and it's important to know what you're doing here the maximum current draw for a ws2812bled is 20 milliamps per color per led each led has three colors for 60 milliamps per led total so say we have 60 leds per meter we have a 5 meter strip in theory this could draw up to 18 amps however this is only the case if we have every led set to white at full brightness which almost never happens in reality for long strips like this which draw high current there's a considerable voltage drop along the strip and this can cause the leds at the far end to become much redder as there's not enough voltage to light the blue part of the led here i have a strip that's particularly bad for voltage drop and i'm only powering it from one end every color here is set to white but due to the voltage drop the color gets more and more red as we spiral into the middle and the voltage decreases we can solve this problem using something called power injection and this is where we connect the power supply to the strip every one meter or so as shown in the diagram finally if you're using a four wire chipset like the apa 102 the same wiring diagrams apply but you'll need to connect one more wire from the clock pad on the strip to any digital input on the microcontroller as you can see in the diagram here don't panic about all this though and for our purposes the power consumption will be low so let's hook up some hardware and make some pretty lights we're going to start off simple here so i'm going to connect my parts together on this breadboard i'm going to use an arduino nano as the micro controller uh because they're cheap and easy to get hold of and i'm also gonna use this uh led strip got 18 pixels here 18 leds and these are ws2812b um leds and they have a separation of 60 leds per meter so it's sort of medium density now i'm going to connect the data pin here to pin d2 and the data pin should be connected through a resistor i usually use a 330 ohm resistor but some around 500 ohms something along those lines say is completely fine so let's put that in now when you're connecting up your led strip you want to look carefully and make sure that the data is flowing the correct way so if you look at the green line here this is the data input and you can see the arrows are pointing along the strip this way so that means the data needs to flow that way if you try and put data in from this end uh you're going against these little tiny arrows it's not going to work so make sure the arrow is going the right way i'm going to run this power wise actually just from the 5 volt pin of the um the nano itself so let me just put some jumpers in here for a moment now i don't necessarily recommend running any strips longer than a few leds from the actual power pin of the nano itself you need an external power supply for that but for simplicity for now this is what we're gonna do now it's a good idea to put a capacitor across the the five volt and ground connections just here so i've got a thousand microfarad electrolytic cap size doesn't really matter that much but you know thousands or so microfarads is completely fine uh make sure you get the polarity correct so there's usually a stripe down the negative side of the capacitor so make sure that faces towards ground so i'm gonna put between five volts and ground like that and then let's hook up the strip here so usually these come with wires uh pre-soldered to the end of them uh the white one here is going to go to ground which is this one just here the red strip is five volts and that's going to go to this connection just here and we have the green wire which is our signal wire and that's going to connect to the end of this uh this resistor just here okay so got our hardware all set up and connected um let's head over to the arduino ide and uh dive in and let's get coding so i've plugged the nano in via usb uh make sure if you go to the tools menu here make sure your correct board is selected and the correct com port is selected uh if you haven't done so already you'll need to install the fast led library so go to tools manage libraries give that a second to pop up and then you need to search up here for fast led now i've already got this installed uh you can see here at the top i've got version 3.3.3 which is the most current version at the time of videoing this so the very first line here is hash include fastlab.h that means we're going to be using the the fast layer library we need to make sure we use that every time we do anything with with fast lead of course and then we have a couple of defines so the first thing down here is the number of leds now we've got uh 18 leds in our strip so we've defined num leads being 18. i've then also done another define for the led pin so this is the pin that connects via the resistor to the data pin on the the led strip and then we need to set up our led array so this is called crgb leds num leds so our array of leds is going to be called leads and the size of it is going to be the number of leds that we have which is of course 18 in this case so this array does this stores basically the color data for each one of the leds so if you refer to leads 0 that will be the first led in your strip leads one will be the second led et cetera et cetera then we get to our setup function now the first thing we need to do is to tell uh fast lead where our led array actually is so we're going to use fastlade.ad-leds and then here um is the type of led that you're using now i'll put a list up here of the various types that fast lead accepts i'm using ws2812b type so i put that in there the next parameter here is the led pin which we've defined to be two so that's the data pin for your leds and then the final parameter here is the color order now i found when using lots of these led strips that grb seems to be a pretty common color order but it could be grb rgb bgr whatever and it's a big a matter of messing about with this basically to find out which order that should be in in fact that's what we're going to do in a few minutes time then we need to set the brightness oh we don't have to do this but it's good practice um i've set the brightness here to be 50. like most numbers in fast lead this number here is what's called a uint 8 underscore t that's an unsigned 8 bit integer in english that basically means a number between 0 and 255 lots and lots of numbers in fast lead are these these types of numbers between zero and two five five it's actually incredibly helpful uh it means vaseline can do maths on them much more quickly uh than it could if they were floating point for example so a brightness of 50 will be plenty bright enough we don't want to set this too high because remember we are running this off the uh the usb port so we don't pull too much current through our usb port on the pc here so that's our setup function the very basic setup function uh done and then let's go on to our loop so the way the fast led works is that you set up the colors basically of the led in your leds array and then at the end of it you write fastlead.show and that writes out that array to the leds so what i'm doing here is i'm setting led 0 to be red led 1 to be green and led 2 to be blue so and then we should be setting that in the array and then we're showing it we're sending all our data out to the strip now the reason why i'm doing this is because i want to check that for this strip here this is the correct color order so if we do that now so if we upload that and if we have a look at our strip here we can see that we do have the first led is red the second led is green and the third led is blue so that means the grb was the right color order for this so now we know that our color order is correct for our strip i've changed the loop function here to make a something a little bit different so first of all this line here is telling the first led in our array so that's led 0 to be red and then we call fast lead dot show to kind of write that out to the strip and then we delay for 200 milliseconds after 200 milliseconds we then turn our first led in the strip black so turn it off basically and then we write that information out to the strip with fastlab.show and then we delay for another 200 milliseconds and what we're basically doing here is we're blinking our led on and off not particularly exciting but hopefully you can see how this works now one little comment here is that using delay in fast lead patterns is very much frowned upon and in fact in arduino programming in general it's not normally a very good idea and that's because during delay your arduino can't do anything else over the next couple of videos i'll show you a much better way of doing this but hopefully this is understandable for the moment now let's make the led look as though it's moving back and forth along the strip so i've changed the loop function here again it looks a little bit more complicated but it's not that bad if you understand arduino programming it shouldn't be too tricky so we've got a for loop setup and basically it's going to start off with i being zero so it's going to start off with the first led in the strip and we're going to set that to be red then we're going to show it so we're going to write that data out to the strip and we're going to wait for 100 milliseconds or a 10th of a second after a tenth of a second we're going to turn that led off we're going to switch it to black and then we're going to repeat the loop but for the next led in the strip so at this point i will be one so that'll be the second led confusingly in the strip we're going to make that red we're going to show it then we're going to turn it off and then we're going to make the third led red etc etc and that's going to make it look as if the led is moving along the strip when it gets to the other end we're basically going to do the opposite we're going to move it back so we start off at the maximum number of leds or sorry 17 18 minus one and we're going to step back i minus minus we're going to subtract one from that each time so we start off on led 17 being red and then it'll be 16 15 14 13 etc until we get back to the other end again i now want to have a look at some of the fill functions and the first one i want to look at here is fill solid and what this does is it will fill a certain number of leds with a solid block of color so the first parameter in here is just the led array which is leds or leds we defined that earlier on up here the second parameter is how many of those leds from zero do we want to fill up i've put numled so we can fill all of the leds in our strip and then the final parameter here is what color do we want to fill that with and i put red in this case i then told it to write that data out to the led strip and then wait for half a second and then do the same thing for green and the same thing for blue so let's upload that and you can see that our strip is behaving itself it's flashing red green and blue at half second intervals let's now have a look at the fill gradient function so this is fill gradient rgb because we're using rgb colors uh in here we'll talk more about colors during the next uh video because it's a really important thing to understand on fast lead if you understand how colors work it makes things a lot easier uh there's a few different parameters here for this leds again like earlier this is our array that contains the information about our leds then we have the num leds so how many leds do we want to fill and then i put two different colors here magenta and yellow and so what that will do is it will start a magenta at one end of the strip and yellow at the other end of the strip with a nice gradient in between those two you can actually have up to four colors in one of these gradient fills so here i've got red yellow green and blue and that gives a nice little sort of rainbow effect so let's upload that and see what that looks like finally then one last function to have a look at and that's fill rainbow just because it makes a really pretty pattern it starts off very similar to fill solid and fill gradients we've got leads that's just a reference to our led array number the leds that we want to fill up so i'm just putting them lead so we fill up all of them uh this next parameter here zero this tells you what value of hue to start off in fast lead hue is another color and um hue runs from zero to two five five well again we'll talk about this in more detail on the next video and then the final parameter here is the delta hue so how much do we change the hue by as we go from one led to the next so if i want to go all the way through the rainbow uh from one side to the other i want to do 255 that's the whole hue from one into the other uh divided by the number of leds we've got and that should give us a lovely rainbow effect so let's have a little look at that thank you very much for watching and i hope you found this useful as you start on your fast light journey next time we'll be looking at how fast led handles color a pretty important topic so if you want to know about this as soon as the next video comes out please do consider subscribing and helping me out all right hope to see them bye bye for now
Info
Channel: Scott Marley
Views: 253,451
Rating: undefined out of 5
Keywords:
Id: 4Ut4UK7612M
Channel Id: undefined
Length: 17min 59sec (1079 seconds)
Published: Fri Oct 16 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.