Arduino Tutorial 42: Understanding How to Use a Serial to Parallel Shift Register (74HC595)

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
hello guys this is Palma quarter from top tech boy comm and we are here today with lesson number 42 and our legendary our epic our new improved series of Arduino tutorials what we are going to be learning today is we are going to learn how to use a pair a serial to parallel shift converter or shift register it is the 74 HC 595 which is kind of a classic serial to parallel converter or serial to parallel shift register and we're going to learn how to use that today this is going to be one of the most intense in-depth lessons that we've had so far a lot of things that we hook up a lot of things that you're going to have to do a lot of new things to learn so I will need you to pour yourself a nice enormous mug of ice-cold coffee you will need it today I will need you to get out your Lego super starter kit if you do not have one look at the description there's a link that will take you to amazon 35 bucks you can get the whole kit and guys seriously it does it is a lot easier if you and I are working with the exact same hardware so when you do this when you get the kit then we're working with the same components and it makes it a little bit easier to learn okay what is this nonsense of a serial to parallel shift register or a serial to parallel converter well you know on the Arduino you have digital pins you have digital pins 2 through 13 which you can do things like control things you can hook leds up to them you can do all types of cool things but you will learn as you start doing projects that very quickly you start running out of digital pins and one of the things is like imagine you wanted to make an LED bar graph okay if you were going to make an LED bar graph well it with let's say 8 LEDs very quickly you're going to be using using up those digital pins and then the other things that you might want to do like let's say that you might want to have some sensors and some servos and things connected you very quickly run out so the idea between a serial parallel converter is is that you have a chip and that chip hooks to the Arduino through just a couple of digital pins and then Arduino pushes the data to it serially it catches the data and then it outputs it to an array of LEDs and so you in effect get free pins when you use one of these one of these shift registers so for today's project you are going to need you are going to need eight LEDs I use four blue and four red it is a special occasion you are allowed to use the blue LEDs today because it is a rather difficult rather involved lesson you need eight 330 ohm current limiting resistors and in your kit you need your 74 HC 595 serial to parallel shift register now notice that there is this serial to parallel shift register in your kit there is also an identical looking device which is a motor controller you have to make sure that you're getting the shift register you have to look at it very closely and you have to read on there the letter 74 HC 595 and when you do that you know that you have the shift register and not the motor controller very very very important okay let's kind of start talking about this thing and how it works let me bring up like a a bond diagram and so again this would be looking at the chip in let's see let me go to this crazy view this is probably the craziest view that I've ever tried to give but this is looking at the chip in this direction and let's go through and let's talk about what those pins are doing alright so the first pin which up here is labeled q1 you see we've got Q 1 Q 2 Q 3 Q 4 Q 5 Q 6 Q 7 and then up and around the corner at 10:15 we have Q zero so from Q zero to q seven we have eight pins those are the output pins those are the pins that are going to be turned high or low so there you could connect eight LEDs or you could connect eight of whatever it was that you wanted to control okay so that's getting the data out you also need to get the data in and so if you go on the pins one two three four five six seven eight around the corner two nine ten and eleven okay pen eleven is a very important pin and pin eleven is the shift register o'clock and so that is going to be your clock signal that allows you to synchronize the data that you're sending out from the arduino into the shift register so that is your clock pin we also are going to use ten twelve in ten twelve is your latch pin so this chip has to know when the data is coming how does it know when the data is coming will you send that latch pin low and then you send the data and then you bring the latch pin high so that latch pin lets the chip no data on the way listen up then the clock pin synchronizes that data so that it comes over smoothly now you can imagine there needs to be a pin that the data comes over and that is going to be pin number fourteen okay pin number fourteen on this chip is the serial data input so Arduino will connect to pin 14 will spit out data so let's talk again about how this works first of all you take your you take your latch pin you set it low and that is pin 12 then you send the data in on pin 14 and then you bring pin 12 back high and then pin 11 and there is working to get the the coordination so that the timing is right don't worry so much about this because there is a simple command an Arduino that will take care of a lot of this I will tell you that the hardest part about this is going to be to get the whole thing cooked up because you can imagine q0 to q 7 we're gonna have to cook hook to LEDs and current limiting resistors you can see pin 8 above is a ground we're gonna have to hook that up at pin 16 has to go to a voltage and then there's a couple of more pins on there we gotta set high or low and so 90% of the battle on this project is going to be to get this darn thing hooked up now this is what we are going to hook up ok 8 LEDs 8 current limiting resistors the 74 HC 595 and then all hooked to the Arduino you can get this little circuit you can get this little circuit I think I'm better off here you can get this little circuit on top tech boy calm if you go to lesson number 42 Arduino tutorial 42 you can find this if you want to look at it in more detail but I'm gonna be hooking it up and you can follow along with me step-by-step as we make this build ok now we are going to go to one of the most insane shots that I have ever tried to create in my history of producing these things so you can see above me is the circuit that we're trying to build you can see over here is a description of the chip in sort of an overview of what goes where I'm gonna have to get further out of your way there you go and then here is a live shot of the build and then here in front right over there I've got sort of another live shot so hopefully with these two long shots and the pin out and me you are going to be able to follow along but let me just kind of start by going to the big view the simpler view and look at this and see what we're trying to do let's build the LED circuits first so we're going to have eight LEDs if you look at this diagram the LEDs all have a common ground and so the ground is going to be the short leg of the LEDs so we just need to stack those LEDs in there and we need to have the short leg going to that top rail and then that top rail we're going to make a ground and so let me go back to our monster shot here all right so I'm going to start and I'm going to start on the left with the blue LEDs and I'm going to be putting the short legs into that top rail okay so let's see what the easiest way to see this is short leg into the top rail and then like that okay short leg into the top rail I am going to skip one row okay I'm going to skip I guess I should say I'm going to skip one column and then short leg into the top rail with a little luck okay this one's a little tough to get in but I will get it okay short leg into the top row we now have two of our LEDs in we will skip skip a column income as such all right and I want to kind of keep them lined up and keep them looking good right now we'll get the fourth one short skip a column and then the short leg into the top row okay so let's see if you can see that nice and good all right I got four in and now we'll come in with the Reds and skip a column let's see if I can get this a little closer there okay so short leg into the top row first red one this is a new breadboard and sometimes the new bread boards are a little hard to get the pins in the first time they go in so okay there we go I got five now skip a column come in again short leg in the top row okay and guys I don't want to force those things in there because I don't want to bend the pins any more than I have to okay and sometimes if you really try to jam it down in there you mess the pins up okay skip a column a short leg in the top row alright so there I have eight LEDs I am kind of obsessive-compulsive and I like them to line up and make a nice little display okay that looks pretty good this one is a little low let me see if I can bring it in alignment a little better that one's a little low okay I would say that looks pretty good so now that is let me see here make sure yeah that is up top there the LEDs in let's go ahead and establish that common ground at this point and so what we know is we know that that whole first row needs to be a ground and so I'm going to bring that in over here I'm going to bring that into the G and D which is right there and so now that top row is in fact a ground and I am wishing that I had a little more focus on this thing let me see if that if that helps okay hopefully that focus isn't too bad there is I'm not as I'm working on this so now I have the ground established now let's go in and let's put in our current limiting resistors and so the current limiting resistor is going to go from the current limiting resistor is going to go from the long leg of the LED and that it is going to stay in the same column but jump across the trench and by doing that I'm not shorting out the current limiting resistor okay so you see that I'm jumping across the column trich I will put in the second one now to the second LED okay that looks good going for the third one and I am just imagining all the hate that I'm gonna get on this but you know it just build it with me if you're so smart that you can just do it looking at the schematic go do it but there's a lot of people that like to kind of be step through things and so don't hate me if I'm kind of trying to step through this for the people that need a little more help okay current limiting resistor number four do you see how I'm trying to keep my circuit really neat everything kind of lined up everything sort of in the proper place and then I will come over here to the first red LED and bring it in long leg and that darn one is not wanting to go in sometimes if your wires are crooked a little bit it doesn't want to go in you got to really kind of try to bring them straight down when you do this this one is quite stubborn okay there it goes make sure that you see I've got things packed in but make sure that the resistors are not touching each other okay make sure the resistors aren't touching each other okay here is the next one okay number seven went right in and now we go to number eight okay now this is where it's very easy to make a mistake to kind of be off by one pin and so what we want to do is we want to come in and verify that each one of those resistors actually is in the same column as its led and then what we also want to do is we want to make sure that none of those resistors are touching each other because we packed them in there pretty tightly and I think that that looks pretty good okay what we want to do now is we want to hook up the other end of these resistors to the control pins on the on the 74 HC 595 and so the first wire is going to need to be a little longer and I'm going to come to this first current limiting resistor and then it is going to go over two it is going to go over two let's look and show it really big here okay that first resistor needs to go over to that q0 okay do you remember the q0 that is pin fifteen okay so I got to be kind of careful with this I got to make sure that I am coming all the way over I'm coming all the way over to pin 15 and so that would be right there okay do you see that remember we count the pins 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 okay so let's see if we can get that thing to focus the focusing with this cameras sometimes the biggest challenge now okay that's not too bad hopefully you can see it it'll get our it'll get a clearer focus here in a minute okay so that's the first one then where does the second one go the second one is going to go in I think I can show it clear here the second led with its resistor is going to go to it looks like pin 1 and so let's verify that here yes q0 was 15 that's output 0 is 15 output 1 is going to be pin 1 ok output 1 is pin 1 and I will speed up here in a minute but I just don't want you to get lost as I'm getting started ok so this next one is going to go to pin 1 ok you see that pin 1 all right the next one this is going to go kind of fast now just make sure that you get in the same column make sure that you don't miss that column is going to come to pin 2 okay you see that the third one goes to pin 2 and then we are going to go 2 & 3 next one to ten for next one to pin five next one to pin six and I'm just going to count to make sure one two okay you see this one two three four five six okay so things are looking that good there and then the last one will go to pin seven all right and then I want to get this wire out of the way I had to use a little bit of a longer wire there all right so DC now we have our ground rail established we have the complete circuit for the eight LEDs hooked up and so what do we need to do now what we need to do now I'm still bugged by wanting these things in here aligned perfectly and it is just not ever going to be as perfect as I would like it on those IDs okay so we have we have our LED circuit hooked up and we've got our ground rail established I like to kind of do this in a in a logical order and so what would be a good thing to do now I think maybe the good thing to do now would be to bring in our five volts to create a five volt rail and we do in fact need a five volt rail so I will do that now I will get a red wire to just remind us that it's five volts I will come from the five volts on the Arduino and then I will come over here and create a five volt rail in that second row okay that second row is now a five volt rail now where does that 5 volts need to go well one place it needs to go is it needs to go it needs to go to the VCC on the chip and where is that VCC that VCC is pin 16 okay where is pin 16 for us pin 16 would be all the way up here in the upper left okay that would be pin 16 and that one is going to need to go to our rail our positive rail okay and let's see what else is going on here I need to do a little tiny bit of bookkeeping here I'm sorry I just need to make sure that I am not doing anything on this side we know what we're trying to hook it up so I'm basically loading up bare minimum so give me just a second here guys don't hate me because of this okay I think I've got things loaded up all right so let's go back we've got our power there let's see there's a couple of other things that need to be connected to that power and let's go ahead and take that take care of that so you see they're creating the power rail on the bottom row and that looks like it is also going to pin let's see eight nine ten okay it's going to pin ten and so let's make sure that we come in and do that and what is pin ten one two three four five six seven eight nine ten that 10 10 is the master reset and so it's active when it's low so if you don't want to clear you want it high okay so if you make it low it reek Lear's everything if you don't want it reek leer you better put it high so master reset is going to go hi and that is just something that we need to do so that would be master reset would be hi so here we come to master reset 1010 and it is going to go high alright so we brought pin 10 10 10 we brought high let's look and see what else we need to do is there anything else that needs to be high so I'm looking at their bottom row and I see that the only thing that they're bringing off of that is that pin 10 alright what else needs to be grounded well it looks like if I have 16 15 14 it looks like 13 needs to be low and so let's see what pin 13 is pin 13 is output enable so if you want the output enabled it's active when it's low well we want an output so we better put 13 low okay so this is 8 9 10 11 12 13 okay this is bugging me that this thing is coming on and off and I wish it wouldn't okay you see we kind of have it in an intermediate state and that's why it's it's blinking on us like that okay so this is pin 13 14 15 16 this is pin 13 and then we said that we wanted that to be low so I will put that in the top row which is our ground rail right our ground rail is that top row and so we now have that 10 13 set love okay well I wish it would focus that good every time maybe maybe I found the sweet spot there all right so let's go back and let's look at this and so we have all the bottom row hooked up we have not grounded we have not grounded the entire thing which we need to do that if we look here let's see what is that pin eight okay pin 8 is the major ground and so we need to do that and for us pin eight is this end one on the bottom okay the end one on the bottom needs to be grounded and that will come up to our top row to ground if you guys don't like doing this with me just skip forward on the video to the coding part and look at it but the reason I do it with you man hooking it up is the hardest thing and so we I kind of talk you through it to let you see how I think while I'm doing it and do you kind of see that I'm trying to be methodical now I have most of it done but we've got to come back here and we have to see that we need a shift register clock we need a latch pin and we need the data input and so the data input which is pin 14 is going to go to Arduino 12 okay pin 14 on the chip is going to go to Arduino 12 so pin 14 on the chip so this is 8 9 10 11 12 13 14 is going to go to pin 12 on the Arduino ok digital pin 12 on the Arduino and let's look and make sure that that's right according to this if these things agree and we can see that 10 12 does in fact go up to 14 all right now let's see what the other thing that we need to do is we need pen 12 to go to Arduino 11 pin 12 to go to arduino 11 so here we have 8 9 10 11 12 so that's 12 on the chip goes to Arduino pin 11 okay 12 on the chip goes to Arduino and 11 and then let's check and make sure that that's in agreement with our main circuit diagram so we have 10 9 10 11 12 goes to and 11 12 goes to 10 11 on the Arduino alright we have one more thing to hook up and what that is the one more thing that we have to hook up is I believe 10 9 which is going to be the clock pin so pin 11 on the chip goes to pin 9 on the Arduino okay 11 goes to 9 so this is 8 9 10 11 on the chip 11 on the chip is going to go to 9 on the Arduino 9 on the Arduino and it was amazing how well that thing focused earlier so you can see we got kind of a a mess here but I feel pretty good I actually feel pretty good because I feel like that we went through it methodically and carefully we got 5 volts we do have a ground that is making everything a ground and I think at this point we are in pretty good shape as far as hoping that this thing is going to work so me try to get those out of the way seems like it really wants to focus back on that it's like it sees the brand it sees the lettering and it really wants to focus on that so let me see if I can maybe I can prop this up and try to help it keep the focus a little better give it something to look at all right sorry sorry I'm not doing a better job on the focus okay well I think we have this thing pretty much built now so now we need to go in and we need to start programming it so let's see if I can find a good code view for you I will come back over here that's our overhead view I could move this up a little bit more like that so you've got a good view of it from the overhead okay so there I think you can pretty much see everything okay so that is kind of all set up now so now we need to start coding so let's look and see if I can find a good coding view for you okay that is not what I want okay that's pretty good that's pretty good all right so we need to start coding this thing and it's pretty straightforward okay it is pretty straightforward we've got how many pins 4 we're using we were using three pins okay and so I'm going to have int latch 10 is equal to remember where did the latch pin go to on our circuit here the latch pin went to 11 on the Arduino so back here in code view we will set we will set latch pin to 11 okay and as you saw there also int clock and was connected to nine and then the data pin which we said was so important I believe that was 14 was connected to 12 so that has set up those critical pins that we send the data those are the ones where we send the data okay now we need to a man I hope you guys watch lesson number lesson number 41 because there we learned about hexadecimal numbers and if you haven't watched that one you got to go back and do it because what we do is we're going to set up a hexadecimal number a hexadecimal number is eight four and four a hex number as far as the Arduino is it is eight bits which then are two characters and so we have to set that up well let's set it up to begin with by setting it how do we declare a hex number we call it a byte and we're going to call it our LEDs and let's just set it to how do I tell it it's fixing to be a hex number zero X that's just saying hey Arduino listen up the number this coming your way is a is is is a hex so 0 X says hex incoming and then what number do I want well if I want to turn all the LEDs on what would that be 1 1 1 1 and then 1 1 1 1 it would be 8 once but to input it as a hex what is 1 1 1 1 that is F what is 1 1 1 1 that is F please go back in watch the last video if you haven't seen it but this is saying that the number that I'm going to send to this serial to parallel converter is F F which is 1 1 1 1 1 1 1 1 what should that do that should turn all the LEDs on now we come down here and we better do our pin modes so I'm going to have pin mode latch pin is an output okay pin mode did I do that right yeah data pin is an output and then pin mode clock pin is out but because all those things we are writing to now you're probably kind of afraid of this clock business you're probably kind of afraid of the clock business but don't worry there's a simple command that will take care of all this clocking nonsense so now what did I say we wanted to do with latch pin when we are ready to send data to the converter the serial to parallel converter we've got to take the latch pin low that's saying data incoming so how would I do that did chit digital right le tch pin low alright now that it's low we want our dueƱo to send out through that pin out through that pin 12 on pin 12 we want to send out the data so how do we do that we do a new command called shift out and what do we do we got to say what pin do we want to send the data out through on the Arduino well we want to send it out the data pin and that data pin was pin 12 and that goes to pin 14 I believe on the on the chip so that is the data pin we also have to tell Arduino which pin to use as the clock pin because that's going to be doing the synchronization so we just say clock and so you see that was all you had to worry about with the clock that clocking goes on between the Arduino and the 74 HC 595 you don't have to worry about it other than telling it where it is connected now we have to do something that is just saying right it's like are you sending the bits in this way where they're going into the least significant bit first or the most significant bit first it's kind of like which order are you sending them in it is least significant bit first okay I could spend 30 minutes trying to explain this to you but I will say the right answer for how we wired the circuit is the least significant bit first if you wired it up differently or you're working on a project and don't understand it doesn't work do the the instead of the least significant bit first do the most significant bit first that's the other possibility and then you got to tell it okay you've got to tell it what is the data what is the data packet that you're sending well for us it's LEDs that's the FF so to send it the FF we say LEDs okay so that we send now what do we need to do well we need to take that latch pin high because we've sent the data digital right and then I have latch pin latch pin like that hi okay so now I want you to think about this when we download this what do you expect okay I set LEDs to FF what is FF 1 1 1 1 1 1 1 1 well if I'm sending all ones to the LEDs what do I expect the LEDs to do all come on why do I turn them all on to begin with because it lets me see it lets me see if I have my circuit hooked up right if I have something cooked up wrong the LED isn't going to come on I do you need you to take a big drink of coffee this is huge a lot of coding a lot of circuit the tension you could cut the tension with a knife at this point what is the chance that this is gonna work what is the chance that I didn't goof something up particularly over here in this latch pin clock pin data pin are forgot aground somewhere there's a lot that could go wrong so I need everyone to hold their breath oh it downloaded but the LEDs did not come on so we have a problem here LEDs is 0 FF we took the latch pin as an output we took the data pin as an output we took the clock pin as an output we made latch pin low we sent data pin clock pin leaks LEDs and then we did a digital right we did a shift out man and we are not getting anything and so I wonder ah a little wire he'd come out my DCC had come out okay but now we are getting partial success but I don't have everything coming in so I need to just come in and make sure that all my wires are in nice and snug okay everything in nice and snug okay like what am i doing I'm making sure that all those resistors that I put in are in fact all the way in and I am having what looks like a difficulty with a couple of these that is in so you see at this point we're not sure is it a circuit problem on the LED circuit side or is it a and let me just go over here I think probably what we're going to do is we're going to give you a better view as I try to debug this thing because the chances are probably more likely it is something not hooked up right so I'm going to come in and put this current-limiting resistor back in and make sure that I get it in okay it's kind of hard to do it when it's in the middle but that should be in what would be another possibility what if I plugged it in upside down the LED and short leg goes to ground that does look good okay short leg to ground that looks good you know what you know what all right sorry for all of that delay but I hope you see you know you look at your circuit you look at the code you look at the circuit you look at the code the chip itself had sort of popped out and so now all of a sudden it is looking a lot more promising okay it is looking a lot more promising the last thing that I wrote was FF so let's come back down here to let's see let me go to this code view okay and then let me add let's say duplicate shot and then I will come down here and I will take this out and I'm gonna get a lot of hate on this I know I am alright so let's go to add another shot and let's add the 920 so now you can see the code and you can see both cameras like that okay so now let's go in and let's start doing some coding and I want to get this where it will stand up better so you can see it yes okay and now I will come and look right at it okay so FF puts them all on we are rolling out man that was painful wasn't it I wonder if it was as painful for you as it was for me now what if I put zero zero of what do you expect hmm what do you expect if I put zero zero you expect them all to be off and boom they are all off what if I put one one well hexadecimal one is zero zero zero one and hexadecimal one is zero zero zero one so we would expect off off off on off on so let's look at that and see what happens boom okay what if I wanted it to go hmmm let's say on off off off on off off off I think that if I am not mistaken would be an eight in an eight let's see boom okay on off off on off off I am just now really wanting to get a more dramatic zoomed in in focus view so let's see if I can get this to focus okay now that is looking pretty good pretty darn good okay so now let's look at another way right on a byte we can put it in and hexadecimal you remember what we could also do instead of 0 x 4 hexadecimal you could also say 0 binary and then you just top them in 0 1 0 1 0 1 0 1 and you can just type in the pad that you want just like that okay oh this should be a zero at zero B stands for binary and then you just put the pattern that you want in there okay hopefully hopefully ah boom look at that okay did you see that now let's go one zero one zero one zero one zero and then that should switch the other one okay alright now that gives me the idea what if we came down here and we sort of copy those control copy and then what if we control pasted and then what have we said delay of delay time and then what if we said delay of delay time okay and then what if we came back up here and made an INT of delay time of five let's make it 250 make it a little more snazzy and then we had an LED one which is that and then what if we had a byte led to which led to s which was equal to the binary zero one zero one zero one zero one okay and now we would down here we would just need to write LED once led where was that LED ones and LED twos now what do you expect this to do go back and forth right wow look at that okay pretty darn neat okay you starting to see how this thing works man I apologize that this was such a painful lesson but you know for me it's like I could go back and when I have a problem I could redo the video right when I have a I could redo the video and then I could go through it and make it work perfectly but I want you to see that you're never gonna do it perfectly and one of the hardest things to learn when you're an engineer or when you're doing this type of project is it doesn't work you've got to figure out why it could be a bad component it could be a bad wire it could be a circuit hooked up wrong it could be bad coding okay so did you see I'd look at the code and look at the circuit I verified that the LEDs were in fact working they weren't burned out I verified my LED circuits and then it was sort of working sort of not working and you could see then I was thinking bad wire bad connection somewhere a bad wire somewhere a bad connection and then what I found was that the chip itself the chip itself had kind of popped out and it was just sitting there but it wasn't all the way in and so it had intermittent connections and that was the problem you will have homework oh yes there will be homework all right so with eight LEDs what could I count to in binary I could count to 255 that would be one one one one one one one one using the shift register I want you to make a binary counter that will count to 255 using the shift register connected to the Arduino now I'm going to give you a warning this sounds real easy but then what it's going to become is it's probably going to become very hard and you're gonna think it's easy and then you're gonna start doing it and then it's going to just be really really really hard so I will give you a heads up I will tell you that there actually is a very very very easy way to do this and just using that the circuit that you have now there's a very easy way to make a binary counter so make it work come what may but be looking for the kind of simpler elegant solution to do the to do the thing it does not take hundreds of lines of code it takes just a few more lines of code very few more lines of code than what we have right now okay this is polemic order from top tech boy comm I hope you guys enjoyed this lesson I hope you understand why when things go wrong I don't stop and and just do the hard part while you're not watching I'm the guy that's trying to help you learn and so I need you of the things that you're learning I need you to learn how to debug and troubleshoot when there's a problem so I'm sorry the video was long but I think there was a real purpose to it give me a thumbs up if you liked this think about subscribing to the channel if you do make sure you ring the bell if you hit that bell you will get a notification when I have new new things posted and really would love to hear your comments down below were you guys able to get this up and working did you have other problems that you know were you able to troubleshoot your problems so let me know really appreciate it when I see that people are actually watching these videos so I will talk to you guys later
Info
Channel: Paul McWhorter
Views: 63,674
Rating: undefined out of 5
Keywords: Arduino, 74HC595, Shift Register, Serial to Parallel
Id: n3qmQHzcgto
Channel Id: undefined
Length: 52min 16sec (3136 seconds)
Published: Tue Dec 31 2019
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.