Can I use independently 2 ShiftRegisters 74HC595 with ShifOut Function?

This is my code, I'm trying to use 2 ShifRegisters Independently... but when I load and run the program on the Arduino ONE something fails, I checked the connections and they are ok... I just want to know if its possible to use 2 ShifRegisters controlled independently like this? Please Comment?

int latchPin1 = 2;
int clockPin1 = 3;
int dataPin1 = 4;

int latchPin2 = 5;
int clockPin2 = 6;
int dataPin2 = 7;

int array1[8] = {1,2,4,8,16,32,64,128};
int array2[8] = {128,64,32,16,8,4,2,1};

void setup()
{
pinMode(latchPin1, OUTPUT);
pinMode(clockPin1, OUTPUT);
pinMode(dataPin1, OUTPUT);

pinMode(latchPin2, OUTPUT);
pinMode(clockPin2, OUTPUT);
pinMode(dataPin2, OUTPUT);
}

void loop()
{
for(int i = 0; i < 8; i++)
{
digitalWrite(latchPin1, LOW);
digitalWrite(latchPin2, LOW);

shiftOut(dataPin1, clockPin1, MSBFIRST, array1*);*
_ shiftOut(dataPin2, clockPin2, MSBFIRST, array2*);*_

* digitalWrite(latchPin1, HIGH);*
* digitalWrite(latchPin2, HIGH);*
* delay(100);*
* }*
}
sketch_jun30a.ino (387 Bytes)

mmm when I run the program in the Arduino ONE just one ShiftRegisters works well, but the another ShiftRegister repeat the same sequence that the first one although the sequences are different...

That should work just fine.
Do you have 0.1uF caps on the Vcc pin of each shift register?
And NO caps on any control line.

The other thing to change is correct the syntax for the arrays:

shiftOut(dataPin1, clockPin1, MSBFIRST, array1[i]);
shiftOut(dataPin2, clockPin2, MSBFIRST, array2[i]);

The arrays are well just that the forum page doesn't ledn me to modify it again... but I had a bad conecttion:D.... It works well... Than You:D

I have a question regarding this process. I am looking to do the same type of setup, however ultimately I will want to output data to 16 shift registers to control 16 groups of LEDS independently. However, this would require 48 output pins from an AVR, one pin for each latch, clock and data per register. The 2560 arduino on has 36(?) Digital output pins which is not enough. Is it possible to share a latch or clock pin for all Shift registers in this type of set up?

ibanman555:
I have a question regarding this process. I am looking to do the same type of setup, however ultimately I will want to output data to 16 shift registers to control 16 groups of LEDS independently. However, this would require 48 output pins from an AVR, one pin for each latch, clock and data per register. The 2560 arduino on has 36(?) Digital output pins which is not enough. Is it possible to share a latch or clock pin for all Shift registers in this type of set up?

You should be able to control the output of 16 shift registers with three digital pins.

Check out this tutorial.

caveat: powering all of them.

I've already looked at the above tutorial mentioned, which is very helpful and will be used. The reason I asked if this was feasible was because I would like to utilize as many of the Microcontrollers pins as I can, assuming it would transmit the data more effectively than by sending all of my data through one pin. The arduino will be flashed to with the Hiduino firmware and send midi data to control the LEDS. There is a lot of data being sent to the arduino at one time.

The final circuit design will include a 12v power supply, each chip will be supplied enough voltage to run.

ShiftOut() is remarkably fast. Perhaps someone else knows this but it seems just as fast to push out extra bits as to move to the next block and perform a ShiftOut() again on the next set of LEDs. A good question.

Maybe break the 16 into 4 x 4 and use only 12 pins.

You can share the Latch pin and latch all 16 at the same time.

steinie44:
You can share the Latch pin and latch all 16 at the same time.

so now you are down to nine!

BulldogLowell:
ShiftOut() is remarkably fast.

"fast" is all relative. In my view it isn't very fast give the speed of the AVR and
what the AVR is capable of.
The code is not very well written for speed.
It can easily be doubled or trippled in speed by simply re-writing the routine.
There are several thing that are being done over and over again on each bit that can
moved outside the loop if the code is re-factored.
If you really want speed you can use direct port i/o and and speed it up at least
a factor of 50x or more.

steinie44:
You can share the Latch pin and latch all 16 at the same time.

Actually that is the pin you can't share if you want to control the shift registers independently.
You can share the data and clock pins but not the latch.
Yes, when you share the data and clock pins the data will be shifting through all the shift
registers, but the outputs will only be changed on the one that is latched.

Now if you don't want/need to control them independently, and want to send all the bits every time,
you only need 3 pins since the data bits will shift out of the first shift register and into
the next.

--- bill

Use SPI.transfer instead.
Keep an array of 16 bytes

byte ledArray[16[];

and loop thru it quick, with SPI clock divider at 2 can the data in just 10' of microseconds;

// did an array value  change? Send the array out:
digitalWrite (ssPin, LOW);
for (x=0; x<16; x=x+1){
SPI.transfer (ledArray[x]);
}
digitalWrite (ssPin, HIGH); // outputs updated on this rising edge.

Even faster, do it without the for loop, and use direct port manipulation for the latch. Use pinMode in setup to set the pin as an OUTPUT:

PORTB = PORTB & 0b11111011; // clear D10 on 328P chips, leave rest alone
// did an array value  change? Send the array out:
SPI.transfer (ledArray[0]);
SPI.transfer (ledArray[1]);
SPI.transfer (ledArray[2]);
SPI.transfer (ledArray[3]);
SPI.transfer (ledArray[4]);
SPI.transfer (ledArray[5]);
SPI.transfer (ledArray[6]);
SPI.transfer (ledArray[7]);
SPI.transfer (ledArray[8]);
SPI.transfer (ledArray[9]);
SPI.transfer (ledArray[10]);
SPI.transfer (ledArray[11]);
SPI.transfer (ledArray[12]);
SPI.transfer (ledArray[13]);
SPI.transfer (ledArray[14]);
SPI.transfer (ledArray[15]);
PORTB = PORTB | 0b0000100; // set D10, leave rest alone

I suppose I should clarify as to what my particular project entails and if my idea is feasible. My Arduino 2560 is flashed with the Hiduino firmware which allows me to receive midi messages into the chip. There are 16 specific channels that transmit from an audio program, each message is 3 bytes long, and the last byte is what changes per channel. Channel one sends A0 00 (00-0D), 13 messages per channel.

I would like each shift register (16) to only receive its specific channels midi messages, and each shift register will output the proper "third byte" data to AD557, and also to drive LEDs alone, there will be two separate designs.

So, because there are 16 separate channels, and 16 shift registers used off of the 2560, I can't share the data pins. And the latch pin, can or cannot be shared?? Since there were two answers above.... Is this doable?