Esp32 and 10x 74hc595

hello, Im trying to read input from 70 buttons on a keyboard i have 10 74hc595's and my esp32, will it be possible to daisy chain 10 of these shift registers to my board, while retaining decent write speed. i plan to attach all the outputs of my 70 buttons to one input pin, then individually write to each button, one by one, using the registers (this way i will know which button has been pressed)

will this processes of scanning each button for a press be fast enough? consideing the buttons are on a keyboard being typed on (esp32 is very quick right?)

can esp32 handle 10 74hc595s

base code that will be used to write to registers:

#define number_of_74hc595s 10 //can it handle this is my question
#define numOfRegisterPins number_of_74hc595s * 8
#define SER_Pin 25
#define RCLK_Pin 33
#define SRCLK_Pin 32

//Variables
boolean registers [numOfRegisterPins];

void setup(){
//Init Serial USB
Serial.begin(115200);
Serial.println(F("Initialize System"));
//Init register
pinMode(SER_Pin, OUTPUT);
pinMode(RCLK_Pin, OUTPUT);
pinMode(SRCLK_Pin, OUTPUT);
clearRegisters();
writeRegisters();
delay(500);
}

void loop(){

}

void clearRegisters(){/* function clearRegisters */ 
//// Clear registers variables 
for(int i = numOfRegisterPins-1; i >=  0; i--){
  registers[i] = HIGH;//LOW;
}}

void writeRegisters(){/* function writeRegisters */ 
//// Write register after being set 
digitalWrite(RCLK_Pin, LOW);
 for(int i = numOfRegisterPins-1; i >=  0; i--){
  digitalWrite(SRCLK_Pin, LOW); int val = registers[i];
  digitalWrite(SER_Pin, val);
  digitalWrite(SRCLK_Pin, HIGH);
}
  digitalWrite(RCLK_Pin, HIGH);
}

void setRegisterPin(int index,int value){/* function setRegisterPin */ 
////Set register variable to HIGH or LOW
registers[index] = value;
}

wiring that will be expanded for 10 registers:

The 74hc595 is an output shift register.

Google:

74HC165

1 Like

I am aware of this. the esp32 will , using the registers write to each buttons input terminal. if said button where to be pressed, the signal that was written to it would pass through the button to its output, which is connected to one input pin on the esp32. all the other buttons outputs are connected to this one input pin too.

  • Schematic please ?

working on one now, sorry im not explaining it very well

  • What happens when 2 or more switches are pushed ?

Google:

74HC165

this is why each button is written to one by one, effectively "activating" that button. its comparable to the board just reading one button. its just goes along one by one, powering the input of the button, checking if the output also reads as high (its been pressed) then goes to the next button, powers it, checks the ouput.

  • The 74hc595 outputs are totem-pole, either HIGH or LOW.

  • If one output is HIGH the other 69 outputs are LOW.

  • two closed switches cause a short between Vcc and GND i.e. HIGH and LOW.


Google:

74HC165


this is ofcourse simplified, there is another 66 buttons.

  • The 74hc595 outputs are totem-pole, either HIGH or LOW.
  • If one output is HIGH the other 69 outputs are LOW.
  • two closed switches cause a short between Vcc and GND i.e. HIGH and LOW.

Google:

74HC165

1 Like

sorry, i only just realised the issue of a short occuring if two buttons are pressed

, it didnt cross my mind. is there a different way of reading my 70 buttons with the limited pins of the esp32 while still being able to read more than one button press at a time without shorts.

  • You could try your setup with the ESP input pin to GND through a 10k resistor.

  • Then add 70 schottky diodes to the outs of your 595s to prevent back feeding.

  • However, use 74HC165 to read 70 switches, that’s what they are designed for.

Cascading ten 74HC595 or ten 74HC165 is no problem (in theory).
What you want is possible, to power each button one by one via a 74HC595 output shift register. You also need a pullup or pulldown resistor, that is not in your schematic.
However, if you want to make that, then we all advise to use the 75HC165 as a input shift register.

There will be so many wires. It might be a big ball of wires that capture all the noise from around. If you have ten shift registers, then you need a good PCB board. It will not be reliable with wires. How big is the keyboard ?
You also need to read the buttons a lot for debouncing.

I think there are alternatives that are more reliable.
A matrix of 9*8 or 10*7 needs 17 pins. You might need a diode at each button, but I'm not sure about that.
There are keyboard-scanning-chips. For example a I2C chip with a matrix of 8*16.

To finish your project, you have to be practical.

I will definately try the 74hc165
With the necessary pulldown resistors and the 74hc165, would the issue of shorts when more than one button is pressed be avoided?
Note, the wiring all fits into a 3d printed case that individually separates each wire into printed channels, atleast each wire isnt in contact with eachover and is relatively neat
I have plenty of pcb perf boards that i am using for all the ic,s

  • You can expand on Nick Gammon’s schematic:

  • No problem with multiple switches being pressed.

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