rgb 8x8 LED MATRIX BACKPACK

Having problems moving forward with the new rgb 8x8 led matrix backpack from sparkfun

I’d like to showcase a series of images on the matrix, but it’s driving me mad. any help is greatly appreciated.

-C

I uploaded this code with success:

// Simple program to test using the Arduino with the RGB Matrix
// & Backpack from Sparkfun. Code is a combination of Heather Dewey-Hagborg,
// Arduino Forum user: Little-Scale, and // Daniel Hirschmann. Enjoy!
//
// The Backpack requires 125Khz SPI, which is the slowest rate
// at which the Arduino’s hardware SPI bus can communicate at.
//
// We need to send SPI to the backpack in the following steps:
// 1) Activate ChipSelect;
// 2) Wait 500microseconds;
// 3) Transfer 64bytes @ 125KHz (1 byte for each RGB LED in the matrix);
// 4) De-activate ChipSelect;
// 5) Wait 500microseconds
// Repeat however often you like!

#define CHIPSELECT 10//ss
#define SPICLOCK 13//sck
#define DATAOUT 11//MOSI
#define DATAIN 12//MISO

char spi_transfer(volatile char data)
{
SPDR = data; // Start the transmission
while (!(SPSR & (1<<SPIF))) // Wait the end of the transmission
{
};
}

void setup()
{
byte clr;
pinMode(DATAOUT,OUTPUT);
pinMode(SPICLOCK,OUTPUT);
pinMode(CHIPSELECT,OUTPUT);
digitalWrite(CHIPSELECT,HIGH); //disable device

SPCR = B01010001; //SPI Registers
SPSR = SPSR & B11111110; //make sure the speed is 125KHz

/*
SPCR bits:
7: SPIEE - enables SPI interrupt when high
6: SPE - enable SPI bus when high
5: DORD - LSB first when high, MSB first when low
4: MSTR - arduino is in master mode when high, slave when low
3: CPOL - data clock idle when high if 1, idle when low if 0
2: CPHA - data on falling edge of clock when high, rising edge when low
1: SPR1 - set speed of SPI bus
0: SPR0 - set speed of SPI bus (00 is fastest @ 4MHz, 11 is slowest @ 250KHz)
*/

clr=SPSR;
clr=SPDR;
delay(10);
}

void loop()
{
delay(100);
digitalWrite(CHIPSELECT,LOW); // enable the ChipSelect on the backpack
delayMicroseconds(500);
for (int i=0;i<8;i++) for (int j=0;j<8;j++)
{
spi_transfer(i);
// There are only 8 colours available to the matrix with the
// backpack, so this will present 1 colour per column on the matrix
}
digitalWrite(CHIPSELECT,HIGH); // disable the ChipSelect on the backpack
delayMicroseconds(500);
}

What exactly do you want to do?

Thanks for your response.

the end goal is to have audio in, using an apple plain talk microphone, control the brightness and or image on the matrix. I figured out how to send a particular still image to the matrix, but I’m stuck at that point now.

Piece of cake, you are through the tough part if you can get an image up.
If you don’t get this answer, just send me the code and I’ll show you what you have to do.

Define a global variable called say

char *out_buffer; // Pointer to next image to be sent.

And a function to write that buffer out when you need to:

/*
Write image to display.
/
void write_buffer(){
digitalWrite(SLAVESELECT,LOW); // enable
delay(5);
for(int i = 0; i < 64; i++){
shiftOut(DATAOUT, SPICLOCK, MSBFIRST, out_buffer
);*

  • }*
  • digitalWrite(SLAVESELECT,HIGH); // disable device*
  • delay(5);*
    }
    [/quote]
    Now lets define some images
    > byte CHECKED1[] = {
    > 0,0,0,0,1,1,1,1,
    > 0,0,0,0,1,1,1,1,
    > 0,0,0,0,1,1,1,1,
    > 0,0,0,0,1,1,1,1,
    > 1,1,1,1,0,0,0,0,
    > 1,1,1,1,0,0,0,0,
    > 1,1,1,1,0,0,0,0,
    > 1,1,1,1,0,0,0,0
    > };
    > byte CHECKED2[] = {
    > 1,1,1,1,0,0,0,0,
    > 1,1,1,1,0,0,0,0,
    > 1,1,1,1,0,0,0,0,
    > 1,1,1,1,0,0,0,0,
    > 0,0,0,0,1,1,1,1,
    > 0,0,0,0,1,1,1,1,
    > 0,0,0,0,1,1,1,1,
    > 0,0,0,0,1,1,1,1
    > };
    > byte X [] = {
    > 1,1,1,0,0,1,1,1,
    > 0,1,0,0,0,0,1,0,
    > 0,0,1,0,0,1,0,0,
    > 0,0,0,1,1,0,0,0,
    > 0,0,0,1,1,0,0,0,
    > 0,0,1,0,0,1,0,0,
    > 0,1,0,0,0,0,1,0,
    > 1,1,1,0,0,1,1,1
    > };
    now in loop set the out_buffer and send it.
    > void loop(void){
    > out_buffer = CHECKED1;
    > write_buffer();
    > delay(500);
    >
    > out_buffer = CHECKED2;
    > write_buffer();
    > delay(500);
    > }
    This is a simplification of some bike light code that can be found http://docs.google.com/Doc?docid=ddrqznjs_127d8sc2xc3&hl=en.
    Good luck and let me know if that works.

Oops, didn’t see you had included the code. Using your setup it might look like this.
Justin

#define CHIPSELECT 10//ss
#define SPICLOCK 13//sck
#define DATAOUT 11//MOSI
#define DATAIN 12//MISO

char *out_buffer; // Pointer to next image to be sent.

// some images
byte CHECKED1 = {
0,0,0,0,1,1,1,1,
0,0,0,0,1,1,1,1,
0,0,0,0,1,1,1,1,
0,0,0,0,1,1,1,1,
1,1,1,1,0,0,0,0,
1,1,1,1,0,0,0,0,
1,1,1,1,0,0,0,0,
1,1,1,1,0,0,0,0
};
byte CHECKED2 = {
1,1,1,1,0,0,0,0,
1,1,1,1,0,0,0,0,
1,1,1,1,0,0,0,0,
1,1,1,1,0,0,0,0,
0,0,0,0,1,1,1,1,
0,0,0,0,1,1,1,1,
0,0,0,0,1,1,1,1,
0,0,0,0,1,1,1,1
};

char spi_transfer(volatile char data)
{
SPDR = data; // Start the transmission
while (!(SPSR & (1<<SPIF))) // Wait the end of the transmission
{
};
}

/*
Write image to display.
/
void write_buffer(){
digitalWrite(SLAVESELECT,LOW); // enable
delay(5);
for(int i = 0; i < 64; i++){
spi_transfer(out_buffer
);*

  • }*
  • digitalWrite(SLAVESELECT,HIGH); // disable device*
  • delay(5);*
    }
    void setup()
    {
    byte clr;
    pinMode(DATAOUT,OUTPUT);
    pinMode(SPICLOCK,OUTPUT);
    pinMode(CHIPSELECT,OUTPUT);
    digitalWrite(CHIPSELECT,HIGH); //disable device
    SPCR = B01010001; //SPI Registers
    SPSR = SPSR & B11111110; //make sure the speed is 125KHz
    clr=SPSR;
    clr=SPDR;
    delay(10);
    }
    *void loop() *
    {
  • out_buffer = CHECKED1;*
  • write_buffer();*
  • delay(500);*
  • out_buffer = CHECKED2;*
  • write_buffer();*
  • delay(500);*
    }
    [/quote]

Thank you very much : )

I pretty much pasted the code you had provided into arduino, just changed SLAVESELECT to CHIPSELECT…

There seams to be an error in the void(loop)
Error : invalid conversions from Byte to Char…

I’m going to trouble shoot it, but maybe you have a quick answer…

Thanks again, I appreciate the help.


#define CHIPSELECT 10//ss
#define SPICLOCK 13//sck
#define DATAOUT 11//MOSI
#define DATAIN 12//MISO

char *out_buffer; // Pointer to next image to be sent.

// some images
byte CHECKED1 = {
0,0,0,0,1,1,1,1,
0,0,0,0,1,1,1,1,
0,0,0,0,1,1,1,1,
0,0,0,0,1,1,1,1,
1,1,1,1,0,0,0,0,
1,1,1,1,0,0,0,0,
1,1,1,1,0,0,0,0,
1,1,1,1,0,0,0,0
};
byte CHECKED2 = {
1,1,1,1,0,0,0,0,
1,1,1,1,0,0,0,0,
1,1,1,1,0,0,0,0,
1,1,1,1,0,0,0,0,
0,0,0,0,1,1,1,1,
0,0,0,0,1,1,1,1,
0,0,0,0,1,1,1,1,
0,0,0,0,1,1,1,1
};

char spi_transfer(volatile char data)
{
SPDR = data; // Start the transmission
while (!(SPSR & (1<<SPIF))) // Wait the end of the transmission
{
};
}

/*
Write image to display.
/
void write_buffer(){
digitalWrite(CHIPSELECT,LOW); // enable
delay(5);
for(int i = 0; i < 64; i++){
spi_transfer(out_buffer
);*
}
digitalWrite(CHIPSELECT,HIGH); // disable device
delay(5);
}
void setup()
{
byte clr;
pinMode(DATAOUT,OUTPUT);
pinMode(SPICLOCK,OUTPUT);
pinMode(CHIPSELECT,OUTPUT);
digitalWrite(CHIPSELECT,HIGH); //disable device
SPCR = B01010001; //SPI Registers
SPSR = SPSR & B11111110; //make sure the speed is 125KHz
clr=SPSR;
clr=SPDR;
delay(10);
}
*void loop() *
{
out_buffer = CHECKED1;
write_buffer();
delay(500);
out_buffer = CHECKED2;
write_buffer();
delay(500);
}

Alright. simple fix…

change char to byte

here’s the code that is working for me…
I owe you a cupcake ; )

#define CHIPSELECT 10//ss
#define SPICLOCK 13//sck
#define DATAOUT 11//MOSI
#define DATAIN 12//MISO

byte *out_buffer; // Pointer to next image to be sent.

// some images
byte CHECKED1 = {
0,0,0,0,1,1,1,1,
0,0,0,0,1,1,1,1,
0,0,0,0,1,1,1,1,
0,0,0,0,1,1,1,1,
1,1,1,1,0,0,0,0,
1,1,1,1,0,0,0,0,
1,1,1,1,0,0,0,0,
1,1,1,1,0,0,0,0
};
byte CHECKED2 = {
1,1,1,1,0,0,0,0,
1,1,1,1,0,0,0,0,
1,1,1,1,0,0,0,0,
1,1,1,1,0,0,0,0,
0,0,0,0,1,1,1,1,
0,0,0,0,1,1,1,1,
0,0,0,0,1,1,1,1,
0,0,0,0,1,1,1,1
};

char spi_transfer(volatile char data)
{
SPDR = data; // Start the transmission
while (!(SPSR & (1<<SPIF))) // Wait the end of the transmission
{
};
}

/*
Write image to display.
/
void write_buffer(){
digitalWrite(CHIPSELECT,LOW); // enable
delay(5);
for(int i = 0; i < 64; i++){
spi_transfer(out_buffer
);*
}
digitalWrite(CHIPSELECT,HIGH); // disable device
delay(5);
}
void setup()
{
byte clr;
pinMode(DATAOUT,OUTPUT);
pinMode(SPICLOCK,OUTPUT);
pinMode(CHIPSELECT,OUTPUT);
digitalWrite(CHIPSELECT,HIGH); //disable device
SPCR = B01010001; //SPI Registers
SPSR = SPSR & B11111110; //make sure the speed is 125KHz
clr=SPSR;
clr=SPDR;
delay(10);
}
*void loop() *
{
out_buffer = CHECKED1;
write_buffer();
delay(500);
out_buffer = CHECKED2;
write_buffer();
delay(500);
}

Just as a side not; could you only have CHECKED1 and then change:

void loop() { out_buffer = CHECKED1; write_buffer(); delay(500);

out_buffer = CHECKED2; write_buffer(); delay(500); }

to

void loop() { out_buffer = CHECKED1; write_buffer(); delay(500);

out_buffer = !CHECKED1; write_buffer(); delay(500); }

Because CHECKED1 and 2 are just the opposite bits of each other?!

/me

hm… I am making progress, but I have stumbled upon a new problem.

So I have a set up now that if I press a button I get one type of response on the matrix, and if I press it again I get another.

The problem is they seam to be getting mixed up a bit. Like: if switchstate is ‘on’ I get a flash of switchstate ‘off’.

any thoughts on why? any help is greatly appreciated…

I have the following code:

#define CHIPSELECT 10//ss
#define SPICLOCK 13//sck
#define DATAOUT 11//MOSI
#define DATAIN 12//MISO

int switchPin = 2; // digital input pin for a switch
int switchState = 0; // the state of the switch

byte *out_buffer; // Pointer to next image to be sent.

byte C2 = {
0xC0,0,0,0,0,0,0,0,
0xC0,0,0,0,0,0,0,0,
0xC0,0,0,0,0,0,0,0,
0xC0,0,0,0,0,0,0,0,
0xC0,0,0,0,0,0,0,0,
0xC0,0,0,0,0,0,0,0,
0xC0,0,0,0,0,0,0,0,
0xC0,0,0,0,0,0,0,0
};

byte C3 = {
1,0xC0,0,0,0,0,0,0,
1,0xC0,0,0,0,0,0,0,
1,0xC0,0,0,0,0,0,0,
1,0xC0,0,0,0,0,0,0,
1,0xC0,0,0,0,0,0,0,
1,0xC0,0,0,0,0,0,0,
1,0xC0,0,0,0,0,0,0,
1,0xC0,0,0,0,0,0,0
};

byte C4 = {
0,1,0xC0,0,0,0,0,0,
0,1,0xC0,0,0,0,0,0,
0,1,0xC0,0,0,0,0,0,
0,1,0xC0,0,0,0,0,0,
0,1,0xC0,0,0,0,0,0,
0,1,0xC0,0,0,0,0,0,
0,1,0xC0,0,0,0,0,0,
0,1,0xC0,0,0,0,0,0
};

byte C5 = {
0,0,1,0xC0,0,0,0,0,
0,0,1,0xC0,0,0,0,0,
0,0,1,0xC0,0,0,0,0,
0,0,1,0xC0,0,0,0,0,
0,0,1,0xC0,0,0,0,0,
0,0,1,0xC0,0,0,0,0,
0,0,1,0xC0,0,0,0,0,
0,0,1,0xC0,0,0,0,0
};

byte C6 = {
0,0,0,1,0xC0,0,0,0,
0,0,0,1,0xC0,0,0,0,
0,0,0,1,0xC0,0,0,0,
0,0,0,1,0xC0,0,0,0,
0,0,0,1,0xC0,0,0,0,
0,0,0,1,0xC0,0,0,0,
0,0,0,1,0xC0,0,0,0,
0,0,0,1,0xC0,0,0,0
};

byte C7 = {
0,0,0,0,1,0xC0,0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C0,0xC0,0xC0,0xC0,
0xC0,0xC0,0xC0,0xC0,1,1,1,1,
0xC0,1,1,0xC0,1,0xC0,0xC0,1,
0xC0,1,1,0xC0,1,0xC0,0xC0,1,
0xC0,0xC0,0xC0,0xC0,1,1,1,1
};

char spi_transfer(volatile char data)
{
SPDR = data; // Start the transmission
while (!(SPSR & (1<<SPIF))) // Wait the end of the transmission
{
};
}

/*
Write image to display.
/
void write_buffer(){
digitalWrite(CHIPSELECT,LOW); // enable
delay(5);
for(int i = 0; i < 64; i++){
spi_transfer(out_buffer
);*
}
digitalWrite(CHIPSELECT,HIGH); // disable device
delay(5);
}
void setup()
{

  • pinMode(switchPin, INPUT); // set the switch pin to be an input*
    byte clr;
    pinMode(DATAOUT,OUTPUT);
    pinMode(SPICLOCK,OUTPUT);
    pinMode(CHIPSELECT,OUTPUT);
    digitalWrite(CHIPSELECT,HIGH); //disable device
    SPCR = B01010001; //SPI Registers
    SPSR = SPSR & B11111110; //make sure the speed is 125KHz
    clr=SPSR;
    clr=SPDR;
    delay(10);
    }
    *void loop() { *

  • switchState = digitalRead(switchPin);*
    if (switchState == 1) {
    out_buffer = C2;
    write_buffer();
    delay(50);

  • out_buffer = C3;*
    write_buffer();
    delay(50);

  • out_buffer = C4;*
    write_buffer();
    delay(50);

  • out_buffer = C5;*
    write_buffer();
    delay(50);

  • out_buffer = C6;*
    write_buffer();
    delay(50);

  • out_buffer = C7;*
    write_buffer();
    delay(50);
    out_buffer = C8;
    write_buffer();
    delay(50);
    out_buffer = C9;
    write_buffer();
    delay(50);

  • out_buffer = C10;*
    write_buffer();
    delay(50);

  • }*

  • else {*

  • // if the switch is open:*

  • out_buffer = CHECKED1;*
    write_buffer();
    delay(100);
    out_buffer = CHECKED2;
    write_buffer();
    delay(100);

  • out_buffer = CHECKED3;*
    write_buffer();
    delay(100);

  • out_buffer = CHECKED4;*
    write_buffer();
    delay(100);

  • out_buffer = CHECKED5;*
    write_buffer();
    delay(100);

  • out_buffer = CHECKED6;*
    write_buffer();
    delay(100);

  • out_buffer = CHECKED7;*
    write_buffer();
    delay(100);

  • out_buffer = CHECKED8;*
    write_buffer();
    delay(100);

  • }*
    }

I think you are referring to switch 'bouncing'.

http://www.arduino.cc/en/Tutorial/Debounce

/me