I'm trying to make use out of the SN74HC595N chip i had laying around and wanted to make a command line type of stuff, everything works until i try to get data from the chip.
I expected it to tell me the number i put (in this case, its 50) but it just returns 0
Here is the code:
void loop() {
/* Serial reader, you may ignore this or uncomment if you are debugging.
String output;
while (Serial.available()) {
delay(3); //delay to allow buffer to fill
if (Serial.available() >0) {
char c = Serial.read(); //gets one byte from serial buffer
output += c; //makes the string readString
}
}*/
if (output.startsWith("STORE")) {
int arg = output.substring(6).toInt() * 2; // To make it display correctly in binary, i multiply it by 2
//because in the LEDs it is half of the number.
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, MSBFIRST, arg);
digitalWrite(latchPin, HIGH);
Serial.println("DONE");
}else if (output.startsWith("GET")) {
int result = (int)shiftIn(dataPin, clockPin, MSBFIRST) / 2; // divide by 2 because we just multiplied by 2
Serial.println(result);
}
}
The 595 is a Serial In / Parallel Out shift register. You can shift data OUT of the Arduino IN to the data pin of the 595 and when you raise the latch line, the bits will appear on the 8 outputs of the register, in parallel. It is only good for outputs.
The 165 is a Parallel In / Serial Out shift register. When you lower the latch line, the data on the 8 parallel pins get latched in the register in parallel. Then you can shift data IN to the Arduino OUT of the data pin of the 165. it is only good for inputs.
On 595 a serial input pin (14) is used for a 'shiftOut', but a serial out pin (9) is used for a 'shiftIn'. You need to use different pin on boths sommands. Keep in mind that when you perform a 'shiftIn' from 595, some other value will probably be loaded.
595 pin description
pin 14 serial data input
pin 9 serial data output
And i am not sure for uses of 'latchPin' - in your 'shiftIn' is not used.
You’re exactly right… the ‘carry bit’ shifted out is intended for daisy-chained ‘595 s.
If you care to read that back in while shifting, you’ll see the data that you shifted out earlier… a bit ring buffer if you will.
There’s no practical reason you’d do this, because you should know what was originally shifted out to the 595/serial-in anyway.
Where I have seen this used is when 595s and 165s are daisy chained to illuminate indicators -and- to simultaneously read switches or other pin states..
The dara stream is shifted through the length of the whole chain, and while you ignore the 595 output bits, you can read and write long strings of inputs from the 165s, and outputs with 3/4 wires. (tricks required for 3 wires!)
Thank you so much, this is exactly what i was looking for. (the reason i didn't find this simple answer is because of the arduino documentation not giving a name for every pin)
Oh i forgot my name, i do have an arduino board but i made this account when i didnt, but thank you for this website, i will consider using it to help with my future projects.