Two or more shift registers

Hi all,

I’m very new to shift registers. I’ve studied the tutorial but I’m afraid I just can’t work out how to drive two shift registers.
The first one I’ve put in an array, this works fine:

  data_array[0] = 1;
  data_array[1] = 2;
  data_array[2] = 4;
  data_array[3] = 8;
  data_array[4] = 128; // order has changed
  data_array[5] = 64;
  data_array[6] = 32;
  data_array[7] = 16;

My question is how do I aproach the next 8? I tried this:

  data_array_O3[0] = 129;
  data_array_O3[1] = 130;
  data_array_O3[2] = 132;
  data_array_O3[3] = 136;
  data_array_O3[4] = 256;
  data_array_O3[5] = 192;
  data_array_O3[6] = 160;
  data_array_O3[7] = 144;

And then turning on the LED’s by twice calling my own my_shiftout function:

for(int j=0; j<=7; j++){
data = data_array[j];
      data_O3 = data_array_O3[j];
      // turn on display
      my_shiftout(data);
      my_shiftout(data_O3);
}

void my_shiftout(byte d){
  Serial.print("shifting ");
  // send byte
    Serial.println(d, BIN);
    shiftOut(DATA,CLOCK, MSBFIRST, d); 
    // turn dispay on
    strobe();
}
void strobe()
{
  digitalWrite(STROBE, HIGH);
  delay(1);
  digitalWrite(STROBE, LOW);
}

But I can’t seem to get ‘past’ the first 8 LEDs.

Any help would be greately apreciated, best, Danielle.

Have you tried the example codes for shift out? The shift out tutorial does a pretty good job of showing you haw to connect a pair of shift registers as well as giving 3 example codes of how to use them.

Hi,

As I say above: I've studied the tutorial but I'm afraid I just can't work out how to drive two shift registers. I mean this one: http://arduino.cc/en/Tutorial/ShftOut23 But may be there's another one which will help me understand better.

Your data is interleaved; shouldn't it be consecutive? i.e. all the bits from "data" and then all the bits from "data_O3"

@ Groove That’s also the direction I’m thinking in. I wouldn’t quite know to do that. For now I’ve put two for loops in sequence (on for data and one for O3_data) but the result is the same…

Just take the 8 bit output code and extend the array to have 16 locations instead of 8.

Then have two:- shiftOut(DATA1,CLOCK, MSBFIRST, d); shiftOut(DATA2,CLOCK, MSBFIRST, d); where DATA1 is the most significant 8 bits and DATA2 is the least significant.

Hi, Just checking, by shiftOut(DATA1,CLOCK, MSBFIRST, d); shiftOut(DATA2,CLOCK, MSBFIRST, d); Do you mean I need two fysical out pins for the data? That won't be possible as I've got a custom made etched print board.

Just take the 8 bit output code and extend the array to have 16 locations instead of 8. Do I use the numbers of the second array: data_array_O3 from my example?

Thanks.

try moving the call to strobe until after all the data is shifted out, ie:

for(int j=0; j<=7; j++){
data = data_array[j];
      data_O3 = data_array_O3[j];
      // turn on display
      my_shiftout(data);
      my_shiftout(data_O3);
    // turn dispay on
    strobe();
}

void my_shiftout(byte d){
  Serial.print("shifting ");
  // send byte
    Serial.println(d, BIN);
    shiftOut(DATA,CLOCK, MSBFIRST, d);

}
void strobe()
{
  digitalWrite(STROBE, HIGH);
  delay(1);
  digitalWrite(STROBE, LOW);
}

Thanks for all your responses.
@stimmer Calling strobe() right after the shifting causes the bit order to get mixed up.

I’ve got it working now. I’m afraid I made a hardware error which stopped the LEDs from turning on.

  data_array[0] = 1;
  data_array[1] = 2;
  data_array[2] = 4;
  data_array[3] = 8;
  data_array[4] = 128; 
  data_array[5] = 64;
  data_array[6] = 32;
  data_array[7] = 16;
  // ozone
  data_array_O3[0] = 1;
  data_array_O3[1] = 2;
  data_array_O3[2] = 4;
  data_array_O3[3] = 8;
  data_array_O3[4] = 128; 
  data_array_O3[5] = 64;
  data_array_O3[6] = 32;
  data_array_O3[7] = 16;

for(int j=0; j<=7; j++){ // low pollution
      //Serial.print(data_array[j], HEX);
      //Serial.print(" ");
      //Serial.println(data_array[j], BIN);
      // turn on outer most ring
      data = data_array[j];
      data_O3 = data_array_O3[j];
      //Serial.println(data, BIN);
      // turn on display
      my_shiftout(data);
      my_shiftout(data_O3);
    }

This code basically works. Although some LEDs behave strange. But that might be due to the printboard.

Thanks again, regards, Danielle.

Do you mean I need two fysical out pins for the data?

No, you send two lots of data to the same pins without the latch strobe after the first lot only the second lot.

You didn't post the myShiftOut() function. If it is the same as before remove the latch strobe from it and add it at the end of the two calls.