I am trying to daisy chain 4 boards together, I set up the function daisyChain that takes (int matrix) so that I could easily change the number of boards in the chain. And yes, I did attempt to run this on each board individually before chaining them together.
However when I have the boards together, I only get jumbled pixels here and there.
EDIT: Okay, I partially solved the problem, it seems that since I was using 2 power supplies to power the arduino, and matrix’s I needed to tie the grounds together. Now I get a definable image (a heart), however, it is shifted to the left by +1 pixel on every matrix.
Here is the complete code I am using.
#define CHIPSELECT 10//ss
#define SPICLOCK 13//sck
#define DATAOUT 11//MOSI
#define DATAIN 12//MISO
int color = 1;
int count = 1;
long randNum;
int data[] =
{
0,0,0,0,0,0,0,0,
0,0,64,64,0,64,64,0,
0,64,0,0,64,0,0,64,
0,64,0,0,0,0,0,64,
0,0,64,0,0,0,64,0,
0,0,0,64,0,64,0,0,
0,0,0,0,64,0,0,0,
0,0,0,0,0,0,0,0
};
========================================================================================
void setup()
{
byte clr;
pinMode(DATAOUT,OUTPUT);
pinMode(SPICLOCK,OUTPUT);
pinMode(CHIPSELECT,OUTPUT);
digitalWrite(CHIPSELECT,HIGH); //disable device
//SPI Bus setup
SPCR = (1<<SPE)|(1<<MSTR)|(1<<SPR1); //Enable SPI HW, Master Mode, divide clock by 16
delay(10);
//daisyChain(4); // let the backpack know that it is in a chain of "x" matrix's
}
========================================================================================
void loop()
{
digitalWrite(CHIPSELECT,LOW); // enable the ChipSelect on the backpack
delayMicroseconds(500);
for(int n=0;n<4;n++)
{
for (int x=0;x<64;x++) // Send pre-built array
{
spi_transfer(data[x]);
}
}
digitalWrite(CHIPSELECT,HIGH); // disable the ChipSelect on the backpack
delayMicroseconds(500);
delay(1000);
}
========================================================================================
char spi_transfer(volatile char data)
{
SPDR = data; // Start the transmission
while (!(SPSR & (1<<SPIF))) // Wait the end of the transmission
{
};
}
========================================================================================
void daisyChain(int matrix)
{
digitalWrite(CHIPSELECT,LOW); // enable the ChipSelect on the backpack
delayMicroseconds(500);
spi_transfer('%');
spi_transfer(matrix);
digitalWrite(CHIPSELECT,HIGH); // disable the ChipSelect on the backpack
delayMicroseconds(500);
}
And this is the output…
http://cse.secs.oakland.edu/~srcasade/RGB.JPG