Daisy chaining 74HC595 shift registers

Right, first things first, if this is in the wrong section, feel free to move it.

Now, onto the question:

I am trying to make sound-reactive LEDs (you may have seen my last post). I have a bar of 8 working fine with one 74HC595. Now I want to try and use 16 LEDs.

I have wired the Q7' pin from the first to the DS pin on the second, and I figured that if I were to write a value bigger than 255 to the first register, then the bits would over flow into the second, e.g. if I were to write 511, all 8 pins would light up on the first register and one on the second. However, they work independently from each other, both doing the same thing, like two bars of 8.

My sketch can be found here: http://pastebin.com/7a7JExdc

Thanks for any help provided,

Sam

use 2 shift outs in a row, the first one will be shifted to leds 16-9 the second one will be shifted out to leds 8-1

samwhiteUK: Right, first things first, if this is in the wrong section, feel free to move it.

Now, onto the question:

I am trying to make sound-reactive LEDs (you may have seen my last post). I have a bar of 8 working fine with one 74HC595. Now I want to try and use 16 LEDs.

I have wired the Q7' pin from the first to the DS pin on the second, and I figured that if I were to write a value bigger than 255 to the first register, then the bits would over flow into the second, e.g. if I were to write 511, all 8 pins would light up on the first register and one on the second. However, they work independently from each other, both doing the same thing, like two bars of 8.

My sketch can be found here: http://pastebin.com/7a7JExdc

Thanks for any help provided,

Sam

There are more than a few good examples for chaining 595. Here is one http://arduino.cc/en/Tutorial/ShftOut13 . You're right about sending 16bits etc. But I would suggest that you first look at the source code for the shiftOut function (very simple code) and try to understand how it's sending the information. But it's like you did in your code. But instead of calling the shiftOut function once, you do it twice. The first shiftOut will go to the chained register(connected to Q7) and the second shiftOut will go to the main register(connected to DS).

BTW, here is the source code for shiftout http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1274766175

unsigned int v;  // Holds numeric representation of our volume. 
unsigned int bitfield = 0; // Holds bit representation of our volume (two bytes)

v = analogRead(0);
// v = constrain(v,0,100); // is this necessary? It will chop your reading.
v = map(v,0,1024,0,16);  // map analog value (0 to 1024) to 0 to 16;

for (int ctr = 0; ctr < 16; ctr++) {
  if (ctr >= v) {  
    bitfield |= 1<<ctr;  // turn bit on at "ctr" position.
  }
}

digitalWrite(latch, LOW);
shiftOut(data, clock, MSBFIRST, bitfield);  
shiftOut(data, clock, MSBFIRST, bitfield >> 8);
digitalWrite(latch, HIGH);

Note that shiftOut only shits out the least significant 8 bits. To shift out the next, higher 8 bits in our bitfield we send it again shifted 8 bits to the right.

This code is wholly untested :wink:

Ok thanks to all, I will attempt that when I get home this afternoon.

And Chagrin, the reason I use constrain() is because the voltage is coming straight from an iPod headphone jack, and so is very small, so until I obtain a small transformer I am limiting the readings as otherwise anything over about half a volt is never reached, this gives me a view of the whole range of LEDs working.

Unless there is another method I could use for either stepping up to voltage or varying the readings? At the moment I only get all the LEDs when the iPod is at full volume, which when plugged in to a dock as well is none too pleasant for my ears!

Another quick question about the bit functions: is 8>>bit the same as bit <<8? Ie does it matter what is in the left and the right or is it purely based on what the “arrows” (don’t know the proper name) are pointing from and to?

Thanks,

Sam

Hi Sam,
first:
8 >> bit is NOT the same as bit << 8 .
bit << 8 shifts the variable named bit 8 places to the left (the same as multiplying it by two, while 8 >> bit, shifts the value 8 (1000binary) bit places to the right so if bit is one 8 >> bit will equal 4 (or 100binary).
There is a tutorial on daisy chaining 74HC595s at Lucidtronix: http://www.lucidtronix.com/tutorials/40
There is also is sound reactive daisy-chained LED matrix tutorial with arduino code, that might help with your project at: http://lucidtronix.com/tutorials/35

You could always try the shifter library. I had this working with 2 register and 2x 10 segment LED Bars.

@tahikib, Check the dates on topics you post to. This one has been inactive for over 18 months. Moderator.

@moderator

CrossRoads: @tahikib, Check the dates on topics you post to. This one has been inactive for over 18 months. Moderator.

So what!!

If threads are that old, it is likely the people involved are no longer around and questions will not be answered.

It is best that people start a new thread, one that will more accurately represent their situation and one that will get a response from people who are still here.

But you know this . . .

It has been at least five years as far as I know, since it was possible for someone to post as "guest" - and even then I suspect it was only due to some glitch in the way the forum was run at that time.

Therefore anyone posting as "guest" has not been participating in the forum for a long time as they would necessarily have had to create a persona - as hewi did just four years ago and has just come out of hibernation seven weeks ago. :grinning:

The only argument for "reviving" a post after the Original Poster (and even some participants) is no longer a participant and will not be notified of any updates to the discussion (because that can only happen if you created an account) is to assert that new information is being provided that others may find useful if their search lands on this particular thread.

And that is in itself plausible. I have done it from time to time, though generally in a thread where I had already been a participant. It automatically implies that the person adding to the thread has themselves been searching for the same subject matter as in this example.

Unfortunately, it is of limited benefit as people often find searching unsuccessful or too tedious if the thread has become very long and extends over many "pages" (which are by default, inappropriately short at 14 "answers" per page - best configured to the maximum available, presently 50 per page and of course you have to set up an account to configure this) so a lot of the time - we cannot know exactly how much - they simply post a new question detailing their exact situation which is mostly quite acceptable.

Of course, if their problem is only a minor variation on an older discussion and the discussion thread is not ridiculously long, then adding to that that is OK as well. :sunglasses: