Controlling an 8x8 Matrix Common Anode Array

So I have my led matrix (common anode) wired up like shown here:


]( Credit Francis Shanahan )

I'm trying to follow the shiftOut tutorial but modify it so that the LED starts as one color on the corner call it (0,0) or Q0 on Chip 1, Green Cathode, and walk it over the matrix to test all of the led's. Switch colors and repeat with red and then blue.

Currently attempting to do this lights up the matrix in random blocks of colors and has me slightly perplexed as to what I'm doing wrong, or if I have shorts. Checking it over and rewiring doesn't seem to have altered this behavior.

Well for a start you ha e no decoupling capacitors on any of the chips.
Next why not post your code.
Finally any chance of a real schematic that shows how things are wired up not leaving things dangling and disconnected.

You should be able to use SPI.transfer.

As Mike says, post your code as it may be the problem spot. Maybe. Maybe the lack of decoupling capacitors is.

I'm following along on the instructions with the shiftOut tutorial on the site shiftOut() - Arduino Reference , Code sample 1.2 "One by One" http://arduino.cc/en/Tutorial/ShftOut12

I have DS #14 ( Blue) -> D11; SH_CP #12 (Yellow) -> D12; ST_CP #12 (green) -> D8 5V -> Arduino 5V, Ground to Arduino Ground.

As of now I have not written any of my own code, just trying to test what is wired up with the examples.

Ok so Im going to try this over again with green LED's only, throwing out everything I have done.

My matrix is like so with the orientation that pin 1 is at the bottom left:
I believe it is very similar or possibly even the same one here http://www.seeedstudio.com/wiki/60mm_square_8*8_LED_matrix_-_super_bright_RGB

[32 - 17]
[1 - 16]

32,31,30,29 - are one set of anodes
28,27,26,25,24,23,22,21 green cathodes
20,19,18,17 are the second set of anodes

connecting pin 32 to ground and pin 28 to +5v's with a 330 Ohm resistor lights up the green row 1-8 as I move from 28 -21
31 with 28 -21 lights the second row from the bottom.
so on and so forth, I get to the last pin 29, and then have to jump over to 20 - 17 to light the top half of the matrix.

I will use two of my 47HC595 chips, one for the anodes and one for the green cathodes.
CHIP 1 : Q0 - G3 to 32 - 29, Q4-Q7 to 20 - 17
CHIP 2: Q0 - Q7 to 28 - 21

I will draw a schematic and post it as soon as its done,

Common Anode - You need to use appropriate parts to source current into the anodes and sink current from the cathodes.
HC595 is not the best choice.

A better choice is a "high side driver", basically a shift register with p-channel mosfet outputs to source current.
On the cathode side, a part like TPIC6B595 is better because it can sink current on all 8 channels at higher levels then HC595.
Best results will be one row of LEDs on at a time, any and all 3 colors, allows for faster multiplexing and a brighter display when you have 3 colors.

What controls whether a HC595 sinks current from a cathode or provides it for an anode? Simply connecting the LED cathodes do it?

Reiterating CrossRoads' observation, there is no way the 74HC595 can provide the necessary anode current for multiple cathodes, even if it can effectively provide that for the cathodes. A simple way around this would be to put an NPN emitter follower transistor into each anode circuit - collector to 5V (or anything higher - you may bypass the regulator), base to the HC595 output and emitter to the LED matrix anode. No other components are required to be added. There will be a 0.65V penalty in the voltage delivered, but actually much less than if you try to drive with the HC595 alone.

My concern is the peculiar sequence in which you are chaining the HC595 serial lines with the green cathodes first, then the anodes, then blue and red cathodes. I suspect it would be quite easy to be sending the data bytes in the wrong order. Do remember that you have to send all four bytes every time before sending the latch signal.

What controls whether a HC595 sinks current from a cathode or provides it for an anode? Simply connecting the LED cathodes do it?

The HC595 can source current into an anode by shifting in a 1 for a high output.
It can sink current from a cathode by shifting in a 1 for a low output.
The problem is quantity - the part as a whole can only source or sink 70mA Absolute Max.
So 8 outputs on at once requires a limit of 70/8 = 8.75mA.
And if you have only 1 output on at a time, there is a limit of how much you can get from a pin

After 6mA, the output voltage starts degrading. So it's not really the right part for this application.
Now add in that you are multiplexing, and you cut the amount of on time for each color to 1/24th of the total available on time. Or worse, you try to work around the HC595 limits by only driving 1 LED at a time, and now you cut the ontime down to 1/64th of 1/24th.
Add in that you want refresh of the entire matrix to occur 24-30 times per second for flicker-free operation, and you can see the ontime will be very small.
So for best results, use hardware that can source 8 x 20mA = 160mA into the anodes, and that can sink a full 20mA from a cathode.
After that, writing some code that will read a byte from an array and send it to the appropriate shift register every 1/24 of a second is pretty simple using blink without delay style coding.

So something like this sound better?

3 x TPIC6B595 - 1 per set of color cathodes
1 x SN74AHCT595N (3 extra)
1 x UDN2981A - Anode Driver ( contains eight 'high-side switches')

For code attempt to control over spi?

For code to start I was going to try something like this, with only the anode and the
green shift registers connected. Having the green and then the anode register,

Shouldn't shiftOut(datapin, clockpin, MSBFIRST, matrixcolumn[column-1]); //set column
push the first command "shiftOut(datapin, clockpin, MSBFIRST, 255); // set anodes"
into the anode register?

void pixeldisplay(int row, int column, int pause)
// turns on and off a pixel at row, column with pause
{
digitalWrite(latchpin, LOW);
shiftOut(datapin, clockpin, MSBFIRST, 255); // set anodes
shiftOut(datapin, clockpin, MSBFIRST, matrixcolumn[column-1]); //set column
shiftOut(datapin, clockpin, MSBFIRST, matrixrow[row-1]); //set row
digitalWrite(latchpin, HIGH);
delay(pause);
}

You have 4 shift registers, yes?
So send the data out using 4 SPI.transfers.

void loop (){
currentMicros = micros(); // capture the current 'time'
elapsedMicros = currentMicros - nextMicros; // how much time has passed?
if ( elapsedMicros >=onDuration){  // ready for the next row?
nextMicros = nextMicros + onDuration;  // set up for next multiplex time
row=row+1;
if (row==24){row=0;} // keep track of rows 0 to 23

digitalWrite (latchPin, LOW); // use direct port manipulation to do this faster
SPI.transfer(anodePins[row]);
SPI.transfer(CathodePins[row*8]); // use 0 when rows are to be off
SPI.transfer(CathodePins[(row*8)+1]);
SPI.transfer(CathodePins[(row*8)+2]);
// data gets moved to output stage with this rising edge:
digitalWrite (latchPin, LOW); // use direct port manipulation to do this faster

} // end time check

//
// do other stuff while waiting
//

} // end loop

anodePins[] = {0x01, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80,};
and
colorCathodePins[] = { // 3 bytes of data for each row, with 0's when a color is off
data, 0, 0, // row 0
0, data, 0,
0, 0, data,
data, 0, 0, // row 1
0, data, 0,
0, 0, data,
data, 0, 0, // row 2
0, data, 0,
0, 0, data,
data, 0, 0, // row 3
0, data, 0,
0, 0, data,
data, 0, 0, // row 4
0, data, 0,
0, 0, data,
data, 0, 0, // row 5
0, data, 0,
0, 0, data,
data, 0, 0, // row 6
0, data, 0,
0, 0, data,
data, 0, 0, // row 7
0, data, 0,
0, 0, data,
};

Make sense?

So kinda, here you are setting anodes as 1,2,4,8,16,32, etc. I'm having an issue whats going on with the rows however,
your taking cathode pin row 0x018 = 8, 0x018+1=9, 0x01*8+2=10. What do you send you for data in the colorCathodePins ?

Right now I have IC's 3 and 4 removed, I just orded the 4 parts I don't have. I want to run the greens off of the anodes and cathodes that are connected as shown above, as a test and one led at a time lit, is it doable with just the two HC595 at the moment?

To answer #12 first - the 1,2,4,8,etc. turn on one anode at a time.
The color cathodes, you send out the data for what you want displayed.
Say for instance you wanted to make 3 squares with green around the outside, red inside that, and blue inside that.
1's represent all the LEDs that will appear on thru persistance of vision.
All LEDs
11111111
11111111
11111111
11100111
11100111
11111111
11111111
11111111

Green LEDs data element in colorArray[]
11111111 0
10000001 3
10000001 6
10000001 9
10000001 12
10000001 15
10000001 18
11111111 21

Red LEDs
00000000 1
01111110 4
01000010 7
01000010 10
01000010 13
01000010 16
01111110 19
00000000 22

Blue LEDs
00000000 2
00000000 5
00111100 8
00100100 11
00100100 14
00100100 17
00100100 20
00111100 23
00000000 26
00000000 29

(oh, for a fixed width font!)

So when you send a Green byte out, you send out 0 and 0 for Red & Blue so they are off.
When you send Red out, Green & Blue are 0
When you send Blue out, Green 7 Red are 0

My software logic above may need some revising to actually do that, but you can see how the multiplexing would work.
Build in all 3 colors to start even if only using Green, will be easier than shoehorning it in later.

Yes, you can test 1 LED at a time with two 74HC595.

So far I have this, connecting pins
D11 to DS of 74HC595,
SCK D13 to SH_CP of 74HC595
CS D10 to ST_CP of 74HC595

How do I wire up the second register to the first one?
PIN 9 Q7" Serial Out to PIN 14 DS on the green just like it is now?

Here is the code I quickly wrote up after taking a look at the tutorial examples here
Im going to try and walk the matrix lighting each green led, turning on the next and the one before it off.

#include "SPI.h"

int ss=10; // D10 for SPI slave select
int pause=200; 
 
void setup()
{
  pinMode(ss, OUTPUT); // set ss pin to output
  SPI.begin(); // wake SPI.
  SPI.setBitOrder(MSBFIRST);
}
 
void setValue(int anode_position, int red, int green, int blue)
{
  digitalWrite(ss, LOW);
  SPI.transfer(anode); // send anode byte
  SPI.transfer(red); // send value (0~128)
  SPI.transfer(green); // send value (0~128)
  SPI.transfer(blue); // send value (0~128)
  digitalWrite(ss, HIGH);
}
 
void loop()
{
  //Select each anode, counting down from 128 (1st row) to 0 (8th row) by powers of two.
  //0 == Bx000000000, 1 == Bx0000001, 2 == Bx00000010 .... 128 == Bx1000000

  for(int anode = 7, anode >= 0, anode--;) 
  {
    //select anode ( the row )
    int anode_position = ipow(2,anode);
    int column_position = 0;
    
    //Select the column to light 
    for(int row = 7, row >= 0,row--;)
    { 
      //update the position of column
      column_position = ipow(2,row); 
    }
 
   setValue(anode_position,0,column_position,0);
  }	
}

//Get power as an int, without math library
int ipow(int base, int exp)
{
    int result = 1;
    while (exp)
    {
        if (exp & 1)
            result *= base;
        exp >>= 1;
        base *= base;
    }

    return result;
}