Go Down

Topic: 128 LED Larson Scanner (Read 3667 times) previous topic - next topic

cayoke

Nov 13, 2013, 05:03 pm Last Edit: Nov 15, 2013, 05:18 pm by cayoke Reason: 1
I am working on a large scale 'Larson' and I am slowly adding more and more shift registers as I work. In the end I plan on having around 128 LEDS powered through Shift registers and most of the work I have done so far includes daisy chaining them. However I am now at three shift registers and I cannot seem to fix my problem.  The program runs perfectly through the first two registers and when it gets the the third register the all of the LEDS light for a second or so then the program resumes working perfectly. I have double checked my wiring over and over but I cant find a issue.

This is the code for three Registers and It is what I am having problems with.
Code: [Select]

int latch = 12;
int clock = 11;
int data = 10;
int value = 1;

void setup(){
 pinMode(latch, OUTPUT);
 pinMode(data, OUTPUT);
 pinMode(clock, OUTPUT);
}
void loop(){
 for(int i = 0; i < 24; i++){
   value = 1 << i; //Shifts the value of 7 over Each time
 digitalWrite(latch, LOW);
 shiftOut(data, clock, MSBFIRST, (value & 0xFF0000)>>16);
 shiftOut(data, clock, MSBFIRST, (value & 0x00FF00)>>8);
 shiftOut(data, clock, MSBFIRST, (value & 0x0000FF));
 digitalWrite(latch, HIGH);
 delay(75);
 }
 for(int u = 22; u > 0; u--){
   value = 1 << u;
 digitalWrite(latch, LOW);
 shiftOut(data, clock, MSBFIRST, (value & 0xFF0000)>>16);
 shiftOut(data, clock, MSBFIRST, (value & 0x00FF00)>>8);
 shiftOut(data, clock, MSBFIRST, (value & 0x0000FF));
 digitalWrite(latch, HIGH);
 delay(75);
 }
}



This is a diagram of what I have. Please note that I DO have Resistors where they are needed and all of the LEDs are properly hooked up.



This code is for two Shift registers and it works wonderfully!
Code: [Select]

int latch = 12;
int clock = 11;
int data = 10;
int value = 1;

void setup(){
 pinMode(latch, OUTPUT);
 pinMode(data, OUTPUT);
 pinMode(clock, OUTPUT);
}
void loop(){
 for(int i = 0; i < 16; i++){
   value = 1 << i;
 digitalWrite(latch, LOW);
 shiftOut(data, clock, MSBFIRST, (value & 0xFF00)>>8);
 shiftOut(data, clock, MSBFIRST, (value & 0x00FF));
 digitalWrite(latch, HIGH);
 delay(75);
 }
 for(int u = 14; u > 0; u--){
   value = 1 << u;
 digitalWrite(latch, LOW);
 shiftOut(data, clock, MSBFIRST, (value & 0xFF00)>>8);
 shiftOut(data, clock, MSBFIRST, (value & 0x00FF));
 digitalWrite(latch, HIGH);
 delay(75);
 }
}




If anybody can help me figure out my problem I will greatly appreciate it


-Cayoke

fungus

Advanced Arduino

CrossRoads

Instead of a bank of shift register, try two MAX7219s, each controlling 64 LEDs.
Wire as 8 groups of 8 for each 64. Each group will have a common cathode that goes to a Digit pin, all groups will have A anode in parallel, B anode in parallel, etc, going to a Segment pin.
Then you merely do an SPI.transfer() to one of registers on each chip to update your display.
Or even easier, just send all 16 out whenever a change is made.
Keep an array of 16 bytes for your data, when a byte changes, send the array out.
MACX7219  has built in current control with maximum brightness set by 1 external resistor, dimmable in 15 steps with a command to a register.
Designing & building electrical circuits for over 25 years.  Screw Shield for Mega/Due/Uno,  Bobuino with ATMega1284P, & other '328P & '1284P creations & offerings at  my website.

nickgammon




int value = 1;



'value' only has 16 bits in it.



Correct. You need to set up some sort of array rather than trying to find a 128-bit wide single variable.
Please post technical questions on the forum, not by personal message. Thanks!

More info: http://www.gammon.com.au/electronics

cayoke

#4
Nov 14, 2013, 03:42 pm Last Edit: Nov 14, 2013, 04:06 pm by cayoke Reason: 1




int value = 1;



'value' only has 16 bits in it.



Correct. You need to set up some sort of array rather than trying to find a 128-bit wide single variable.


I tried setting value as a Unsigned Long but that didn't fix the problem.  I'm guess I'll have to try to find a way to use an Array.


[EDIT} I decided to check the values Value was being given and they make sense for a while then they jump unexpectedly to a number that shouldnt popup.  

This is to show you the positon where I put Serial.println and below I have the values of value for anybody to look at,
Code: [Select]
void loop(){
 for(int i = 0; i < 24; i++){
   value = 1 << i;
 digitalWrite(latch, LOW);
 Serial.println(value);
 shiftOut(data, clock, MSBFIRST, (value & 0xFF0000)>>16);
 shiftOut(data, clock, MSBFIRST, (value & 0x00FF00)>>8);
 shiftOut(data, clock, MSBFIRST, (value & 0x0000FF));
 digitalWrite(latch, HIGH);
 delay(75);
 }
 for(int i = 24; i > 0; i--){
   value = 1 << i;
 digitalWrite(latch, LOW);
 Serial.println(value);
 shiftOut(data, clock, MSBFIRST, (value & 0xFF0000)>>16);
 shiftOut(data, clock, MSBFIRST, (value & 0x00FF00)>>8);
 shiftOut(data, clock, MSBFIRST, (value & 0x0000FF));
 digitalWrite(latch, HIGH);
 delay(75);
 }
}


This is the value of it for a few cycles notice how it spikes for some reason. I know it is in my code but where and why?

Code: [Select]

1
2
4
8
16
32
64
128
256
512
1024
2048
4096
8192
16384
4294934528
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
4294934528
16384
8192
4096
2048
1024
512
256
128
64
32
16
8
4
2
1
2
4
8
16
32
64
128
256
512
1024
2048
4096
8192
16384
4294934528
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
4294934528
16384
8192
4096
2048
1024
512
256
128
64
32
16
8
4
2
1


When I convert the large number to Binary I see why all of the lights on that one end flash. However the values it gets after that seem to be larger than the 32bit storage limit of longs. Further prodding found that I get this value when int i = 15 and value = 1 << i;

arduinodlb

Even with unsigned long, that'll only get you to 32 bits. You need to change over to an array.

But, the problem right now is these line:

    value = 1 << i;

That 1 is an int. You need to use:

    value = 1L << i;

to let the compiler know it's a long. You won't have this problem when you change to arrays.
Do not IM me. I will not respond. Ask questions in the forum.

cayoke

#6
Nov 15, 2013, 04:28 pm Last Edit: Nov 15, 2013, 06:22 pm by cayoke Reason: 1

Even with unsigned long, that'll only get you to 32 bits. You need to change over to an array.

But, the problem right now is these line:

   value = 1 << i;

That 1 is an int. You need to use:

   value = 1L << i;

to let the compiler know it's a long. You won't have this problem when you change to arrays.



That makes sense. As for the rest of the program I planned on adding some more for loops to control three other daisy chains.  to get the transiton to be seamless I guess I will have to use arrays. Thanks guys! I'll have a video or something up of my progress.


I found a way to do it with out arrays as a temproary fix. This code works perfectly.
Code: [Select]

int data = 2;
int latch = 3;
int clock = 4;
unsigned long bit1 = 1;

int gap = 75;


void setup(){
 for(int i = 2; i < 14; i++){
  pinMode(i, OUTPUT);
 }
}
void loop(){
 
 for(int i = 0; i < 31; i++){
   bit1 = bit1 * 2;
 digitalWrite(latch, LOW);
 shiftOut(data, clock, MSBFIRST, (bit1 & 0xFF000000)>>24);  
 shiftOut(data, clock, MSBFIRST, (bit1 & 0x00FF0000)>>16);
 shiftOut(data, clock, MSBFIRST, (bit1 & 0x0000FF00)>>8);
 shiftOut(data, clock, MSBFIRST, (bit1 & 0x000000FF));
 digitalWrite(latch, HIGH);
 delay(gap);
 }

 
 for(int i = 31; i > 0; i--){
   bit1 = bit1 / 2;
 digitalWrite(latch, LOW);
 shiftOut(data, clock, MSBFIRST, (bit1 & 0xFF000000)>>24);  
 shiftOut(data, clock, MSBFIRST, (bit1 & 0x00FF0000)>>16);
 shiftOut(data, clock, MSBFIRST, (bit1 & 0x0000FF00)>>8);
 shiftOut(data, clock, MSBFIRST, (bit1 & 0x000000FF));
 digitalWrite(latch, HIGH);
 delay(gap);
 }
}



This is what have so far to control the multiple chains of registers. I have not tested it yet but I'm pretty sure I will have to do some fine tuning to make trasitions between chains smooth.

Code: [Select]
//FIRST CHAIN
int data = 2;
int latch = 3;
int clock = 4;
unsigned long bit1 = 1;

//SECOND CHAIN
int data2 = 5;
int latch2 = 6;
int clock2 = 7;
unsigned long bit2 = 1;

//THIRD CHAIN
int data3 = 8;
int latch3 = 9;
int clock3 = 10;
unsigned long bit3 = 1;

//FOURTH CHAIN
int data4 = 11;
int latch4 = 12;
int clock4 = 13;
unsigned long bit4 = 1;

int gap = 75;


void setup(){
  for(int i = 2; i < 14; i++){
   pinMode(i, OUTPUT);
  }
}
void loop(){
   
  for(int i = 0; i < 31; i++){
    bit1 = bit1 * 2;
  digitalWrite(latch, LOW);
  shiftOut(data, clock, MSBFIRST, (bit1 & 0xFF000000)>>24); 
  shiftOut(data, clock, MSBFIRST, (bit1 & 0x00FF0000)>>16);
  shiftOut(data, clock, MSBFIRST, (bit1 & 0x0000FF00)>>8);
  shiftOut(data, clock, MSBFIRST, (bit1 & 0x000000FF));
  digitalWrite(latch, HIGH);
  delay(gap);
  }
 
  for(int i = 0; i < 31; i++){
    bit2 = bit2 * 2;
  digitalWrite(latch2, LOW);
  shiftOut(data2, clock2, MSBFIRST, (bit2 & 0xFF000000)>>24); 
  shiftOut(data2, clock2, MSBFIRST, (bit2 & 0x00FF0000)>>16);
  shiftOut(data2, clock2, MSBFIRST, (bit2 & 0x0000FF00)>>8);
  shiftOut(data2, clock2, MSBFIRST, (bit2 & 0x000000FF));
  digitalWrite(latch2, HIGH);
  delay(gap);
  }
 
  for(int i = 0; i < 31; i++){
    bit3 = bit3 * 2;
  digitalWrite(latch3, LOW);
  shiftOut(data3, clock3, MSBFIRST, (bit3 & 0xFF000000)>>24); 
  shiftOut(data3, clock3, MSBFIRST, (bit3 & 0x00FF0000)>>16);
  shiftOut(data3, clock3, MSBFIRST, (bit3 & 0x0000FF00)>>8);
  shiftOut(data3, clock3, MSBFIRST, (bit3 & 0x000000FF));
  digitalWrite(latch3, HIGH);
  delay(gap);
  }
 
  for(int i = 0; i < 31; i++){
    bit4 = bit4 * 2;
  digitalWrite(latch4, LOW);
  shiftOut(data4, clock4, MSBFIRST, (bit4 & 0xFF000000)>>24); 
  shiftOut(data4, clock4, MSBFIRST, (bit4 & 0x00FF0000)>>16);
  shiftOut(data4, clock4, MSBFIRST, (bit4 & 0x0000FF00)>>8);
  shiftOut(data4, clock4, MSBFIRST, (bit4 & 0x000000FF));
  digitalWrite(latch4, HIGH);
  delay(gap);
  }
///////////////////////////////////////////////////
/////////////GOING BACK ///////////////////////////
///////////////////////////////////////////////////

  for(int i = 31; i > 0; i--){
    bit4 = bit4 / 2;
  digitalWrite(latch4, LOW);
  shiftOut(data4, clock4, MSBFIRST, (bit4 & 0xFF000000)>>24); 
  shiftOut(data4, clock4, MSBFIRST, (bit4 & 0x00FF0000)>>16);
  shiftOut(data4, clock4, MSBFIRST, (bit4 & 0x0000FF00)>>8);
  shiftOut(data4, clock4, MSBFIRST, (bit4 & 0x000000FF));
  digitalWrite(latch4, HIGH);
  delay(gap);
  }
 
  for(int i = 31; i > 0; i--){
    bit3 = bit3 / 3;
  digitalWrite(latch3, LOW);
  shiftOut(data3, clock3, MSBFIRST, (bit3 & 0xFF000000)>>24); 
  shiftOut(data3, clock3, MSBFIRST, (bit3 & 0x00FF0000)>>16);
  shiftOut(data3, clock3, MSBFIRST, (bit3 & 0x0000FF00)>>8);
  shiftOut(data3, clock3, MSBFIRST, (bit3 & 0x000000FF));
  digitalWrite(latch3, HIGH);
  delay(gap);
  }
 
  for(int i = 31; i > 0; i--){
    bit2 = bit2 / 2;
  digitalWrite(latch2, LOW);
  shiftOut(data2, clock2, MSBFIRST, (bit2 & 0xFF000000)>>24); 
  shiftOut(data2, clock2, MSBFIRST, (bit2 & 0x00FF0000)>>16);
  shiftOut(data2, clock2, MSBFIRST, (bit2 & 0x0000FF00)>>8);
  shiftOut(data2, clock2, MSBFIRST, (bit2 & 0x000000FF));
  digitalWrite(latch2, HIGH);
  delay(gap);
  }
 
  for(int i = 31; i > 0; i--){
    bit1 = bit1 / 2;
  digitalWrite(latch, LOW);
  shiftOut(data, clock, MSBFIRST, (bit1 & 0xFF000000)>>24); 
  shiftOut(data, clock, MSBFIRST, (bit1 & 0x00FF0000)>>16);
  shiftOut(data, clock, MSBFIRST, (bit1 & 0x0000FF00)>>8);
  shiftOut(data, clock, MSBFIRST, (bit1 & 0x000000FF));
  digitalWrite(latch, HIGH);
  delay(gap);
  }
}


Go Up