Three wires to rule them all: CD4094 & CD4021 shift register tutorial

  Переглядів 10,836

FriendlyWire

FriendlyWire

День тому

What do you do when your microcontroller doesn't have enough pins? Today we will learn how to use the CD4094 output-type shift register and the CD4021 input-type shift register to control LEDs and read out the status of pushbuttons, and all of that with only three wires.
Thanks for watching, and let me know in the comments if you have any questions!
Companion article: www.friendlywire.com/tutorials...
Email list: www.friendlywire.com/email
Website: www.friendlywire.com
Twitter: / friendlywire
Reddit: / friendlywire
Facebook: / friendlywire
Instagram: / friendlywire
Timestamps:
00:00 Introduction
01:14 What you need
01:52 Main idea
02:57 CD4094 on the inside
04:43 CD4021 on the inside
06:12 Getting started with our PIC16F1455 microcontroller
09:59 One CD4094
14:24 Adding another CD4094 in series
17:01 One CD4021
21:11 Adding another CD4021 in series
23:29 Reading out an SNES controller
25:25 Final thoughts

КОМЕНТАРІ: 89
@Raze_134
@Raze_134 Рік тому
It's not very often I see new stuff from this channel but when I do, I know it's going to be good. Great info and great presentation!
@FriendlyWire
@FriendlyWire Рік тому
Thank you so much! :)
@TheScissorunner
@TheScissorunner Рік тому
Your breadboard layout is nothing less than artwork!! Incredible content as usual! Thank you!!!
@FriendlyWire
@FriendlyWire Рік тому
Thank you so much, Craig! I find making these breadboards very relaxing, almost like doing a jigsaw puzzle.
@bob-ny6kn
@bob-ny6kn Рік тому
I really like how your videos show elementary tasks (introduce components, place components, connect wires, type code, et c.) with creating advanced results, and your companion articles are a great resource to follow at a slower pace. Your work is just right.
@FriendlyWire
@FriendlyWire Рік тому
Thank you so much, Bob, much appreciated!
@sweetlilmre
@sweetlilmre Рік тому
Excellent tutorial, the layout and visualisations were superbly done!
@FriendlyWire
@FriendlyWire Рік тому
Thank you so much, glad you like it!!
@ericdavey6702
@ericdavey6702 Рік тому
Haha! Love the LOTR reference!
@FriendlyWire
@FriendlyWire Рік тому
Glad you like it :D
@karkerav1175
@karkerav1175 Рік тому
Hi.... Excellently good tutorial to understand shift registers many thanks!
@FriendlyWire
@FriendlyWire Рік тому
Glad you like it, thank you so much!
@santiagovaldez5176
@santiagovaldez5176 7 місяців тому
Awesome video! But let me tell of you a trick: there's a way to use only 4 wires instead of 6 to have expandable inputs AND outputs. This is great because you can use cheaper MCUs that have only 4 I/O pins instead of 6 or more. Another benefeat of this method is that you replace the input shift register for another output one, and it's generally cheaper to buy a pack of the same ICs. Basically you need: 3 output pins 1 input pin 2 output shift registers 1 resistor And as many diodes as buttons you want. Using this method you can expand your I/O pins from 4 to whatever you want If you or someone wants to know about this method let me know
@FriendlyWire
@FriendlyWire 7 місяців тому
Interesting, I think I may have seen that trick on UKposts somewhere, thanks for sharing! It is also possible to do everything in this video with four wires, because you can basically share the CLOCK wire between registers (which I didn't do for simplicity) and also the DATA pin (also didn't do, because I wanted to keep things simple). So: one wire for data, one wire for clock, and then two enable lines, and that would get you an infinite number of inputs/outputs (at least in theory) :)
@DavidHancock7
@DavidHancock7 Рік тому
Just found this channel- these videos are amazing- keep up the great content
@FriendlyWire
@FriendlyWire Рік тому
Thank you very much, David, I am very glad you like the videos!
@kckc9245
@kckc9245 Рік тому
Thank You 👍😎 Excellent Tutorial .. Good for LED lights on the buttons for an Arcade Machine ..
@FriendlyWire
@FriendlyWire Рік тому
Thank you, glad you like it! Yeah, these are perfect for smaller LEDs. For bigger LEDs also check out my video on the TLC5916 driver: ukposts.info/have/v-deo/faOGrI2GZ29nrWQ.html
@ahmedalkabir543
@ahmedalkabir543 Рік тому
thanks for neat tutorial, keep it up brother, I like your approach of teaching and giving information.
@FriendlyWire
@FriendlyWire Рік тому
Thank you so much, Ahmed, much appreciated! And will do, I have no intentions to stop anytime soon. What would you like to see next in a video?
@ubike3948
@ubike3948 Рік тому
Amazing explanation!
@FriendlyWire
@FriendlyWire Рік тому
Glad you like it!
@simonyovino2126
@simonyovino2126 14 днів тому
Thanks! Very helpful
@FriendlyWire
@FriendlyWire 14 днів тому
Thank you, Simon, much appreciated! :)
@David_11111
@David_11111 Рік тому
yay seems useful
@Gkid8
@Gkid8 3 місяці тому
I just wrote code like this last night and would have saved me a lot of code had I seen this first...
@FriendlyWire
@FriendlyWire 3 місяці тому
Glad the video is helpful! Oh cool, what are you building?
@Gkid8
@Gkid8 3 місяці тому
I was trying to make some sort of screen out of LED's. I'm not sure how to effectively that will work out but it's fun to try. The shifting works with two shift registers but now I need to see if I can do pwm with them and control each light.
@FriendlyWire
@FriendlyWire 3 місяці тому
@@Gkid8Oh I see! In that case you can also try to use the TLC5916 (video on my channel) or the MAX7219 (also video on my channel) if you are OK with multiplexing. Good luck!
@Gkid8
@Gkid8 3 місяці тому
@@FriendlyWire The MAX7219 seems really nice but the price point it pretty high for my price range. I might as well buy an arduino screen I feel like for $11. The TLC5916 has a better price and I will have to check that out. What I was trying to do with shift registers was multiplex something like 32 LED's on the input and output side to make a screen. This is a project I started 5 years ago and left it in a bin. I'm only circling around to it again as I was cleaning things up and remembered I didn't know how to finish this back then. My initial design may need some changing but we will see.
@FriendlyWire
@FriendlyWire 3 місяці тому
@@Gkid8The MAX7219 is expensive if you buy it separately, but you can get it in ready-made modules on many websites, and that will be cheaper (even as a DIP chip). Send me an email if you want and I can show you (you can find my email at the bottom of www.friendLywire.com). Your project sounds fun!
@yamitokyoo
@yamitokyoo Місяць тому
"It activate it like Minecraft piston." Lol, that's fun. I am amaze by this presentation. I am frustrated in understanding this because mine doesn't work and I am switching from 74HC165 to CD4021 shift register due to it's lack of information to fix that or do that shift register and it is just annoying.
@FriendlyWire
@FriendlyWire 26 днів тому
I am glad you liked the video! Yes, it can be very frustrating... Sometimes it helps to just have the shift register, with LEDs at all outputs, and pushbuttons at the input pins (with debounce capacitor and pulldown/pullup resistor) to check everything step by step. Have you tried that? Let me know if this helps. If not, I can explain more. Don't be discouraged by this. It is a normal experience, and I have had similar experiences, too. I almost gave up many times. But I know you can do this :)
@yamitokyoo
@yamitokyoo 12 днів тому
@@FriendlyWire I actually did it. I didn't know 'shiftIn()' function actually works but it is quite tricky at timing. I just keep on believing on it that it'll work until it did and made me so happy. Also, for people reading this I don't recommend using breadboard I recommend soldering it in a temporary soldering board because breadboard can have a chance of loose connection of the resistors causing it to read different.
@FriendlyWire
@FriendlyWire 12 днів тому
​@@yamitokyoo I'm glad that it works now, congratulations! Awesome job, and thank you for sharing!! Yes, the timing can be a bit tricky, in the sense that if you do the clock pulses too quickly it may be too fast for the shift register. This is why I run these examples here at 4MHz (effectively 1MHz with PICs) which is slow enough so we don't have to worry. I am glad you got it working on a PCB! I like breadboards because they are so flexible, but if you get a bad breadboard it can be extremely frustrating because of loose wires/bad connections. Glad it worked out! :)
@NionXenion-gh7rf
@NionXenion-gh7rf 11 місяців тому
Where you learned pic programming, what books do you recommend? Do you plan some videos about wireless connection of PICs in the future?
@FriendlyWire
@FriendlyWire 11 місяців тому
Good question! I learned C from a book, but in all honesty this was all useless to me for working with PICs. I basically looked at peoples' codes and tried to understand them, one by one, this was the easiest for me to learn. Wireless stuff is interesting, but it is quite far away from the level at which I place these tutorials here. If you have a link to what you have in mind, I would love to check it out! :)
@misterretrowolf1464
@misterretrowolf1464 Рік тому
Your videos are incredibly well made. So much respect to you!! Could you give a hint what you use to do your animations?
@FriendlyWire
@FriendlyWire Рік тому
Thank you so much! I am using GIMP to draw the images, and super-impose them by hand in DaVinci Resolve (using keyframes) :)
@misterretrowolf1464
@misterretrowolf1464 Рік тому
@@FriendlyWire ah ok. I use DaVinci too, so I can only imagine how long that takes. The effect is amazing though. Well done for the hard work.
@FriendlyWire
@FriendlyWire Рік тому
@@misterretrowolf1464 Thank you so much! The real problem is the amount of video tracks, especially when there is overlapping motion. I think in this video it was a new extreme and around 35 at some point.
@misterretrowolf1464
@misterretrowolf1464 Рік тому
@@FriendlyWire yes exactly!I was marveling at the fact your numbers move in a curve, when you could much easier moved them straight! True attention to detail.
@FriendlyWire
@FriendlyWire Рік тому
@@misterretrowolf1464 Yeah that was a bit painful to animate, but I knew that my audience has a keen eye! :)
@David_11111
@David_11111 Рік тому
I wondered how you animated the bread board wire arriving ?
@FriendlyWire
@FriendlyWire Рік тому
I took separate photos (around 180 of them) and aligned them using a function in Photoshop. Unfortunately, Photoshop is the only program I could find (so far) that does a good job at that.
@hola3535
@hola3535 2 місяці тому
It might be posible to adapt the extra buttom of the SNES controller to the input of a NES controller with this trick?...and how will be perceive by the NES console? ... Will be great if all the above wiil be made into the single motherboard of the SNES controller.
@FriendlyWire
@FriendlyWire 2 місяці тому
Thanks for the question :-) I am not sure if I understood 100%, but yes, it should be possible to connect the CD4021 to the NES, to make it think that it is a controller. Is that what you meant? :)
@helectro3021
@helectro3021 6 місяців тому
Thank you, but how can this be implemented with 4 pins instead of 6 using esp01?
@FriendlyWire
@FriendlyWire 6 місяців тому
In the video I describe how the CD4021 and CD4094 work, you can implement this on any microcontroller platform you like. I use 3 pins for the CD4021 and 3 for the CD4021. You could perhaps the clock pins, and also the data pins maybe. Do you have a schematic or program to follow?
@ebbewertz3417
@ebbewertz3417 2 місяці тому
Is the output of the output-register a separate storage register or only a latch? I am searching for a shift reg where I don't disturb my outputs while shifting and I found this one. It looks to me that it has an output storage register + a latch for OE, but this makes me wonder why it's so much cheaper then the 74HC595.
@FriendlyWire
@FriendlyWire 2 місяці тому
Yes, this one is latched! I think the 595 is probably more expensive these days because it's older and used in a bunch of legacy equipment?
@lubdar
@lubdar Рік тому
This is so helpful!! I'm curious though if the VDD for the 4094 shift register can be lower than the VDD for the Microcontroller. In your example, both microcontroller and 4094 are running at +4.5V. Can we connect a microcontroller running at +5V to a 4094 running at +3.3V or will that damage the 4094?
@FriendlyWire
@FriendlyWire Рік тому
Thank you, glad you like the video! It's generally not a good idea to run logic chips on the same circuit at different voltages. Is there any reason why you need different voltages?
@lubdar
@lubdar Рік тому
@@FriendlyWire My apologies for the delay. The main logic chip I am using runs at 3v3, but the PICs i program i typically run at 5v. I was able to test some things on the breadboard and get things to work together just running my PICs at 3v3 now instead. Thanks again for your help. My next question is how this relates to SPI. I've seen that microchip has some digital potentiometers, but they require SPI to communicate and I'm thinking there is a connection somewhere in there.. but I've just got to keep looking... :)
@FriendlyWire
@FriendlyWire Рік тому
@@lubdar A lot of PICs can run just fine at 3V. The PIC16F1455, for example, works fine in the range of 2.3V to 5.5V. SPI is a serial protocol to transmit and receive data with other devices. Do you have a datasheet for this potentiometer? What do you want to build? :)
@lubdar
@lubdar Рік тому
@@FriendlyWire Thanks So much!! I apologize for my delayed response. I'm kind of all over the place with exploring and learning new bits of code at the moment, I would like to digitally control the nuvoton ISD17120PY voice recorder to record and play back audio recordings. Needless to say, my limited knowledge of SPI is holding me back. But this video has helped me and I have even incorporated the CD4094 into a current project so thank you, again for creating these videos!!!
@FriendlyWire
@FriendlyWire Рік тому
@@lubdar No worries, I know this hobby can consume a lot of time when we're learning new things. I am so excited to hear about your progress, congratulations! Let me know if you have any questions, I will be happy to help, and thank you for your kind words!
@mikelarrutiromero9430
@mikelarrutiromero9430 6 місяців тому
Nice! I don't know anything about electronics. Well, I know some stuff and have repaired some things. Currently I'm working on some kind of modular pinball machine that is driven by a program on my PC. The problem is, I need an IO interface board with enough inputs and outputs to drive the switches, lights, coils... Thing is that they should be able to turn and stay on at the same time, so a multiplexor might not work for me. Instead, could this be a good solution for me? To clarify, I need about 96 inputs, 80 output for lights, another 67 outputs for relays, and about 10 outputs for extra stuff. I might need to add more of them in the future 😅
@FriendlyWire
@FriendlyWire 6 місяців тому
Hey Mike, I am glad you liked the video! Yes, this may be what you need. You can use a shift register in combination with an ULN2803A driver chip to drive your relays, and that chip also has a protection diode built in. For the inputs you can probably use the CD4021 as is. And I guess the refresh rate of this is low enough that you will get away with having all registers in series (and you can always add more in the future). Let me know if you have any questions, I am happy to help.
@mikelarrutiromero9430
@mikelarrutiromero9430 6 місяців тому
@FriendlyWire thanks! That is awesome! I'll try my best, but I will definitely reach out for you if I get stuck ;) Many thanks, brother!
@FriendlyWire
@FriendlyWire 6 місяців тому
@@mikelarrutiromero9430 Happy to help, and best of luck! Projects like this are a lot of fun :)
@fench1234567
@fench1234567 6 місяців тому
So for use with arduino Atmel and/or arm based boards, which is a better idea: the cd4094 or the 74hc595?
@FriendlyWire
@FriendlyWire 5 місяців тому
I would always recommend CMOS chips due to their wider operating voltage, so: the CD4094. But it depends on what you want to do with it. Remember that the CD4094 is not an LED driver, it can merely supply logic signals at its outputs. If you want to drive LEDs, I recommend the TLC5916 instead ( ukposts.info/have/v-deo/faOGrI2GZ29nrWQ.html ).
@fench1234567
@fench1234567 5 місяців тому
@@FriendlyWire Thank you! I'll take a look!
@FriendlyWire
@FriendlyWire 5 місяців тому
@@fench1234567 Happy to help, and let me know if you have any questions :)
@aSameplayer
@aSameplayer 2 місяці тому
Man würde also Anschlüsse am Prozessor oder Controller sparen, aber gibt es denn auch ne möglichkeit die Uhrschläge zu sparen. Also die Clock Cycles. Dadurch dass man nun die Daten seriell sendet benötigt man doch für jedes bit einen Impuls. und so würde man doch in einem System, wie einem Game Boy oder der NES wichtige Rechenzeit für den Input nutzen. Könnte man dafür nicht einen weiteren Prozessor nehmen? Einer der nur auf die Inputs achtet?
@FriendlyWire
@FriendlyWire Місяць тому
Die Rechenzeit dafuer ist minimal, weil du die Inputs ja nur maximal einige hundert Mal pro Sekunde abfragst, es geht ja um menschliche Computereingaben, und nicht um digitale Signale. Wenn Du schneller reagieren moechtest, dann ist diese Auslesemethode in der Tat nicht die idealste, aber fuer Konsoleninputs reicht es alle mal :)
@aSameplayer
@aSameplayer Місяць тому
@@FriendlyWire Verstanden. Danke für die Antwort.
@FriendlyWire
@FriendlyWire Місяць тому
@@aSameplayer Keine Ursache! :) Lass mich wissen, ob Du noch weitere Fragen hast, ich helfe gerne.
@Ori_Zappa_Rocks
@Ori_Zappa_Rocks Рік тому
if i use only 5v power, how much resistance in need for Clock, Latch and Input?
@FriendlyWire
@FriendlyWire Рік тому
You can run this circuit exactly as-is with 5V as well, no changes necessary :)
@Syeda-Hadia
@Syeda-Hadia Рік тому
Hi, Sir I hope u are doing good. I just wanna ask one thing , in one of your videos in which u are multiplexing max7219 dot matrix module with pic microcontroller, in that tutorial u have used pic16F1455, Sir can I use pic16F877a microcontroller and what should be the changes in pin connections plus the program code. Can u please please guide me regarding this it would be of great help. Best wishes for you... Sir u just have clear explanation that is why I'm bothering you, I literally need a guidance for my project.
@FriendlyWire
@FriendlyWire Рік тому
Yeah, of course, it is possible. Did you follow the MAX7219 tutorial? If yes, the next step is to set up a project for the PIC16F877A in MPLAB. Does that work already? If yes, we can do the next steps :)
@Syeda-Hadia
@Syeda-Hadia Рік тому
@@FriendlyWire Sir I'm a bit confused for the pin connections of pic16F877a with max 7219 module? And would the entire code be same as it is for another microcontroller?
@FriendlyWire
@FriendlyWire Рік тому
@@Syeda-Hadia You can connect the pins anywhere you like, you just need to change the code :) Do you have some experience in coding?
@Syeda-Hadia
@Syeda-Hadia Рік тому
@@FriendlyWire Sir i love to code but not much know, sir can u please guide me?🤞
@FriendlyWire
@FriendlyWire Рік тому
@@Syeda-Hadia I would love to, but it's a bit difficult within UKposts comments. Can you reach out on Twitter? (Email also works, you can find it at the bottom of my website www.friendlywire.com)
@leonardhehlen2293
@leonardhehlen2293 Рік тому
title recommandation : hack every video game controllers with this shift register Let's get trending haha
@FriendlyWire
@FriendlyWire Рік тому
Haha! :D
@liantooot1706
@liantooot1706 3 місяці тому
Make 3 digit, pleace
@FriendlyWire
@FriendlyWire 3 місяці тому
You can add a third shift register in series :) See here for cd CD4094 (www.friendlywire.com/tutorials/cd4094-cd4021/#ch6) and here for the CD4021 (www.friendlywire.com/tutorials/cd4094-cd4021/#ch7). Let me know if it helps!
How to use rotary encoders
14:12
FriendlyWire
Переглядів 24 тис.
How to Control a Ton of Inputs using Shift Registers!
19:38
Kevin Darrah
Переглядів 310 тис.
Не пей газировку у мамы в машине
00:28
Даша Боровик
Переглядів 1,7 млн
😳 Домінація! ОГЛЯД БОЮ ЛОМАЧЕНКО - КАМБОСОС
04:06
Are PIC Microcontrollers Any Good? - Beyond Arduino #4
21:07
Sine Lab
Переглядів 35 тис.
Controlling a BIG LED Matrix?! How Shift Registers work! || EB#39
12:33
Making a latching relay with 555 timer
7:08
Crucial Lab
Переглядів 43 тис.
Very advanced Indo street light
26:01
bigclivedotcom
Переглядів 152 тис.
NE555 tutorial: three useful circuits
16:09
FriendlyWire
Переглядів 77 тис.
Visualizing Data with 7-Segment Displays
34:26
Sebastian Lague
Переглядів 1,2 млн
Let's build a voltage multiplier!
16:32
Ben Eater
Переглядів 1,8 млн
Port Register Control | Increase speed of Read/Write - Arduino101
15:22
Control LEDs with your computer using RS232!
16:09
FriendlyWire
Переглядів 56 тис.
Не пей газировку у мамы в машине
00:28
Даша Боровик
Переглядів 1,7 млн