Author Options:

Pesky shift registers? Answered

I started working with 2 74HC595N to control 8x8 matrix, and found that instead of a dot it activates multiple rows. So I assumed this was due to my lack of knowledge about shift registers so I setup a simple scenario from arduino ShiftOut tutorial (single register chip and 4 LEDs controlled by number via serial input i.e. "one by one sketch". Thats when I found out that shift register has almost random values on its output pins. Some LEDs were on, some off before I started to controll them. After I turned on/off all 4 it strated to work as supposed to, but last pin retained "memory" of its state even if I reset Arduino. 
So my question is, do I always need to initialize every pin of every shift register (and is there an example sketch), or do I have faulty IC?

Edit: Added schematic (it's from http://arduino.cc/en/Tutorial/ShiftOut)


Pull the /MR pin low when you reset the processor, and you reset the 595. The processor reset is available on a pin of the Arduino - I can't remember if its a positive logic or negative logic, but if its positive, you need to invert it for your 595.

Make SURE /MR is HELD high after reset.
Make SURE /OE is tied LOW.


Awesome! That will be much easier than shifting out thru all of the pins. Thank you!

.01 uF (103). That's what they recommended :)

That's a typo in the schematic. Actually they recommend .1uf
"Notice the 0.1"f capacitor on the latchPin, if you have some flicker when the latch pin pulses you can use a capacitor to even it out. "

About LEDs flickering: there should not be voltage difference - use only Arduino 5V output. Then capacitor is not even needed.

I got flicker when I attached external 5V supply to shift register's Vcc.

correction - external 5V can be used, but attach Arduino GND to circuit. Can be combined with external GND.

I see it as Arduino generated clock signal needs return path back to Arduino.

Probably that's how shift registers act. I have experience only with 74HC164, I had a circuit with two of them and a led matrix. When microcontroller was removed from it's socket and I wiped my finger over the empty socket, then leds lit or went off because of that. And they also retained their state when nothing was happening near shift registers input pins.

To reset your shift register to one state you can simply shift out binary 00000000 or 11111111 (if it's 8 bit, or more numbers accordingly if it's something else) in arduino code setup().

I see! Thank you! So if I have more than on in chain I have to shift out 00000000 several times right?

to confirm;
Every time you want to write to ANYTHING in the chain, you have to write EVERYTHING in the chain...

With 2 595's, If you want to change output 4 on chip 1, you have to output 16 bits (2 bytes), because getting to that 4th bit will push everything beyond it down 4 bits...
That seems annoying, but really, you're trading speed for output pins. You could drive 16 pins from the arduino directly, and have almost none for anything else. Realistically, the tradeoff for speed is trivial, because the atmega can shift out hundreds of thousands of bits per second.

Without looking at your schematic any answer is just an educated guess more or less so take this all with a grain of salt.

I have a limited experience with shift registers but some with other digital operations.

Some things to watch for

On some chips unused input and output must be tied to a state and not left floating or they will generate unpredictable and false results

Some chips are sensitive to power supply trash and the power supplies should be bypassed with a small cap close to each chip

In most cases it's better to assume that on start up the contents of a chip will be random and will need to be reset to the state you desire as a first operation. 

Sorry my bad for not including schematic. It's one form example in ShiftOut Tutorial:
Specifically: http://arduino.cc/en/uploads/Tutorial/ShftOut_Schm1.gif