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

  Рет қаралды 11,667

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

Пікірлер: 91
@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! :)
@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!
@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.
@koomber777
@koomber777 16 күн бұрын
I subscribed by the end of the intro
@FriendlyWire
@FriendlyWire 16 күн бұрын
Thank you, I am glad you liked the video! :)
@sweetlilmre
@sweetlilmre Жыл бұрын
Excellent tutorial, the layout and visualisations were superbly done!
@FriendlyWire
@FriendlyWire Жыл бұрын
Thank you so much, glad you like it!!
@santiagovaldez5176
@santiagovaldez5176 9 ай бұрын
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 9 ай бұрын
Interesting, I think I may have seen that trick on KZbin 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) :)
@karkerav1175
@karkerav1175 Жыл бұрын
Hi.... Excellently good tutorial to understand shift registers many thanks!
@FriendlyWire
@FriendlyWire Жыл бұрын
Glad you like it, thank you so much!
@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?
@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: kzbin.info/www/bejne/e6S4qYqFZZ5pgpI
@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!
@ericdavey6702
@ericdavey6702 Жыл бұрын
Haha! Love the LOTR reference!
@FriendlyWire
@FriendlyWire Жыл бұрын
Glad you like it :D
@simonyovino2126
@simonyovino2126 2 ай бұрын
Thanks! Very helpful
@FriendlyWire
@FriendlyWire 2 ай бұрын
Thank you, Simon, much appreciated! :)
@ubike3948
@ubike3948 Жыл бұрын
Amazing explanation!
@FriendlyWire
@FriendlyWire Жыл бұрын
Glad you like it!
@David_11111
@David_11111 Жыл бұрын
yay seems useful
@yamitokyoo
@yamitokyoo 3 ай бұрын
"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 2 ай бұрын
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 2 ай бұрын
@@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 2 ай бұрын
​@@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! :)
@Gkid8
@Gkid8 5 ай бұрын
I just wrote code like this last night and would have saved me a lot of code had I seen this first...
@FriendlyWire
@FriendlyWire 5 ай бұрын
Glad the video is helpful! Oh cool, what are you building?
@Gkid8
@Gkid8 5 ай бұрын
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 5 ай бұрын
@@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 5 ай бұрын
@@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 5 ай бұрын
@@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!
@NionXenion-gh7rf
@NionXenion-gh7rf Жыл бұрын
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 Жыл бұрын
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.
@helectro3021
@helectro3021 8 ай бұрын
Thank you, but how can this be implemented with 4 pins instead of 6 using esp01?
@FriendlyWire
@FriendlyWire 8 ай бұрын
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 4 ай бұрын
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 4 ай бұрын
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?
@hola3535
@hola3535 4 ай бұрын
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 4 ай бұрын
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? :)
@aSameplayer
@aSameplayer 4 ай бұрын
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 4 ай бұрын
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 3 ай бұрын
@@FriendlyWire Verstanden. Danke für die Antwort.
@FriendlyWire
@FriendlyWire 3 ай бұрын
@@aSameplayer Keine Ursache! :) Lass mich wissen, ob Du noch weitere Fragen hast, ich helfe gerne.
@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 8 ай бұрын
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 8 ай бұрын
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 8 ай бұрын
@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 8 ай бұрын
@@mikelarrutiromero9430 Happy to help, and best of luck! Projects like this are a lot of fun :)
@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 :)
@fench1234567
@fench1234567 8 ай бұрын
So for use with arduino Atmel and/or arm based boards, which is a better idea: the cd4094 or the 74hc595?
@FriendlyWire
@FriendlyWire 8 ай бұрын
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 ( kzbin.info/www/bejne/e6S4qYqFZZ5pgpI ).
@fench1234567
@fench1234567 8 ай бұрын
@@FriendlyWire Thank you! I'll take a look!
@FriendlyWire
@FriendlyWire 8 ай бұрын
@@fench1234567 Happy to help, and let me know if you have any questions :)
@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 KZbin comments. Can you reach out on Twitter? (Email also works, you can find it at the bottom of my website www.friendlywire.com)
@liantooot1706
@liantooot1706 5 ай бұрын
Make 3 digit, pleace
@FriendlyWire
@FriendlyWire 5 ай бұрын
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!
@Herzfeld10
@Herzfeld10 Жыл бұрын
title recommandation : hack every video game controllers with this shift register Let's get trending haha
@FriendlyWire
@FriendlyWire Жыл бұрын
Haha! :D
How to use rotary encoders
14:12
FriendlyWire
Рет қаралды 29 М.
Controlling a BIG LED Matrix?! How Shift Registers work! || EB#39
12:33
HAPPY BIRTHDAY @mozabrick 🎉 #cat #funny
00:36
SOFIADELMONSTRO
Рет қаралды 11 МЛН
DEFINITELY NOT HAPPENING ON MY WATCH! 😒
00:12
Laro Benz
Рет қаралды 47 МЛН
孩子多的烦恼?#火影忍者 #家庭 #佐助
00:31
火影忍者一家
Рет қаралды 50 МЛН
Control LEDs with your computer using RS232!
16:09
FriendlyWire
Рет қаралды 58 М.
74HC595 & 74HC165 Shift Registers with Arduino
40:38
DroneBot Workshop
Рет қаралды 393 М.
How Shift Registers Work!
11:50
Kevin Darrah
Рет қаралды 403 М.
How To Use A Shift Register (74HC595N)
13:53
Francis Studios Engineering
Рет қаралды 16 М.
Breadboard capacitive touch sensor tutorial
15:13
FriendlyWire
Рет қаралды 84 М.
#1099 How I learned electronics
19:55
IMSAI Guy
Рет қаралды 1,2 МЛН
Are PIC Microcontrollers Any Good? - Beyond Arduino #4
21:07
Sine Lab
Рет қаралды 39 М.
INFINITE Pins for ARDUINO?  |  74595 Shift Register
9:45
Eureka!
Рет қаралды 36 М.
MCP23017 Port Expander and ESPHome: Add More I/O Pins to Your Project
20:39
How Do Computers Remember?
19:32
Sebastian Lague
Рет қаралды 6 МЛН
HAPPY BIRTHDAY @mozabrick 🎉 #cat #funny
00:36
SOFIADELMONSTRO
Рет қаралды 11 МЛН