Pages: [1] 2   Go Down
Author Topic: how to drive 25 led with 5 pcs of 595 shift register?  (Read 1218 times)
0 Members and 1 Guest are viewing this topic.
Croatia
Offline Offline
Newbie
*
Karma: 0
Posts: 17
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi,
I need to control 25 led's, one after another. Everything is fine with 2x 595 and 16 leds, but I don't know how to add another 3x 595 and rest of led's  smiley-confuse
When I add third 595 it light up all led's connected to it after last led in second 595.

Code:
/*

 Created 23 Mar 2010
 by Tom Igoe

 */

//Pin connected to latch pin (ST_CP) of 74HC595
const int latchPin = 8;
//Pin connected to clock pin (SH_CP) of 74HC595
const int clockPin = 12;
////Pin connected to Data in (DS) of 74HC595
const int dataPin = 11;

void setup() {
  //set pins to output because they are addressed in the main loop
  pinMode(latchPin, OUTPUT);
  pinMode(dataPin, OUTPUT); 
  pinMode(clockPin, OUTPUT);

}

void loop() {
 
    int bitToSet = 0;

  // write to the shift register with the correct bit set high:
  for (bitToSet=0; bitToSet<16; bitToSet++){
    registerWrite(bitToSet, HIGH);
  delay(300);
}
 
}

// This method sends bits to the shift register:

void registerWrite(int whichPin, int whichState) {
// the bits you want to send
  unsigned int bitsToSend = 0;

  // turn off the output so the pins don't light up
  // while you're shifting bits:
  digitalWrite(latchPin, LOW);

  // turn on the next highest bit in bitsToSend:
  bitWrite(bitsToSend, whichPin, whichState);

  // break the bits into two bytes, one for
  // the first register and one for the second:
  byte registerOne = highByte(bitsToSend);
  byte registerTwo = lowByte(bitsToSend);

  // shift the bytes out:
  shiftOut(dataPin, clockPin, MSBFIRST, registerOne);
  shiftOut(dataPin, clockPin, MSBFIRST, registerTwo);
 
    // turn on the output so the LEDs can light up:
  digitalWrite(latchPin, HIGH);

}
Logged

Offline Offline
Edison Member
*
Karma: 116
Posts: 2205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

1) use 2 hc595s to drive up to 64 leds;
2) save the remaining 3 hc595s for future projects.
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 538
Posts: 27069
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Double the hardware chain, call this twice? Make it just 9 vs 16.
Code:
  int bitToSet = 0;

  // write to the shift register with the correct bit set high:
  for (bitToSet=0; bitToSet<16; bitToSet++){
    registerWrite(bitToSet, HIGH);
  delay(300);
}
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

0
Offline Offline
Shannon Member
****
Karma: 206
Posts: 12169
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You have proper decoupling on all these 595's and a powerful enough power supply?  There shouldn't be problems daisy-chaining them upto 10 or so (so long as all wiring is short).  For 25 LEDs you only need 4 shift registers.
Logged

[ I won't respond to messages, use the forum please ]

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

Double the hardware chain, call this twice? Make it just 9 vs 16.
Code:
 int bitToSet = 0;

  // write to the shift register with the correct bit set high:
  for (bitToSet=0; bitToSet<16; bitToSet++){
    registerWrite(bitToSet, HIGH);
  delay(300);
}

I use another arduino pin for additional two 595 data line. clock and latch are connected to same arduino pins as first pair of 595.
add slightly changed registerWrite to sketch and IT'S ALIVE!  smiley-mr-green 
25 led goes like the way I wanted! Thanks for direction!
« Last Edit: November 15, 2012, 05:48:50 pm by flega » Logged

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

You have proper decoupling on all these 595's and a powerful enough power supply?  There shouldn't be problems daisy-chaining them upto 10 or so (so long as all wiring is short).  For 25 LEDs you only need 4 shift registers.

wires will be long, one led at one meter. 595 will be at every 8 led + transistor for driving led. All this will be in transparent tube and immerse in swimming pool.
Is there another way to control this 25 led's, maybe with even less wires from tube to controller with arduino
Logged

0
Offline Offline
Shannon Member
****
Karma: 206
Posts: 12169
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You will likely have trouble sending clock and data along long cables like that unless at a low data rate.  Logic signals degrade over a few feet / metres and can lead to crosstalk, spurious glitches etc (remember these signals have rise and fall times of a few nanoseconds).  I'd select quite a low clock frequency in the first instance, say 10kHz or so, and add 100 ohm resistors in-line before the inputs to each 595 (suppresses reflections).  You may still have problems - experiment with one '595 and set of LEDs first.

More advanced cures are adding an RC low-pass filter and a schmitt trigger gate to clean up the edges.
Logged

[ I won't respond to messages, use the forum please ]

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

You will likely have trouble sending clock and data along long cables like that unless at a low data rate.  Logic signals degrade over a few feet / metres and can lead to crosstalk, spurious glitches etc (remember these signals have rise and fall times of a few nanoseconds).  I'd select quite a low clock frequency in the first instance, say 10kHz or so, and add 100 ohm resistors in-line before the inputs to each 595 (suppresses reflections).  You may still have problems - experiment with one '595 and set of LEDs first.

More advanced cures are adding an RC low-pass filter and a schmitt trigger gate to clean up the edges.
I still have trouble to make more than 16 leds to move. This is first problem  smiley-sad
Second, there is a possible problem with a long wires. smiley-sad
Is there another way beside 595 to control 25 leds with just few wires? somebody mentioned SPI control
Logged

0
Offline Offline
Shannon Member
****
Karma: 206
Posts: 12169
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

SPI is just another serial clocked protocol, same issues.  Some of the LED driver chips have schmitt trigger clock inputs specifically to help with long signal runs.   You are using good decoupling aren't you?  22uF or more at each shift register is a start.

There is Charlieplexing - 25 LEDs would take 6 wires and 6 resistors, but you get a reduction in brightness due to multiplexing.
Logged

[ I won't respond to messages, use the forum please ]

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

SPI is just another serial clocked protocol, same issues.  Some of the LED driver chips have schmitt trigger clock inputs specifically to help with long signal runs.   You are using good decoupling aren't you?  22uF or more at each shift register is a start.

There is Charlieplexing - 25 LEDs would take 6 wires and 6 resistors, but you get a reduction in brightness due to multiplexing.
For now all is on breadboard so I don't use any decoupling for now. First I want to make all 25 led running as I expect. After that I will be making a long version and solve problems.
Charlieplexing use too many pins from arduino and it is complicated to cross wires in the tube.
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 538
Posts: 27069
Author of "Arduino for Teens". Available for Design & Build services. Now with Unlimited Eagle board sizes!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I think you want a little bit of logic at each LED.
Have a little 8-pin uC every meter to control the LED and minimizethe wiring in the tube.


* LED swim chase lights.jpg (58.7 KB, 960x720 - viewed 15 times.)
Logged

Designing & building electrical circuits for over 25 years. Check out the ATMega1284P based Bobuino and other '328P & '1284P creations & offerings at  www.crossroadsfencing.com/BobuinoRev17.
Arduino for Teens available at Amazon.com.

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

I'd select quite a low clock frequency in the first instance
Logged

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

I think you want a little bit of logic at each LED.
Have a little 8-pin uC every meter to control the LED and minimizethe wiring in the tube.

This is possible solution if 595 failed. But this will cost a much more than 4 595 chips + lots of wire, so I will firs try cheaper solution. Thank for your advice and time!  smiley
Logged

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

I'd select quite a low clock frequency in the first instance
how to do that?
Logged

Offline Offline
Edison Member
*
Karma: 116
Posts: 2205
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
First I want to make all 25 led running as I expect.

You simply shift out 4 bytes. Using shiftOut() for example:

Code:
  shiftOut(data[3]); //shift out the furtherest byte
  shiftOut(data[2]);
  shiftOut(data[1]);
  shiftOut(data[0]); //shift out the closest byte
  //done!

Quote
After that I will be making a long version

You can either slow it down or you can use buffers.

Both are very simple.
Logged

Pages: [1] 2   Go Up
Jump to: