Pages: 1 2 [3] 4 5   Go Down
Author Topic: Big RGB Table Finally Needs Code  (Read 4838 times)
0 Members and 1 Guest are viewing this topic.
Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 524
Posts: 26473
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

So you basically have this (see schematic):
5 8-bit registers down the left side to drive to 36 anodes of the 12 RGB LEDs.
3 8-bit registers across the bottom controlling MOSFETs, one per each column of 24 LEDs.

You will basically have 8 arrays that hold the data to write to those registers.
(you could do it other ways, I find this easiest to visualize  implement)
Going down the side, you have 24 byte arrays for each of the 5 anode drivers.  These are your  Red, Green, Blue data
So, chip5[ 0 ] to chip5[ 23 ], same for chip4, chip3, chip2, chip1

Going across, you have 24 byte arrays for each of the 3 cathode drivers.
So, left_cathode [ 0 ] to leftcathode [ 23 ], same for mid_cathode, and right_cathode (or whatever we called them).

Now to cycle thru the array, you'll count from 0 to 23 and output data from a particular array into that driver.
Code:
void loop(){
for (x =0; x<24; x=x+1){
SPI.transfer (chip5 [x] );  // send the data from chip5 array position x into the chip5 shift register
SPI.transfer (chip4 [x] );  // send the data from chip4 array position x into the chip4 shift register
SPI.transfer (chip3 [x] );  // send the data from chip3 array position x into the chip3 shift register
SPI.transfer (chip2 [x] );  // send the data from chip2 array position x into the chip2 shift register
SPI.transfer (chip1 [x] );  // send the data from chip1 array position x into the chip1 shift register

// now the anodes are set with their highs & lows, turn on the cathode driver
SPI.transfer (left_cathode [x] );  // the data in these, 1,2,4,8,10,20,40,80, is set so that only 1 at a time is driven
SPI.transfer (mid_cathode [x] );
SPI.transfer (right_cathode [x] );
delayMicroseconds (500); //  let the column shine a bit
} // now you've gone thru all 24 columns

// now tweak the data on chip1[ ], chip2[ ], chip3[ ], chip4[ ] and chip5[ ] to make the display change
// its late, I can't think of a pattern, do something simple for now:

if (millis()>=previousMillis){ // time to update the displays!
previousMillis = previousMillis + 500); // change every 1/2 second
color = color+1; // define color as an int
if (color == 256){color = 0;} // reset back to 0
for (x=0; x<24; x=x+1){
chip5[x] = color; // cycle thru from 0 to 255
chip4[x] = color;
chip3[x] = color;
chip2[x] = color;
chip1[x] = color;
}
] // end loop


* 12x24_RGB_array.jpg (142.59 KB, 960x720 - viewed 28 times.)
« Last Edit: May 03, 2012, 01:59:35 am by CrossRoads » 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.

Seattle, WA
Offline Offline
Full Member
***
Karma: 1
Posts: 225
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Your are correct about the shift registers, 8 8 bits, all daisy chained. first 5 control anodes, last 3 control MOSFETs and cathodes. Im still a little confused about your reasoning for the arrays. I understand where you get 24 byte from, thats understandable, but why a 24 byte array for each chip? the chips are handling specific colors on their own, this is how they are wired currently:
chip1 = r1-r8
chip2 = r9-12/b1-b4
chip3 = b5-12
chip4 = g1-g8
chip5 = g9-12/ 4 unused pins
chip6 = 1-8 mosfets
chip7 = 9-16 mosfets
chip8 = 17-24 mosfets
So why do i need a 24 byte array if they only are dealing with 8 outputs? (sorry, big learning curve for me i guess) Ill give your code a try and see if i can make something work. Also, what about this part:

Code:
byte cathodeslower[ ] = {
  0x01, 0x02, 0x04, 0x08, 0x10, 0x20,  0x40, 0x80, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};  // walking 1 for lower 8 NPNs
byte cathodesmid[ ] = {
  0,0,0,0,0,0,0,0, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0,0,0,0,0,0,0,0}; //walking for mid 8 NPNs
byte cathodeshigher[ ] = {
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x01, 0x02, 0x04, 0x08, 0x10, 0x20,  0x40, 0x80};  // walking 1 for upper 8 NPNs

If you dont mind, could you explain this a bit more to me? Thank you
Logged

"It's Dr. Evil. I didn't spend six years in Evil Medical School to be called 'mister,' thank you very much."

Seattle, WA
Offline Offline
Full Member
***
Karma: 1
Posts: 225
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

okey dokey, well i just tried this:
Code:
#include <SPI.h>

// set up an array for the cathode drives
byte left_cathode[ ] = {
  0x01, 0x02, 0x04, 0x08, 0x10, 0x20,  0x40, 0x80, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};  // walking 1 for lower 8 NPNs
byte mid_cathode[ ] = {
  0,0,0,0,0,0,0,0, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0,0,0,0,0,0,0,0}; //walking for mid 8 NPNs
byte right_cathode[ ] = {
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x01, 0x02, 0x04, 0x08, 0x10, 0x20,  0x40, 0x80};  // walking 1 for upper 8 NPNs

//set up array for anodes
byte chip5 [24]; //holds green 9-12
byte chip4 [24]; //holds green 1-8
byte chip3 [24]; //holds blue 5-12
byte chip2 [24]; //holds red 9-12 and blue 1-4
byte chip1 [24]; //holds red 1-8

int x = 0;
int previousMillis = 0;

void setup(){
  SPI.begin();
}

void loop(){
for (x =0; x<24; x=x+1){
SPI.transfer(chip5 [x] );  // send the data from chip5 array position x into the chip5 shift register
SPI.transfer(chip4 [x] );  // send the data from chip4 array position x into the chip4 shift register
SPI.transfer(chip3 [x] );  // send the data from chip3 array position x into the chip3 shift register
SPI.transfer(chip2 [x] );  // send the data from chip2 array position x into the chip2 shift register
SPI.transfer(chip1 [x] );  // send the data from chip1 array position x into the chip1 shift register

// now the anodes are set with their highs & lows, turn on the cathode driver
SPI.transfer(left_cathode [x] );  // the data in these, 1,2,4,8,10,20,40,80, is set so that only 1 at a time is driven
SPI.transfer(mid_cathode [x] );
SPI.transfer(right_cathode [x] );
delayMicroseconds(500); //  let the column shine a bit
} // now you've gone thru all 24 columns

// now tweak the data on chip1[ ], chip2[ ], chip3[ ], chip4[ ] and chip5[ ] to make the display change
// its late, I can't think of a pattern, do something simple for now:

if (millis() >= previousMillis){ // time to update the displays!
previousMillis = (previousMillis + 500); // change every 1/2 second
int color = color + 1; // define color as an int
if (color == 256){color = 0;} // reset back to 0
for (x=0; x<24; x=x+1){
chip5[x] = color; // cycle thru from 0 to 255
chip4[x] = color;
chip3[x] = color;
chip2[x] = color;
chip1[x] = color;
 }
}
}// end loop

no big suprise, it didnt work. I think we are getting closer though. Check that code, i might have made a dumb mistake.
Quote
// its late, I can't think of a pattern, do something simple for now:
yeah.. i know what you mean, i think we are both night owls...
Logged

"It's Dr. Evil. I didn't spend six years in Evil Medical School to be called 'mister,' thank you very much."

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Let me format that for you:

Code:
#include <SPI.h>

// set up an array for the cathode drives
byte left_cathode[ ] = {
  0x01, 0x02, 0x04, 0x08, 0x10, 0x20,  0x40, 0x80, 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0};  // walking 1 for lower 8 NPNs
byte mid_cathode[ ] = {
  0,0,0,0,0,0,0,0, 0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0,0,0,0,0,0,0,0}; //walking for mid 8 NPNs
byte right_cathode[ ] = {
  0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0x01, 0x02, 0x04, 0x08, 0x10, 0x20,  0x40, 0x80};  // walking 1 for upper 8 NPNs

//set up array for anodes
byte chip5 [24]; //holds green 9-12
byte chip4 [24]; //holds green 1-8
byte chip3 [24]; //holds blue 5-12
byte chip2 [24]; //holds red 9-12 and blue 1-4
byte chip1 [24]; //holds red 1-8

int x = 0;
int previousMillis = 0;

void setup(){
  SPI.begin();
}

void loop(){
  for (x =0; x<24; x=x+1){
    SPI.transfer(chip5 [x] );  // send the data from chip5 array position x into the chip5 shift register
    SPI.transfer(chip4 [x] );  // send the data from chip4 array position x into the chip4 shift register
    SPI.transfer(chip3 [x] );  // send the data from chip3 array position x into the chip3 shift register
    SPI.transfer(chip2 [x] );  // send the data from chip2 array position x into the chip2 shift register
    SPI.transfer(chip1 [x] );  // send the data from chip1 array position x into the chip1 shift register

    // now the anodes are set with their highs & lows, turn on the cathode driver
    SPI.transfer(left_cathode [x] );  // the data in these, 1,2,4,8,10,20,40,80, is set so that only 1 at a time is driven
    SPI.transfer(mid_cathode [x] );
    SPI.transfer(right_cathode [x] );
    delayMicroseconds(500); //  let the column shine a bit
  } // now you've gone thru all 24 columns

  // now tweak the data on chip1[ ], chip2[ ], chip3[ ], chip4[ ] and chip5[ ] to make the display change
  // its late, I can't think of a pattern, do something simple for now:

  if (millis() >= previousMillis){ // time to update the displays!
    previousMillis = (previousMillis + 500); // change every 1/2 second
    int color = color + 1; // define color as an int
    if (color == 256){
      color = 0;
    } // reset back to 0
    for (x=0; x<24; x=x+1){
      chip5[x] = color; // cycle thru from 0 to 255
      chip4[x] = color;
      chip3[x] = color;
      chip2[x] = color;
      chip1[x] = color;
    }
  }
}// end loop

Now, how many chips do you have? 192?

Code:
  for (x =0; x<24; x=x+1){
    SPI.transfer(chip5 [x] );  // send the data from chip5 array position x into the chip5 shift register
    SPI.transfer(chip4 [x] );  // send the data from chip4 array position x into the chip4 shift register
    SPI.transfer(chip3 [x] );  // send the data from chip3 array position x into the chip3 shift register
    SPI.transfer(chip2 [x] );  // send the data from chip2 array position x into the chip2 shift register
    SPI.transfer(chip1 [x] );  // send the data from chip1 array position x into the chip1 shift register

    // now the anodes are set with their highs & lows, turn on the cathode driver
    SPI.transfer(left_cathode [x] );  // the data in these, 1,2,4,8,10,20,40,80, is set so that only 1 at a time is driven
    SPI.transfer(mid_cathode [x] );
    SPI.transfer(right_cathode [x] );
    delayMicroseconds(500); //  let the column shine a bit
  } // now you've gone thru all 24 columns

Each SPI.transfer shifts out (best not leave out the F eh?) 8 bits, so you are sending out 24 * 8 * 8 bits. That's 1536 bits. Do you have 1536 LEDs?


I don't see you latching the data anywhere.
Logged

Seattle, WA
Offline Offline
Full Member
***
Karma: 1
Posts: 225
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry man, my knowledge of this is limited, i thought 24 was a bit high, i thought 8 for each chip. Youll have to talk to Rob about the 24 byte thing. Do you mean the output enabler as latching?
Logged

"It's Dr. Evil. I didn't spend six years in Evil Medical School to be called 'mister,' thank you very much."

Seattle, WA
Offline Offline
Full Member
***
Karma: 1
Posts: 225
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well if there is still confusion on how the anodes are wired, try this:
chip1:
q1 = r1
q2 = r2
q3 = r3
q4 = r4
q5 = r5
q6 = r6
q7 = r7
q8 = r8

chip2:
q1 = r9
q2 = r10
q3 = r11
q4 = r12
q5 = b1
q6 = b2
q7 = b3
q8 = b4

chip3:
q1 = b5
q2 = b6
q3 = b7
q4 = b8
q5 = b9
q6 = b10
q7 = b11
q8 = b12

chip4:
q1 = g1
q2 = g2
q3 = g3
q4 = g4
q5 = g5
q6 = g6
q7 = g7
q8 = g8

chip5:
q1 = g9
q2 = g10
q3 = g11
q4 = g12
q5 = //
q6 = //
q7 = //
q8 = //

I was just thinking that maybe that part about cycling the cathodes should be at the bottom of the loop, so you set up what you want the anodes to be set at at the beginning, then go and send out that info along with the first cathode, then it goes back to the top and the anodes info changes(or doesn't, depending on the pattern) then the bottom tells it to ground cathode 2 and so on, when it gets to the end, rinse and repeat. I'll give it a shot, but who knows what will happen.
Logged

"It's Dr. Evil. I didn't spend six years in Evil Medical School to be called 'mister,' thank you very much."

Seattle, WA
Offline Offline
Full Member
***
Karma: 1
Posts: 225
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well i kind of feel like im just talking t myself now, but i tried this and i cannot figure out why it doesn't work. It should be the short hand version of my bigger one, its just supposed to turn everything on and leave it, but it doesn't. Can anyone think of why? thanks.

Code:
// code for a 36 x 24 array (12 RGB LEDs, 24 columns)

#include <SPI.h>

// set up an array for the cathode drives
byte cathode6[ ] = { //chip 6, first 3rd of display
  0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
byte cathode7[ ] = { //chip 7, second 3rd of display
  0, 0, 0, 0, 0, 0, 0, 0, 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01, 0, 0, 0, 0, 0, 0, 0, 0
};
byte cathode8[ ] = { //chip 8, third 3rd of display
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01
};

byte chip5_value = 0xFF; //chip values
byte chip4_value = 0xFF;
byte chip3_value = 0xFF;
byte chip2_value = 0xFF;
byte chip1_value = 0xFF;

int columncount = 0;

byte oe = 10;

void setup(){
  digitalWrite (oe, LOW);
  SPI.begin();
}

void loop(){
  columncount = columncount++; // update for next column
  if (columncount == 24){
  columncount = 0;
  } // reset if reach the end
  //we have to transfer out the cathodes first
  SPI.transfer(cathode8[columncount]);
  SPI.transfer(cathode7[columncount]);
  SPI.transfer(cathode6[columncount]);
  //transfer out those colors
  SPI.transfer(chip5_value);
  SPI.transfer(chip4_value);
  SPI.transfer(chip3_value);
  SPI.transfer(chip2_value);
  SPI.transfer(chip1_value);
  delayMicroseconds(500);
} // end void loop
Logged

"It's Dr. Evil. I didn't spend six years in Evil Medical School to be called 'mister,' thank you very much."

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Well i kind of feel like im just talking t myself now,

I'm not clear as to what is wrong. Can you be more explicit about "it doesn't work"? Does nothing light up? The wrong things? The wrong colours?

I'm not familiar with the chips you are using, but usually you "latch" or "commit" the data you have sent to the chip.
Logged

Seattle, WA
Offline Offline
Full Member
***
Karma: 1
Posts: 225
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

yeah, sorry. when i say 'it doesn't work' its when nothing is lighting up. that comment was only because i felt weird posting 3 times in a row. but anyhow i did some debugging on that last bit i posted and it prints all the values i want it to be sending out. but for some reason the pins don't do anything. as for the IC just assume they are 8 bit shift registers, 8 in total, daisy chained. (they are 74hc574's with q1 wired to d2, q2 to d3 and so on, so they act just like shift registers) Do you know why that code wont work? I've gotten some long-hand stuff to work:

Code:
#include <SPI.h>

const int oe = 10;

byte chip1 = 0x00;
byte chip2 = 0x00;
byte chip3 = 0x00;
byte chip4 = 0x00;
byte chip5 = 0x00;

unsigned int time = 2000;

long randNum1;
long randNum2;
long randNum3;
long randNum4;
long randNum5;

void setup(){
  SPI.begin();
  pinMode(oe, OUTPUT);
  digitalWrite(oe, LOW);
  randomSeed(analogRead(0));
}

void loop(){
  
  randNum1 = random(0,255);
  randNum2 = random(0,255);
  randNum3 = random(0,255);
  randNum4 = random(0,255);
  randNum5 = random(0,255);
  
  chip1 = randNum1;
  chip2 = randNum2;
  chip3 = randNum3;
  chip4 = randNum4;
  chip5 = randNum5;
  
  SPI.transfer(0); //8
  SPI.transfer(0); //7
  SPI.transfer(0x80); //6
  SPI.transfer(chip5);
  SPI.transfer(chip4);
  SPI.transfer(chip3);
  SPI.transfer(chip2);
  SPI.transfer(chip1);
  delayMicroseconds(time);
  SPI.transfer(0);
  SPI.transfer(0);
  SPI.transfer(0x40);
  SPI.transfer(chip5);
  SPI.transfer(chip4);
  SPI.transfer(chip3);
  SPI.transfer(chip2);
  SPI.transfer(chip1);
  delayMicroseconds(time);
  SPI.transfer(0);
  SPI.transfer(0);
  SPI.transfer(0x20);
  SPI.transfer(chip5);
  SPI.transfer(chip4);
  SPI.transfer(chip3);
  SPI.transfer(chip2);
  SPI.transfer(chip1);
  delayMicroseconds(time);
  SPI.transfer(0);
  SPI.transfer(0);
  SPI.transfer(0x10);
  SPI.transfer(chip5);
  SPI.transfer(chip4);
  SPI.transfer(chip3);
  SPI.transfer(chip2);
  SPI.transfer(chip1);
  delayMicroseconds(time);
  SPI.transfer(0);
  SPI.transfer(0);
  SPI.transfer(0x08);
  SPI.transfer(chip5);
  SPI.transfer(chip4);
  SPI.transfer(chip3);
  SPI.transfer(chip2);
  SPI.transfer(chip1);
  delayMicroseconds(time);
  SPI.transfer(0);
  SPI.transfer(0);
  SPI.transfer(0x04);
  SPI.transfer(chip5);
  SPI.transfer(chip4);
  SPI.transfer(chip3);
  SPI.transfer(chip2);
  SPI.transfer(chip1);
  delayMicroseconds(time);
  SPI.transfer(0);
  SPI.transfer(0);
  SPI.transfer(0x02);
  SPI.transfer(chip5);
  SPI.transfer(chip4);
  SPI.transfer(chip3);
  SPI.transfer(chip2);
  SPI.transfer(chip1);
  delayMicroseconds(time);
  SPI.transfer(0);
  SPI.transfer(0);
  SPI.transfer(0x01);
  SPI.transfer(chip5);
  SPI.transfer(chip4);
  SPI.transfer(chip3);
  SPI.transfer(chip2);
  SPI.transfer(chip1);
  delayMicroseconds(time);
  
  SPI.transfer(0);
  SPI.transfer(0x80);
  SPI.transfer(0);
  SPI.transfer(chip5);
  SPI.transfer(chip4);
  SPI.transfer(chip3);
  SPI.transfer(chip2);
  SPI.transfer(chip1);
  delayMicroseconds(time);
  SPI.transfer(0);
  SPI.transfer(0x40);
  SPI.transfer(0);
  SPI.transfer(chip5);
  SPI.transfer(chip4);
  SPI.transfer(chip3);
  SPI.transfer(chip2);
  SPI.transfer(chip1);
  delayMicroseconds(time);
  SPI.transfer(0);
  SPI.transfer(0x20);
  SPI.transfer(0);
  SPI.transfer(chip5);
  SPI.transfer(chip4);
  SPI.transfer(chip3);
  SPI.transfer(chip2);
  SPI.transfer(chip1);
  delayMicroseconds(time);
  SPI.transfer(0);
  SPI.transfer(0x10);
  SPI.transfer(0);
  SPI.transfer(chip5);
  SPI.transfer(chip4);
  SPI.transfer(chip3);
  SPI.transfer(chip2);
  SPI.transfer(chip1);
  delayMicroseconds(time);
  SPI.transfer(0);
  SPI.transfer(0x08);
  SPI.transfer(0);
  SPI.transfer(chip5);
  SPI.transfer(chip4);
  SPI.transfer(chip3);
  SPI.transfer(chip2);
  SPI.transfer(chip1);
  delayMicroseconds(time);
  SPI.transfer(0);
  SPI.transfer(0x04);
  SPI.transfer(0);
  SPI.transfer(chip5);
  SPI.transfer(chip4);
  SPI.transfer(chip3);
  SPI.transfer(chip2);
  SPI.transfer(chip1);
  delayMicroseconds(time);
  SPI.transfer(0);
  SPI.transfer(0x02);
  SPI.transfer(0);
  SPI.transfer(chip5);
  SPI.transfer(chip4);
  SPI.transfer(chip3);
  SPI.transfer(chip2);
  SPI.transfer(chip1);
  delayMicroseconds(time);
  SPI.transfer(0);
  SPI.transfer(0x01);
  SPI.transfer(0);
  SPI.transfer(chip5);
  SPI.transfer(chip4);
  SPI.transfer(chip3);
  SPI.transfer(chip2);
  SPI.transfer(chip1);
  delayMicroseconds(time);
  
  SPI.transfer(0x80);
  SPI.transfer(0);
  SPI.transfer(0);
  SPI.transfer(chip5);
  SPI.transfer(chip4);
  SPI.transfer(chip3);
  SPI.transfer(chip2);
  SPI.transfer(chip1);
  delayMicroseconds(time);
  SPI.transfer(0x40);
  SPI.transfer(0);
  SPI.transfer(0);
  SPI.transfer(chip5);
  SPI.transfer(chip4);
  SPI.transfer(chip3);
  SPI.transfer(chip2);
  SPI.transfer(chip1);
  delayMicroseconds(time);
  SPI.transfer(0x20);
  SPI.transfer(0);
  SPI.transfer(0);
  SPI.transfer(chip5);
  SPI.transfer(chip4);
  SPI.transfer(chip3);
  SPI.transfer(chip2);
  SPI.transfer(chip1);
  delayMicroseconds(time);
  SPI.transfer(0x10);
  SPI.transfer(0);
  SPI.transfer(0);
  SPI.transfer(chip5);
  SPI.transfer(chip4);
  SPI.transfer(chip3);
  SPI.transfer(chip2);
  SPI.transfer(chip1);
  delayMicroseconds(time);
  SPI.transfer(0x08);
  SPI.transfer(0);
  SPI.transfer(0);
  SPI.transfer(chip5);
  SPI.transfer(chip4);
  SPI.transfer(chip3);
  SPI.transfer(chip2);
  SPI.transfer(chip1);
  delayMicroseconds(time);
  SPI.transfer(0x04);
  SPI.transfer(0);
  SPI.transfer(0);
  SPI.transfer(chip5);
  SPI.transfer(chip4);
  SPI.transfer(chip3);
  SPI.transfer(chip2);
  SPI.transfer(chip1);
  delayMicroseconds(time);
  SPI.transfer(0x02);
  SPI.transfer(0);
  SPI.transfer(0);
  SPI.transfer(chip5);
  SPI.transfer(chip4);
  SPI.transfer(chip3);
  SPI.transfer(chip2);
  SPI.transfer(chip1);
  delayMicroseconds(time);
  SPI.transfer(0x01);
  SPI.transfer(0);
  SPI.transfer(0);
  SPI.transfer(chip5);
  SPI.transfer(chip4);
  SPI.transfer(chip3);
  SPI.transfer(chip2);
  SPI.transfer(chip1);
  delayMicroseconds(time);
}

Logged

"It's Dr. Evil. I didn't spend six years in Evil Medical School to be called 'mister,' thank you very much."

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 524
Posts: 26473
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

Paranemertes,
Do you really have all 8 shift registers daisy chained?
Or do you have chain of five 74AC574 for the anodes, and a chainof three 74HC595's for the cathodes?
This will work a lot better if they are seperate.
Can you post the schematic for the control logic?

I believe what the design was intended to do is this:
Start with the cathodes all off. Shift 0's into them as part of setup.

Then in loop:
shift data into the '574s (which are wired up like shift registers).
then shift out the cathode data for column, and use the 74HC595 latch pin to make it show up at the HC595 output.
Then turn off off the cathodes.
Shift out the next set of anode data.
then shift out the cathode data for column, and use the 74HC595 latch pin to make it show up at the HC595 output.
Then turn off off the cathodes.
repeat 22 more times.

so pseudocode:
Code:
void loop(){
for (x=0 to 23) { // 24 columns, equivalent of 36 LEDs per column,anodes addressed as 5 bytes (last 4 not connected)
SPI.transfer 5 bytes of anode data  // no latch needed, 574 is wired like a single stage shift register
// turn on the cathode for that column
digitalWrite (cathode latch pin Low)
SPI.transfer  3 bytes of cathode data
digitalWrite (cathode latch pin High) // rising edge latches the data into the '595 outputs
delay (500uS)
// now turn off the cathodes
digitalWrite (cathode latch pin Low)
SPI.transfer  (3 bytes of 0)
digitalWrite (cathode latch pin High) // rising edge latches the data into the '595 outputs
} // next x
// manipulate the 5 anode bytes
} //end void loop
If you really have all 8 daisy chained together, may have to rethink this a little. Ideally they would be 2 seperate chains, so the anode data is not being changed while the cathode are being turned on & off.

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.

Seattle, WA
Offline Offline
Full Member
***
Karma: 1
Posts: 225
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

yeah they are indeed all daisy chained, anodes and cathodes all together. I see what your saying, that does sound easier, but too late now.
Quote
Can you post the schematic for the control logic?
What exactly is that? And do you know why this code wouldnt work? Its just the short hand simple version of what i started out doing, and when i look at the values it prints at the end it all checks out, but nothing lights up. no pin changes.
Code:
// code for a 36 x 24 array (12 RGB LEDs, 24 columns)

#include <SPI.h>

// set up an array for the cathode drives
byte cathode6[] = { //chip 6, first 3rd of display
  0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
byte cathode7[] = { //chip 7, second 3rd of display
  0, 0, 0, 0, 0, 0, 0, 0, 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01, 0, 0, 0, 0, 0, 0, 0, 0
};
byte cathode8[] = { //chip 8, third 3rd of display
  0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x01
};

byte chip5 = 0xFF; //chip values
byte chip4 = 0xFF;
byte chip3 = 0xFF;
byte chip2 = 0xFF;
byte chip1 = 0xFF;

int columncount = 0;
unsigned int time = 500;

const int oe = 10;

void setup(){
  pinMode(oe, OUTPUT);
  digitalWrite(oe, LOW);
  SPI.begin();
  Serial.begin(9600);
}

void loop(){
  //we have to transfer out the cathodes first
  SPI.transfer(cathode8[columncount]);
  SPI.transfer(cathode7[columncount]);
  SPI.transfer(cathode6[columncount]);
  columncount = columncount + 1; // update for next column
  if (columncount == 24){
  columncount = 0; // reset if reach the end
  }
  //transfer out those colors
  SPI.transfer(chip5);
  SPI.transfer(chip4);
  SPI.transfer(chip3);
  SPI.transfer(chip2);
  SPI.transfer(chip1);
  Serial.println(cathode8[columncount], HEX);
  Serial.println(cathode7[columncount], HEX);
  Serial.println(cathode6[columncount], HEX);
  Serial.println(chip5, HEX);
  Serial.println(chip4, HEX);
  Serial.println(chip3, HEX);
  Serial.println(chip2, HEX);
  Serial.println(chip1, HEX);
  delay(time);
} // end void loop
Logged

"It's Dr. Evil. I didn't spend six years in Evil Medical School to be called 'mister,' thank you very much."

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 524
Posts: 26473
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

http://arduino.cc/forum/index.php/topic,97488.15.html
Reply #29 in this thread, "ok so i have a final version of the board."
Is there a schematic that goes with it? Or is that the best there is to work with?
If so, SPI.transfer() is not going to work, you don't have the SPI clock line, SCK, connected to anything.
Doesn't fritzing have some kind of schematic feature as well?
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.

Seattle, WA
Offline Offline
Full Member
***
Karma: 1
Posts: 225
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

yes fritzing has a schematic function, ill work on that. but i did set up the board so that SPI would work, all the long-hand SPI i have done works perfectly, its the short-hand that doesn't. Give me a little bit and ill have a schematic for you.
Logged

"It's Dr. Evil. I didn't spend six years in Evil Medical School to be called 'mister,' thank you very much."

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 474
Posts: 18696
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Why are you using flip-flops and not shift registers? I'm not sure that in a single transition they will ripple along the way you describe. They might.
Logged

Global Moderator
Boston area, metrowest
Offline Offline
Brattain Member
*****
Karma: 524
Posts: 26473
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

Octal latches were used to provide high current drive, vs the 4-6mA of a shift register Nick.

If you drive the anode info and cathode at the same time, and use the cathode OE to actually turn on the column, should end up looking like a normal display.
I'm thinking Paranemertes is just missing something real subtle in the loop code.

That and not understanding about having the anode info for each column coming from an array, vs creating it all on the fly.
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.

Pages: 1 2 [3] 4 5   Go Up
Jump to: