Creating LED animation with 8x8 RGBMatrix with Backpack

Hi, my programming knowledge is still growing so please go easy on me. And I am not looking for a free answer I want to learn.

I am trying to create an animation on an 8x8 RGB Matrix from Sparkfun:

I am not having the best of luck, I have read a number of sample codes and tutorials on the device.

the RGBMatrixdemo.pde code that I found does not seem to run correctly and is a bit corrupt i think...

I have been pulling code and mixing code to try and get some where, but Not having the best of luck.

If someone can point me in the right direction on to how i can create a 10 frame animation, for each frame pick which LED in the matrix lights up and what colour it will be.

A few codes I have looked at.

// Sample Arduino Duemilanove interface code for Sparkfun's
// LED Matrix - Serial Interface - Red/Green/Blue
// http://www.sparkfun.com/commerce/product_info.php?products_id=760
//
// Written by:
// Fabio Pugliese Ornellas
// fabio.ornellas@gmail.com

// Pin definitions for Duemilanove.
// If you have a different board, check its datasheet SPI
// documentation for the corret pins.
#define PIN_SCK  13
#define PIN_MISO 12
#define	PIN_MOSI 11
#define PIN_SS   10

// Send a single byte via SPI, taken from Atmel's datasheet example.
void sendChar(char cData){
  SPDR = cData;
  while(!(SPSR&(1<<SPIF)));
}

// Send a full frame to the LED matrix
void sendFrame(char *frame) {
  // Assert SS
  digitalWrite(PIN_SS, LOW);
  // delay as the LED Matrix datasheet's recommends
  delayMicroseconds(500);
  // send the full buffer
  for(int i=0;i<64;i++) {
    char c;
    c=*(frame+i);
    // This is needed because sending a '%' will reconfigure the
    // board for daisy chain operation
    if('%'==c)
      sendChar('%'-1); // similar color
    else
      sendChar(c);
  }
  // de-assert SS
  digitalWrite(PIN_SS, HIGH);
  // The LED Matrix datasheet's recommends this delay on daisy
  // chain configurations
  //delayMicroseconds(10);
}

void setup(){
  // SPI communication setup. Please refer to Atmel's datasheets
  // to understand all this. Basically it sets up the Arduino as
  // master and configure the appropriate clock speed.

  // Configuration register
  SPCR=(1<<SPE)|(1<<MSTR)|(1<<SPR1)|(1<<SPR0);
  // Status register
  SPSR = SPSR & B11111110;

  // setup pins
  pinMode(PIN_SCK, OUTPUT);
  digitalWrite(PIN_SCK, LOW); // ensure clock low
  pinMode(PIN_MOSI, OUTPUT);
  pinMode(PIN_SS, OUTPUT);
  digitalWrite(PIN_SS, HIGH); // de-assert SS
  delayMicroseconds(500); // delay as the LED Matrix datasheet's recommends

  // This section reconfigure the board to no daisy chain
  // operation.
  // This can be confirmed by an RRGGBB pattern beginning at a
  // corner, with no black LEDs before the first LED, when the
  // matrix is powered on.
  // Warning: this will take effect only after first run, power
  // off and power on!
  digitalWrite(PIN_SS, LOW);
  delayMicroseconds(500);
  sendChar('%');
  sendChar(1);
  digitalWrite(PIN_SS, HIGH);
  delayMicroseconds(10);
}

void loop(){
  char frameBuffer[64];

  // Cycle through each possible color
  for(int color=0;color<=255;color++) {
    // And populate each position of the buffer with one color
    for(int j=0;j<64;j++) {
      frameBuffer[j]=j+color;
    }
    // Send the frame to the LED Matrix
    sendFrame(frameBuffer);
    // Colors are made by blinking the LEDs very fast.
    // Decreasing this delay too much (or removing it) may lead
    // to corrupted images.
    delay(200);
  }
}

THanks for any help.

If you have to turn the display off and on after sending this sequence in setup(), how do you arrange that? I think that once the board is configured for no-daisychain (which I think is the factory default) you should probably NOT send this sequence again.

  // This section reconfigure the board to no daisy chain
  // operation.
  // This can be confirmed by an RRGGBB pattern beginning at a
  // corner, with no black LEDs before the first LED, when the
  // matrix is powered on.
  // Warning: this will take effect only after first run, power
  // off and power on!
  digitalWrite(PIN_SS, LOW);
  delayMicroseconds(500);
  sendChar('%');
  sendChar(1);
  digitalWrite(PIN_SS, HIGH);
  delayMicroseconds(10);

Hello there, did you ever get this working? all the threads on RGB Matrices seem to be unfinished.

Thanks

Ryk

You can take a look at the code i did use.

// Sample Arduino Duemilanove interface code for Sparkfun's
// LED Matrix - Serial Interface - Red/Green/Blue
// http://www.sparkfun.com/commerce/product_info.php?products_id=760
//
// Written by:
// Fabio Pugliese Ornellas
// fabio.ornellas@gmail.com

// Pin definitions for Duemilanove.
// If you have a different board, check its datasheet SPI
// documentation for the corret pins.
#define PIN_SCK  13
#define PIN_MISO 12
#define PIN_MOSI 11
#define PIN_SS   10
int gridLoc;
int sensorPin = 0;   
int sensorValue = 0;

// Send a single byte via SPI, taken from Atmel's datasheet example.
void sendChar(char cData){
  SPDR = cData;
  while(!(SPSR&(1<<SPIF)));
}

// Send a full frame to the LED matrix
void sendFrame(char *frame) {
  // Assert SS
  digitalWrite(PIN_SS, LOW);
  // delay as the LED Matrix datasheet's recommends
  delayMicroseconds(500);
  // send the full buffer
  for(int i=0;i<64;i++) {
    char c;
    c=*(frame+i);
    // This is needed because sending a '%' will reconfigure the
    // board for daisy chain operation
    if('%'==c)
      sendChar('%'-1); // similar color
    else
      sendChar(c);
  }
  // de-assert SS
  digitalWrite(PIN_SS, HIGH);
  // The LED Matrix datasheet's recommends this delay on daisy
  // chain configurations
  //delayMicroseconds(10);
}

void setup(){
  // SPI communication setup. Please refer to Atmel's datasheets
  // to understand all this. Basically it sets up the Arduino as
  // master and configure the appropriate clock speed.

  // Configuration register
  SPCR=(1<<SPE)|(1<<MSTR)|(1<<SPR1)|(1<<SPR0);
  // Status register
  SPSR = SPSR & B11111110;

  // setup pins
  pinMode(PIN_SCK, OUTPUT);
  digitalWrite(PIN_SCK, LOW); // ensure clock low
  pinMode(PIN_MOSI, OUTPUT);
  pinMode(PIN_SS, OUTPUT);
  digitalWrite(PIN_SS, HIGH); // de-assert SS
  delayMicroseconds(500); // delay as the LED Matrix datasheet's recommends

  // This section reconfigure the board to no daisy chain
  // operation.
  // This can be confirmed by an RRGGBB pattern beginning at a
  // corner, with no black LEDs before the first LED, when the
  // matrix is powered on.
  // Warning: this will take effect only after first run, power
  // off and power on!
  digitalWrite(PIN_SS, LOW);
  delayMicroseconds(500);
  sendChar('%');
  sendChar(1);
  digitalWrite(PIN_SS, HIGH);
  delayMicroseconds(10);
  Serial.begin(9600); 
}

void loop(){


 // read the value from the sensor:
 int sensorValue = analogRead(sensorPin);

Serial.println(sensorValue);  
  
if (sensorValue < 150)
{   // if there is no wind
 // print a white bar and let it propogate
  goto noWave;}
else(sensorValue > 150);
{ // if there is wind then 
  // print the wave and let it propogate
  goto wave;}

noWave:
{
char frameBuffer[64];


  // Cycle through each possible color
 // for(int color=0;color<=255;color++) {
    // And populate each position of the buffer with one color
/*    for(int j=0;j<64;j++) {
    //  frameBuffer[j]=j+color;
    frameBuffer[j]=255;
    }*/
    // Colors are made by blinking the LEDs very fast.
    // Decreasing this delay too much (or removing it) may lead
    // to corrupted images.  
   
   // move forward one frame 
    for(int i=0;i<64;i++) {
      frameBuffer[64-i]=frameBuffer[56-i];
      }
   //clear the first frame
   for(int i=0;i<8;i++) {
      frameBuffer[i]=255;
      }
    // Send the frame to the LED Matrix
    sendFrame(frameBuffer);
    delay(200);
    
    return;
 //  }
}
 wave:
  { 
  char frameBuffer[64];
  //draw steps of the animation
  frameBuffer[3]=0;
  frameBuffer[4]=0;
  for (gridLoc = 0; gridLoc<4; gridLoc++){
      frameBuffer[gridLoc+4]=0;
      frameBuffer[3-gridLoc]=0;
 //move forward one frame
    for(int i=0;i<64;i++) {
      frameBuffer[64-i]=frameBuffer[56-i];
      }
 //erase the first frame
      for(int i=0;i<8;i++) {
      frameBuffer[i]=255;
      }
    sendFrame(frameBuffer);
    delay(200);
    
   
}
}

}

also i made this Youtube video, its much smoother now.

Cheers dude, thanks for getting back to me, i'll try the code and hope that it isn't my backpack that is broken.

Yeah i had some issues working with some of the libraries for RBG matrix and the backpack.

even the example code would have its own issues.