What’s Behind the Light? – How WS2812B LED Strips Work

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
wonder how these little buggers work it's not magic [Music] okay i can hear it now some of you are saying you know don't build me a watch just tell me what time it is yes that is true if all you want to do is copy and paste somebody else's code in order to make their project but what if you want to make your own project or more importantly what if you want to learn how to debug your project so we are going to go into a little bit of theory today actually not theory but we're going to examine a data sheet and data sheets have all sorts of pieces of information in them probably more than you need like operating temperatures rise times fall times things like that but there are some real good nuggets in those data sheets that we're going to need to know before we can start investigating the ws2812b led strips now some of you may refer to one of these little lights as an led turns out there are actually three leds one red one green and one blue and they're individually controlled by a small controller on that light now just like the elements on a picture the picture elements or pixels we can change the level of red green and blue independently so i'm going to refer to those little lights for the rest of this lesson as a pixel now the general layout of one of these pixels has voltages coming in or a source voltage which we'll call vcc some people will call it vss and then we've got a ground some people refer to as vdd vss being source dvdd being drain and then we also have a line coming in called data in so three lines are all we need to control this small little pixel all right now once that data well we'll just say the voltages and the grounds are used not only to power the leds but to power the control electronics on this pixel one of the things that happens is when the data comes in and we're going to talk about how that data is formatted when the data comes in you know if you send electrical electrical signals down a path for long distances they get weaker they attenuate they kind of the corners that were sharp get softer the levels that were high get lower and so one of the other things that the controller in here does is when it receives the data it rebroadcasts it back out as d out so that it can go to another led and so this guy can then go did i say led meant to say pixel so this guy can go to another one of these uh pixels as dn will of course have vcc and ground and then it takes its data and boosts the signal cleans the signal up and passes it along to the next device now whenever it comes to vcc there are a couple of things that we need to know in the data sheet and the data sheet really is an important thing to investigate here in the data sheet it doesn't actually tell you how much current draw is happening with the little controller sounds to me like it's negligible but the leds themselves do draw power now this vcc it in the data sheet it says that vcc needs to be greater than 3.5 volts and less than 5.3 volts now this causes a problem for those of us that are going to try and use our raspberry pi's because raspberry pi's operate off of 3.3 volts now as far as the voltage to drive the circuit is concerned as long as we connect it to 5 volts which is available off of the raspberry pi's bus as long as we send that 5 volts here it'll be enough to power a few of these leds but the problem is and we'll get to it in a minute is this data in it too needs to be 3.5 3.7 volts as required by the data sheet we'll see how we can fix that whenever it comes to the raspberry pi the arduinos don't usually have a problem with this because most of the arduinos are 5 volt devices now let's talk about the current now when it comes to the current the vast majority of the current is going to be used by the leds especially when they're on full bright now whenever they're on full they take about 20 milliamps each i've got three leds so that means that i have three times 20 milliamps is equal to 60 milliamps per per each one of those pixels all right and that's just whenever it's full on bright understand that if you don't have an intention to ever make it full on bright for all three of the leds you're not going to be pulling 60 milliamps per led but a string you know for example this short string that i've got right here this is a string of 30 leds and so in order to drive this i need to have a power supply capable of having 30 times 60 milliamps which is equal to 1.8 amps all right and that's more than for example the raspberry pi might have excess to give out of its own power supply you know mostly most of the time the raspberry pi's they run off of three amp wall warts plugs that you plug into the wall that drive them well the raspberry pi is going to pull a lot of that current off two amps possibly maybe even more two and a half amps whenever you're going with the raspberry pi 4. so we don't have the excess amperage we may need to have an excess power an external power supply take a look at the bench top power supply from an atx power supply if you want to get an idea of how to get something like that put together pretty quickly now as i said before the data bits they really need to be you know the voltage so well let's try this again what i've got is a signal that is going to be high and low now the high voltage for this particular signal needs to be greater than 3.7 3.5 depends on the documentation you look at volts all right well the raspberry pi is going to try and drive its data lines with 3 volt 3.3 volts so you may need to have something called a level converter all right now a level converter is pretty simple to use let me erase a little bit of this and we'll talk about how to use a level converter all right now a level converter such as this one about three to five dollars off the internet gives you a number of connections and basically what you're gonna do is on one side you're gonna have the low volt lower voltage device and on the other you're going to have the higher voltage device all right now there's got to be some reference the device needs to have a reference so two of the pins are going to be connected so that you can get that reference one is going to be ground and the other one is going to be connected to the low voltage in the case of the raspberry pi that would be the 3.3 volt source that is coming off of the bus now on the other side what you're going to have is the high voltage ref or the high voltage reference and the associated ground and what this gives us or the electronics is the ability to know okay this is the voltage levels for zero and one that i'm expecting on this side this is the voltage levels for the zero and one the low level the high level that i'm expecting on that side and then it's got a number of connections four on each side all right and these connections will translate voltages that are on the one side to the appropriate voltage level on the other side so you may have the low voltage connection one and then the high voltage connection one and those two will be connected together and the levels will be converted this is not going to be necessary whenever you're talking about an arduino but with raspberry pi operating at 3.3 volts for more reliable operation you're going to need one of these understand that you can't actually just go ahead and connect the data line that you're going to use on the raspberry pi to the data input on these rgb pixels but you may get a little bit of of sometimes things not working just right because the voltage levels are not going to be the same now we are talking about logic ones and logic zeros binary so we're going to be passing binary data off to these rgb pixels now the way it works is that you've got rising edges happening at a constant rate they're going this is this is this is the data line so this is what is expected on data in so you're going to get these rising edges at a regular rate so we expect the bits to come at the to come at a consistent rate now these pulses are going to be coming 1.25 microseconds apart now those micro that and for those of you not familiar with that term 1.25 times 10 to the negative 6 seconds apart so it's that that many so you're going to get a pulse now each one of these pulses is going to represent the starting of a bit now the way we represent a zero is we have a slightly smaller pulse high and a longer pulse low or a longer negative going pulse the way we so this right here would be a zero now for a one you have a slightly longer pulse high pulse positive going pulse and a slightly smaller negative going pulse so this would be a logic one now they do give you times tolerances in the data sheet for what you expect to have these set at specifically if you're looking at a logic zero then you should have about 0.35 microsecond high pulse and a 0.9 microsecond low pulse for a logic 1 you're going to expect a 0.9 microsecond high pulse and a 0.35 microsecond low pulse now there is a little bit of tolerance so it's not going to be exactly the same every time excuse me from device to device or implementation to implementation but in general what you're looking at is you're going to get these regular pulses about 1.25 microseconds apart and what the processor on the led pixel is going to do is it's going to say okay i got my rising edge and then it's gonna read about halfway into that period or halfway into when it expects the next rising edge and if there's a zero guess what that's a logic zero in the case of a one it's going to read about halfway into the pulse and you got a one at that position so you expected a logic one and so the actual data that's being sent is just the series of pulses now when you're writing to the writing to the leds the pixels excuse me you're just going to send all the data together it's all going to be sent as one long block of pixels no delays and the reason because the reason that we can't have any delays is because that any pulse of 50 microseconds or greater and when i say pulse i mean low level this is going to reset the communication um the signal all right now we're going to talk about the importance of resetting that con that communication signal uh whenever we talk about how it is we're going to transfer this data to the pixels but anything that's greater than 50 microseconds and in general if you're just if you're not sending data you just bring that line to a low level leave it low level the next time we are going to send out data then these pulses are going to happen it's going to be considered the beginning of a frame the beginning of the next communication process out to these pixels now let's talk about the data itself um just like any you know any computer type uh interface where you're defining colors you've got your values of red from 0 to 255 this is 8 bits all right and then you've got your green also from 0 to 255 also 8 bits and then you've got your blue also 0 to 255 8 bits so to set the color on 1 pixel we've got 24 bits now those 24 bits have to be passed along to the pixels and the way we do this is that you've got all the data and now that i know how to send a one and a zero now i'm going to put ones and zeros together to make my data and it's going to be broken into well let's see if i've got all of my bits my 24 bits so there are my 24 bits now the first eight bits the patterns of ones and zero this is going to be the amount of green starting with the most significant bit so i've got my green bit seven my green bit six all the way down to my green bit zero and so whatever value i figure out i want for my green i put it right into that uh portion of the pattern of the of the bit pattern now remember these things are coming along at 1.25 microseconds so every one of these bits as they come along they're just right one after the other so there's no break or delay whenever we send the amount of red all right and i think i missed a bit here let's say red there we go and so i've got my red bit seven my red bit six all the way down to my red bit zero and then i send my blue blue bit seven it's supposed to be an r blue bit six and then blue bit zero all right and so there is one color now how does each one of the each one of the leds know which which color is theirs you know they've got we've got 30 in a string then how do we know which color is theirs well what happens is is if i've got my leds set in a row and coming from my processor i've got my data in all right now this first led it's going to get the full string that's sent from data from the processor out to my leds this one is going to grab the first 24 bits set its color appropriately and strip that out of the packet strip that out of the communication then everything that comes after that it's going to pass along to the next led and then that one is going to pull its 24 bits out of the stream and then send and and set its leds appropriately and then send it on down so every time you go down the line you're going to have one less set of 24 bits defining the color also remembering that the that the signal is going to get boosted up and cleaned up as we uh sent it out all right now how are we going to talk about some timing well as an example let's talk about one of these strings of pixels so let's see if i've got 30 leds so i've got a strip of leds similar to this one 30 leds so i've got 30 pixels excuse me pixels right times 24 bits per pixel whoops per pixel right all right so i've got 30 30 pixels times 24 bits per pixel this is 720 bits that i need to send now if i've got 720 bits to send and it takes 1.25 microseconds per bit then how much time does it take to send this whole string well it takes about 900 microseconds or a little it's 0.9 milliseconds all right so at least that gives you an idea of how long it's going to take to send all of this data but what i really want to know is how many leds can i support how long a string can i support and not have what the eye would detect as flicker if i'm just constantly sending out new values to these leds well 80 hertz oops let's try this again 80 hertz is about what you need to send to send data at in order for the eye not to detect a flicker and so if this is the case what we want to do is send new color every 1 80th of a second and so my question is is how many of these leds can i communicate to in 180th of a second so i'm not going to detect any of the flicker well so that means that the time per pixel is going to equal 1.25 microseconds per bit right times 24 bits per pixel which is equal to 30 microseconds and i hope i haven't gone too far off of the screen here let me just try and do this below that means that i've got 30 microseconds per pixel all right now how many of these pixels can i do in one eightieth of a microsec or excuse me 180th of a second well 1 80th of a second is equal to one we'll just say one two five zero zero microseconds and then if we want to divide this by 30 microseconds per pixel this should tell us how many pixels we can have and it turns out we can have 415 pixels and be able to not detect any flicker all right well now it's time to wire up our circuit if you have a raspberry pi or an arduino you'll just need a couple of parts if it comes to the arduino you should be able to just use just this strip of leds maybe an external power supply if it comes to the raspberry pi that you're using you'll also need that level converter you can find ideas of where to find these parts in the description
Info
Channel: Intermation
Views: 49,007
Rating: undefined out of 5
Keywords: WS2812, WS2812B, RGB, LED, pixel, raspberry, pi, arduino, lighting, circuitry, computer, design, digital, logic, organization
Id: rHoFqKGOPRI
Channel Id: undefined
Length: 20min 44sec (1244 seconds)
Published: Sat Feb 06 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.