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

แชร์
ฝัง
  • เผยแพร่เมื่อ 17 พ.ค. 2024
  • 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 ปีที่แล้ว +7

    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!

  • @bob-ny6kn
    @bob-ny6kn ปีที่แล้ว +2

    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  ปีที่แล้ว +1

      Thank you so much, Bob, much appreciated!

  • @TheScissorunner
    @TheScissorunner ปีที่แล้ว +4

    Your breadboard layout is nothing less than artwork!! Incredible content as usual! Thank you!!!

    • @FriendlyWire
      @FriendlyWire  ปีที่แล้ว +1

      Thank you so much, Craig! I find making these breadboards very relaxing, almost like doing a jigsaw puzzle.

  • @santiagovaldez5176
    @santiagovaldez5176 7 หลายเดือนก่อน +1

    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 TH-cam 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) :)

  • @sweetlilmre
    @sweetlilmre ปีที่แล้ว +4

    Excellent tutorial, the layout and visualisations were superbly done!

    • @FriendlyWire
      @FriendlyWire  ปีที่แล้ว +1

      Thank you so much, glad you like it!!

  • @simonyovino2126
    @simonyovino2126 18 วันที่ผ่านมา +1

    Thanks! Very helpful

    • @FriendlyWire
      @FriendlyWire  18 วันที่ผ่านมา

      Thank you, Simon, much appreciated! :)

  • @karkerav1175
    @karkerav1175 ปีที่แล้ว +3

    Hi.... Excellently good tutorial to understand shift registers many thanks!

    • @FriendlyWire
      @FriendlyWire  ปีที่แล้ว

      Glad you like it, thank you so much!

  • @ericdavey6702
    @ericdavey6702 ปีที่แล้ว +1

    Haha! Love the LOTR reference!

  • @ubike3948
    @ubike3948 ปีที่แล้ว +2

    Amazing explanation!

  • @kckc9245
    @kckc9245 ปีที่แล้ว +3

    Thank You 👍😎 Excellent Tutorial .. Good for LED lights on the buttons for an Arcade Machine ..

    • @FriendlyWire
      @FriendlyWire  ปีที่แล้ว +1

      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: th-cam.com/video/EsUxWO096L0/w-d-xo.html

  • @DavidHancock7
    @DavidHancock7 ปีที่แล้ว +3

    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!

  • @ahmedalkabir543
    @ahmedalkabir543 ปีที่แล้ว +2

    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?

  • @David_11111
    @David_11111 ปีที่แล้ว +1

    yay seems useful

  • @misterretrowolf1464
    @misterretrowolf1464 ปีที่แล้ว +1

    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  ปีที่แล้ว +1

      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 ปีที่แล้ว +1

      @@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 ปีที่แล้ว +1

      @@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  ปีที่แล้ว +1

      @@misterretrowolf1464 Yeah that was a bit painful to animate, but I knew that my audience has a keen eye! :)

  • @Gkid8
    @Gkid8 3 หลายเดือนก่อน +1

    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 หลายเดือนก่อน +1

      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 หลายเดือนก่อน +1

      @@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!

  • @NionXenion-gh7rf
    @NionXenion-gh7rf ปีที่แล้ว +1

    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! :)

  • @yamitokyoo
    @yamitokyoo หลายเดือนก่อน +1

    "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  หลายเดือนก่อน

      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 16 วันที่ผ่านมา +1

      @@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  16 วันที่ผ่านมา +1

      ​@@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! :)

  • @ebbewertz3417
    @ebbewertz3417 2 หลายเดือนก่อน +1

    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 ปีที่แล้ว +1

    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  ปีที่แล้ว +1

      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 ปีที่แล้ว +1

      @@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  ปีที่แล้ว +1

      @@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 ปีที่แล้ว +1

      @@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!

  • @helectro3021
    @helectro3021 6 หลายเดือนก่อน +1

    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?

  • @fench1234567
    @fench1234567 6 หลายเดือนก่อน +1

    So for use with arduino Atmel and/or arm based boards, which is a better idea: the cd4094 or the 74hc595?

    • @FriendlyWire
      @FriendlyWire  6 หลายเดือนก่อน +1

      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 ( th-cam.com/video/EsUxWO096L0/w-d-xo.html ).

    • @fench1234567
      @fench1234567 6 หลายเดือนก่อน +1

      @@FriendlyWire Thank you! I'll take a look!

    • @FriendlyWire
      @FriendlyWire  6 หลายเดือนก่อน

      @@fench1234567 Happy to help, and let me know if you have any questions :)

  • @hola3535
    @hola3535 2 หลายเดือนก่อน +1

    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 หลายเดือนก่อน +1

      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 2 หลายเดือนก่อน +1

    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  2 หลายเดือนก่อน +1

      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 2 หลายเดือนก่อน +1

      @@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 ปีที่แล้ว +1

    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 :)

  • @mikelarrutiromero9430
    @mikelarrutiromero9430 7 หลายเดือนก่อน +1

    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  7 หลายเดือนก่อน +1

      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 7 หลายเดือนก่อน +1

      @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 :)

  • @Herzfeld10
    @Herzfeld10 ปีที่แล้ว +2

    title recommandation : hack every video game controllers with this shift register
    Let's get trending haha

  • @David_11111
    @David_11111 ปีที่แล้ว +1

    I wondered how you animated the bread board wire arriving ?

    • @FriendlyWire
      @FriendlyWire  ปีที่แล้ว +1

      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.

  • @Syeda-Hadia
    @Syeda-Hadia ปีที่แล้ว +1

    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 ปีที่แล้ว +1

      @@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 ปีที่แล้ว +1

      @@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 TH-cam 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 3 หลายเดือนก่อน +1

    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!