Miss one bit in 74HC165

Hi,
I’m trying to use 2x 74HC165 shift registers daisy chained.
My problem is that when I read the content of the register, I’m not able to read the D7 input.
I have the same problem if I only use 1 74HC165 but in this case, I’ve found out that if I connect the push button to pin 10 (DS) I can read it from there.
Here’s my code:

void loop() {
  
  digitalWrite(clockPin165, LOW) ;                
  delayMicroseconds(5);
  digitalWrite(clockPin165, HIGH) ;               
  delayMicroseconds(5);
  digitalWrite(CEPin165, LOW);                   
  digitalWrite(clockInput165, HIGH);                   
 
  loQueMeLlega = shiftIn(dataPin165, clockInput165, MSBFIRST);    // Save first byte.
  loQueMeLlega2 = shiftIn(dataPin165, clockInput165, MSBFIRST);  // Save second byte.

  digitalWrite(CEPin165, HIGH);                                // Ready for another loop.


  Serial.println("Value Byte 1: ");
  Serial.print(loQueMeLlega, BIN);
  Serial.println("Value Byte 2: ");
  Serial.print(loQueMeLlega2, BIN);

  delay(500);
}



Does anybody know how can I read the content of the inputs D7 of each Shift register?

Moderator edit:
</mark> <mark>[code]</mark> <mark>

</mark> <mark>[/code]</mark> <mark>
tags added.

Why all the messing about with the clock pin before the data is read in? That is probably messing up the timing.

You should put the latch pin low, shift in the data put the latch pin high.

You should have decoupling capacitors on each shift register chip.

You should post all your code for a more accurate assessment of your problem, we also advise a schematic, what you posted was not a schematic.

Please read the how to use this forum sticky post, it will tell you how to ask a question.

I have just found out where te problem was:

void loop() {

digitalWrite(clockPin165, LOW) ;
delayMicroseconds(5);
digitalWrite(clockPin165, HIGH) ;
delayMicroseconds(5);

// ********* ADD THIS LINE:
digitalWrite(clockInput165, HIGH); // This line should be here, before setting CEPin165 to LOW status.

digitalWrite(CEPin165, LOW);

// ********* REMOVE THIS LINE:
// digitalWrite(clockInput165, HIGH); // THIS LINE SHOULD BE REMOVED AND WRITTEN BEFORE SETTING CEPin165 TO LOW POSITION.

loQueMeLlega = shiftIn(dataPin165, clockInput165, MSBFIRST); // Save first byte.
loQueMeLlega2 = shiftIn(dataPin165, clockInput165, MSBFIRST); // Save second byte.

digitalWrite(CEPin165, HIGH); // Ready for another loop.

Serial.println("Value Byte 1: ");
Serial.print(loQueMeLlega, BIN);
Serial.println("Value Byte 2: ");
Serial.print(loQueMeLlega2, BIN);

delay(500);
}

It's right there in the documentation:
https://www.arduino.cc/reference/en/language/functions/advanced-io/shiftin/
"If you’re interfacing with a device that’s clocked by rising edges, you’ll need to make sure that the clock pin is low before the first call to

shiftIn()

, e.g. with a call to

digitalWrite(clockPin, LOW)

."