Hey Guys,
I am struggling with this issue for quite a while now.
I am using a 74HC 165 PISO Shift Register to control input of eight buttons. Everything works fine except button 3 and 4. Button 3 gives no input at all and button 4 is recognized as either 3 or 4. All other button's signals are as they are supposed to be.
This is my code:
int latchPin = 8;
int dataPin = 9;
int clockPin = 10;
int enablePin = 11;
void setup() {
Serial.begin(9600);
pinMode(enablePin, OUTPUT);
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, INPUT);
}
uint8_t myShiftIn(int dataPin, int clockPin) {
uint8_t shiftValue = 0;
byte x;
for (x = 0; x < 8; ++x) {
digitalWrite(clockPin, LOW);
shiftValue |= digitalRead(dataPin) << (7 - x);
digitalWrite(clockPin, HIGH);
}
return shiftValue;
}
void loop() {
digitalWrite(latchPin, LOW);
delayMicroseconds(20);
digitalWrite(latchPin, HIGH);
digitalWrite(enablePin, LOW);
uint8_t bitFieldButtonPressed =
myShiftIn(dataPinInput, clockPin);
digitalWrite(enablePin, HIGH);
for (int i = 0; i < config::shelfCount; i++) {
if (bitFieldButtonPressed & (1 << i)) {
Serial.println(i);
}
}
}
I connected enablePin to clockInhibit of Shift Register, latchPin to Shift/Load, clockPin to clock and dataPin to QH.
When I press the first button, my code outputs 0,
for the second button it is 1,
for the third button it is nothing,
for the fourth it is either 2 or 3, I see no pattern here.
All other buttons work correctly.
The third and fourth button are soldered correctly. I tested them individually by plugging them into my arduinio directly and they work. But they do not in combination with my shift register.
I bougth three brand new PISO shift registers of the same model and the result is always the same. So I can exclude the shift register from being the problem.
I already did plenty of internet research but I found nothing helpful.
DataSheet This is a data sheet from the shift register I am using. It is provided by Reichelt Elektronik and the link redirects to a Reichelt Elektronik site.
Thank you very much for any help.
Kind regards,
Hendrik