Hello,
I am having trouble getting the Texas Instuments SN74HC165N 8-Bit Parallel-Load Shift Registers to do what i expect.
This one: SN74HC165 data sheet, product information and support | TI.com
Eventually i want to use two of them to read the value of a 12 bit counter, but frist, because if have so much to learn, i'd like to see it work in its simpelest form.
I am hoping somebody can point out what im doing wrong.
See below for code and schema, but in essence, here is what im trying:
Connect the following pins to Arduino
- CLK, SH/_PL, QH
Connect to following pins to 5V - VCC, A
Connect all other pins to Ground - B, C, D, E, F, G, H, _QH, SER
I expect to read "1" but instead i get "2".
If i connect only B to 5V, i expect to read 2 but i get 4
If i connect only C to 5V, i expect to read 4 but i get 8
This continues to pin G reading 128 instead of 64 and pin H reading 0.
I have both a Arduino Uno and Arduino Due. On the the due it gets it right the first time (after hardware reset).
Im getting pretty desperate here, searched this forum and google. I have 4 of these shift registers, tried them all and all give the same results.
const int clk = 8; // SN74HC165N pin 2, CLK
const int data = 12; // SN74HC165N pin 9, QH
const int lock = 13; // SN74HC165N pin 1, SH/LD
// SN74HC165N CLK INH connected to GND
// SN74HC165N A to H connected to GND or VDD, see question
// SN74HC165N _QH, connected to GND
// SN74HC165N SER, connected to GND
void setup()
{
pinMode(clk, OUTPUT);
pinMode(data, INPUT);
pinMode(lock, OUTPUT);
Serial.begin(115200);
}
void loop()
{
// Lock parallel input
digitalWrite(lock, HIGH);
// Read
byte b = shiftIn(data, clk, MSBFIRST);
Serial.println(b);
// Re-enable parallel input
digitalWrite(lock, LOW);
delay(2000);
}