Questions about shift registers

Hi everyone.
As some of you may or may not know, I'm working on a project that is a gaming device with over 80 or 90 inputs, including analog ones, and I'm exploring the different options I have for that.
So far I've tried a Pro Micro with I/O expanders PCF8575, a Pro Micro with a nano acting as a slave for a button matrix, I'm exploring the Mega as HID as well, and I was recently mentioned about the shift registers, which I didn't know about, but looks like a very good option for a gaming device, as I can have them inside the parts of the device and just have a few wires coming out of it, instead of a whole bunch.
So following this YT video, I designed a PCB for a SMD 74HCT166D that can be chained together as many times as needed:

Basically looks like this:


So here are my questions:

  • Do you see anything wrong with the design?
  • If I chain 7 or 8 like these in series, how will be the performance? is there going to be a delay or will it be just fine?
  • I noticed she didn't use any debouncing routine in her code. Is that not needed?

Thank you

Yes, I can see things that are wrong with the design. For example there is no bypass capacitor. But the most important thing that is wrong is that you should never design a PCB until you have built and tested a prototype. For you project you need to build more than 1 prototype so that you can test connecting them together. The easiest way to build your first prototype is to use solderless breadboards, or, if you prefer, protoboard or stripboard.

The more of these boards you connect, the slower reading all the buttons will be. However, if you write the code correctly, speed will not be a problem.

The need to debounce or not to debounce the buttons depends on how the buttons will be used in the game. If you describe that in more detail, I can tell you if debouncing is required or not.

Have you considered other designs to wire a large number of buttons? Using a matrix can make your circuit simpler.

Thank you for your reply @PaulRB .
The good thing about a design is that I can modify it if needed :slight_smile: I'm learning kicad so it's a good practice, even if I need to re-do the PCB too. Where would the bypass capacitor go? the ones that I've seen are in between VCC and GND, so that could still be added in the Arduino side, couldn't it?

There are momentary push buttons, limit switches, latching switches, momentary switches. There is even an rkjxt1f42001 4 way + push switch (the rotary encoder function is not used). Some of them, of any kind, can be pushed at the same time. I have calculated that no more than 5 to 10 at max, including the latching switches. What else do you need to know about it?

A button matrix is one of the currently active options. In fact, I also designed and built a PCB for that, to make it easier to plug in (5 boards cost me less than 4€, shipping included, so even if they don't work, it's not a big waste):


What I don't like about this option is that I need to use an intermediary nano, connected via I2C to the Pro Micro because I didn't have enough pins in it.

No, positioning the bypass capacitor is important. It must be located close to the Vcc & ground pins of the chip, otherwise it cannot perform its function. The arduino already has its own bypass capacitors.

Limit switches and latching switches normally do not need to be debounced. Push buttons, momentary switches, joystick type switches may or may not need to be debounced. It is what the switch/button is used for, more than the type of the switch/button that is important to determine if debouncing is required.

Switch/button bouncing causes it to appear to have been pressed and released multiple times within a short time. If that would cause unwanted behaviour in your code, then debouncing is needed. If the behaviour that would cause in your code is not a problem, then debouncing is not required.

For example, if a button/switch is used to select an item from a menu or enter a password, then bouncing would make it difficult to select the desired menu option or enter the password correctly, so debouncing is needed.

As another example, if a button has a single function like "stop" then bouncing is probably not needed. If a bounce causes your code to think that "stop" has been pressed 2 or 3 times, this probably causes no undesired effects. The first press causes the stop action to be performed. Extra presses from bouncing do not perform any additional actions.

1 Like

I agree, using two or more Arduino is not a good option because of the complexity of writing code for 2 or more Arduinos which must communicate with each other. This makes the project complex and difficult. But you do not need multiple Arduino to use a matrix. The shift registers and I/o expanders you are already familiar with can allow a matrix to be read by a single Arduino.

1 Like

I think I won't need debouncing routines, considering the use of the buttons, but the good thing is that I can always add it afterwards if I notice wrong behaviors.

I wasn't able to get the PCF8575 to read from a matrix, so I'm not sure if I could get the shift registers to do the same. I only found I2C matrix libraries that read only one key press at a time, and I'm not smart enough to code something like that myself. I usually use Chris A keypad library for these type of projects.
Another option was to use multiple PCF8575 (I think I needed 5 or 6) to read the inputs individually, but I was also having troubles working with that. I'll revisit the topic later, as I still have the boards. It may be easier to do with the shift registers, though.

Will one of those small, non polarized capacitors work in the PCB? all capacitors do the same, right? it doesn't need to be one of those electrolytic capacitors that everyone has at home.

BTW, what would be a good value for the capacitor?

This is true, but probably not significant: the 74HCT166 can be clocked at tens of MHz - so waaay faster than a human can press buttons!

In other words:

Yes

Also yes.

It should be possible with either of chips or shift registers. The forum can help with that if you have problems. A single pcf8575 chip can read a 8x8 matrix of buttons/switches. Alternatively an input shift register like the 74hc166 plus an output shift register like 74hc595 can be used.

However, regardless which chips are used, if multiple buttons/switches will be pressed together, or some of the switches are latching or toggle, then you will need to connect a small signal diode in series with every button/switch, otherwise "phantom" button presses could be read.

Different types of capacitors are best for different situations. For bypass capacitors, they should be 0.1uF ceramic (ceramic are not polarised) and as close to the Vcc & ground pins of the chip as you can make them. Polarised capacitors like electrolytic types are not suitable to use as bypass capacitors because they cannot react quickly enough.

2 Likes

Is there any reason why a 74HC165 wouldn't work as well as or better than the 74HC166. I've always used the 165 because it was simpler to parallel load, and I could never find a need for the synchronous loading provided by the 166. Is there some advantage provided by the 166 that I've missed?

Honestly? I'm a complete noob about shift registers. I only learned about them not that long ago and watched a youtube tutorial that uses 74HC166. I searched for a SMD version of it and found the 74HCT166D which I later learned it's not just an SMD version, but one that accepts TTL. Obviously not my intention, since I just wanted a simple SMD PISO shift register.

Anyway, I will probably do some tests with them, since I've already ordered (it was about $5 for 10 of them, so it's not a big loss), but I've now shifted back to the PCF8575 option, which I had already unsuccessfully tried in the past but I think I might be able to recover that option now, since I've been doing some basic tests with them and I might have a better understanding of them now.

I still think shift registers have it's place in some of my current and future projects, so I will keep playing with them and see what they're capable of.

Thank you

Or you could use a multiplexer

A 16:1 multiplexer can separately select 16 different inputs off 4 pins

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.