Shift register help/troubleshooting

Hi all,

I'm relatively new to the arduino and could use some help figuring out shift registers. I've just started working on my first largish project, which is essentially using the arduino to drive 36 or so LEDs. I know there are ICs designed specifically for this purpose, but thought it might be a neat opportunity to figure out shift registers and work on my soldering.

Unfortunately I'm stuck and I'm not sure where to start in addressing the problem (which is to say I don't know if the problem is that I've screwed up the circuit or I've screwed up the software). I've got 5 shift registers wired together in series based on the arduinocc Shift Out tutorial, but in testing the thing I can't seem to properly control the individual pins.

Specifically, seemingly regardless of what code I upload shifting out 5 bytes to the shift registers, I get nothing on any of the output pins of the first register, and every output pin on the remaining registers will light an LED.

Frankly I'm not sure where to start, does anybody have any idea what would likely cause such behavior?

Thanks in advance, any and all help is appreciated.

Rather than jump in and try to get 5 shift registers working, start off with one. Get that going and extend it to two. After that it should be plain sailing. You have probably wired it up wrong, can you post the schematic and code so we can have a look.

Yeah I thought I’d gotten it working with only two shift registers on a breadboard, but maybe I didn’t test that thoroughly enough before moving on to soldering up a more permanent version. Lesson learned I guess.

Here’s a diagram of what (I believe) I have wired up: [edited to fix diagram]
http://img3.imageshack.us/img3/4592/circuitdiagram.png

And the code I’m uploading:

//======================================================
// Shift Register Demo
//======================================================

//Configuration
#define LATCH        8   
#define CLOCK        12  
#define DATA         11  

void shiftOut(int dataPin, int clockPin, byte output)
{
    //Enable output on the clock pin and data pin 
    pinMode(clockPin, OUTPUT);
    pinMode(dataPin, OUTPUT);

    //Just in case
    digitalWrite(clockPin, LOW);
    digitalWrite(dataPin, LOW);

    //Loop through each of the bits
    for(int i = 7; i>=0; --i)
    {   
        digitalWrite(clockPin, LOW);
        
        int pinState;
        if(output & (1 << i)) 
            pinState = HIGH;
        else
            pinState = LOW;

        digitalWrite(dataPin, pinState);
        digitalWrite(clockPin, HIGH);
        digitalWrite(dataPin, LOW);
    }   
    
    digitalWrite(clockPin, LOW);
}

void setup()
{
    //Configure the latch pin for output
    pinMode(LATCH, OUTPUT);
}

void loop()
{
    digitalWrite(LATCH, LOW);

    shiftOut(DATA, CLOCK, B00000001);
    shiftOut(DATA, CLOCK, B00000000);
    shiftOut(DATA, CLOCK, B00000000);
    shiftOut(DATA, CLOCK, B00000000);
    shiftOut(DATA, CLOCK, B00000000);
    shiftOut(DATA, CLOCK, B00000000);

    digitalWrite(LATCH, HIGH);
    }
}

A couple other observations:

  • If I disconnect the wire connecting the circuit to the +5v pin on the arduino the behavior doesn’t change at all
  • Along those lines, the after a little messing around I figured out that the High/Low state of the output pins of the last four registers are always the same as the state of the latch pin on the first register (even when the +5V wire is disconnected)
  • The shift registers are M74HC595B1R registers… not sure if that is important, I’m kind of going off the diagram showed on the ShiftOut tutorial page to identify which pin is which.

Also, one more question: What is the difference between using the shiftOut function (http://www.arduino.cc/en/Reference/ShiftOut) and the function posted in my code (I’ve tried both, but the tutorial uses the above function for the multiple register example)?

Thanks again for taking the time to help me with this stuff, I’m new to debugging circuits.

Double check your wiring. Your sketch works fine. I did notice you are sending data to 6 registers not five. If the last ShiftOut is "B00000000" your first register outputs will all be off. This could be why the first one is always off.

Alright, I think I'm going to cry uncle and start over and go one at a time.