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;
}
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.
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.
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.
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.
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