I'm working on arduino and 74HC595 Shift Register, I attached the LED on output pins. I was doing base on this tutorial: http://arduino.cc/en/Tutorial/ShiftOut.
It's run well but when I reset/restart the arduino all of the outputs on the 74HC595 turn off.
In my case, I want to keep save the output on 74HC595 when the arduino reset/restart. Is possible to do that? could anybody give solutions of this problem?
Put 10K pulldown resistors on the clock and latch lines so they do not float/wander around when the arduino outputs become inputs during the reset time prior to the sketch starting up and controlling the pins.
There should be no cap on ANY control line - only a 0.1uF (100nF) on the Vcc pin to Gnd.
@CrossRoads
I added pulldown resistors (connect the latch/clock pins to GND with 10kR) and remove the cap but when I reset the arduino the outputs still off :~
Did I make a mistake ?
I just need to transfer the 8 bits once so I remove the For Loop:
//Pin connected to ST_CP of 74HC595
int latchPin = 8;
//Pin connected to SH_CP of 74HC595
int clockPin = 9;
////Pin connected to DS of 74HC595
int dataPin = 10;
int i=0;
void setup() {
//set pins to output so you can control the shift register
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
}
void loop() {
if(i<1)
{
// take the latchPin low so
// the LEDs don't change while you're sending in bits:
digitalWrite(latchPin, LOW);
// shift out the bits:
shiftOut(dataPin, clockPin, MSBFIRST, B11110001);
//take the latch pin high so the LEDs will light up:
digitalWrite(latchPin, HIGH);
// pause before next value:
i++;
}
}
What is to keep them from being sent with every restart?
You may need to do something like check a byte in EEPROM, if they LEDs are already written, then check what caused the reset and rewrite if power was lost, if not then don't rewrite after a regular hardware reset.
Or maybe just do this part 1 time in void setup instead of in loop:
digitalWrite(latchPin, LOW);
// shift out the bits:
shiftOut(dataPin, clockPin, MSBFIRST, B11110001);
//take the latch pin high so the LEDs will light up:
digitalWrite(latchPin, HIGH);