Pages: [1]   Go Down
Author Topic: Daisy chaining 74HC595 shift registers  (Read 3678 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 29
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

SE USA
Offline Offline
Faraday Member
**
Karma: 41
Posts: 3783
@ssh0le
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged


Sweden
Offline Offline
Sr. Member
****
Karma: 13
Posts: 257
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Dubuque, Iowa, USA
Offline Offline
Faraday Member
**
Karma: 49
Posts: 2544
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
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 smiley-wink
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 29
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Offline Offline
Newbie
*
Karma: 0
Posts: 15
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Pages: [1]   Go Up
Jump to: