SPI: Arduino and Sparkfun RGB Matrix Backpack

Hi everyone, just thought I’d share this with you:
I bought an RGB matrix & backpack from Sparkfun which acts as an SPI slave device. I wrote a chunk of arduino code that speaks to it the right way.

Here it is, so enjoy!

~Daniel~

// Simple program to test SPI 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);
}

nice

I added it to the Playground, here

D

I just bought the RG Matrix (http://www.sparkfun.com/commerce/product_info.php?products_id=759) and I'm trying out this code. For testing purposes I changed the spi_transfer to spi_transfer(1); which should make the entire matrix go red, but when I run the program I get random red dots flashing all over the place. Any ideas?

I've had the same issue with this - The RG Backpack works - and I get the quick test - but then it goes to random flashes of LEDs.

Is there a different way to int and reg the RG display over the RGB?

:slight_smile: i have two of these rgb back packsa and can get them to scan red to blue or any of the seven colours i choose but would like to know how to display characters e.g, the letter A.

Any help would be much appreciated :slight_smile:

Hi Just found this :

// 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 / DI
#define DATAIN 12//MISO / DO

int data =
{0,0,0,0,0,0,0,0,
0,0,1,1,0,1,1,0,
0,1,0,0,1,0,0,1,
0,1,0,0,0,0,0,1,
0,0,1,0,0,0,1,0,
0,0,0,1,0,1,0,0,
0,0,0,0,1,0,0,0,
0,0,0,0,0,0,0,0
}
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);
int index = 0;
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(data[index]);
index++;
// 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);
}

i copy it into my arduino but it comes up with :
error: expected ‘,’ or ‘;’ before ‘char’

Can some one help :slight_smile:

Thanks

Well, you could try sticking a ; before the char - specifically, after the int data[] = {....}

-j

yea that worked thanks alot :slight_smile:

Hello,

I have an arduino Duemilanove with atmega328 and two of the backkpacks from sparkfun. I started to play with it.
As cubtastic wrote, the piece of code in the Arduino playground is not working correctly as I get some random display.
I think this random display also changed the daisy chain config of my test backpack.

I modified the existing code of the test program and here is a piece of code working for me.

For info pin 12 is not used and pin 10 is to connect to cs on the backpack.

I’m french so sorry for the mistakes. And I’m not a great programmer so comments are welcome.

// 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

#define RED      0xE0 // For code readability.
#define GREEN      0x1C // Only 8 colors available
#define BLUE      0x07 // but variation possible with
#define ORANGE  0xFC // brightness (see Sparkfun doc).
#define MAGENTA      0xE3
#define TEAL      0x1F
#define WHITE      0xFF
#define BLACK      0x00

byte color_tst_tbl[] = {0xE0,0x1C,0x07,0xFC,0xE3,0x1F,0xFF,0xE0}; // Table of color codes, one color duplicated to get 8 entries for test purpose.

byte pattern[] = { // Test pattern to be displayed on the matrix, entries in binary for learning purpose.
B11111111,         // So you can see which led is on (1) or off (0=BLACK) on your pattern.
B00000000,         // Just change it to test your own patterns.
B11111111,         // We can also use hex notation: B11111111 is 0xFF in hexa
B00000000,
B11111111,
B00000000,
B10101010, 
B01010101  
};

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);
   int idx = 0;
   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++)
      { 
        if (bitRead(pattern[i],j) == 0) //bitRead funcion is used to get each 8 bit of the 8 bytes pattern table (64 bits in total).
          { spi_transfer(BLACK);}       // bit is 0 -> Transfer Black color.
        else
          { spi_transfer(color_tst_tbl[j]);} // bit is 1 -> Transfer a color choosen in the color test table.
        idx++;
      }                      
   }   // 64 bytes should have been transfered to the RGB matrix.
   digitalWrite(CHIPSELECT,HIGH); // disable the ChipSelect on the backpack
   // What you've send is displayed on the matrix.
   delayMicroseconds(500);
}

I also checked the backpack documentation for the daisy chain feature and amended the program to easily change their daisy chain config.
Each backpack must be configured individually (not chained to others) !
I encourage you to check the backpack doc, there is a pdf at Sparkfun (see link on the playground).

// Simple program to configure daisy chain for the Sparkfun RGB Matrix using the Arduino
// Each backpack must be configured separately (not physically chained) !! (See Sparkfun backpack doc)
// 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 2 bytes: char % (0x25 in hex) and a configuration number: 1 to 8 (1 means standalone backpack, 2 means daisy chain of two backpacks)
//    Plesae change it accordingly in this program.
// 4) De-activate ChipSelect;
// 5) Wait 500microseconds

#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);
   int idx = 0;   
   digitalWrite(CHIPSELECT,LOW); // enable the ChipSelect on the backpack
   delayMicroseconds(500);
   
   spi_transfer(0x25); // transfer the escape code %
   spi_transfer(1); // transfer the number of matrix in the daisy chaine (1 for standalone, 2 to 8 for a daisy chain)

   digitalWrite(CHIPSELECT,HIGH); // disable the ChipSelect on the backpack
   delayMicroseconds(500);
}

Has anyone tried to bootload the onboard ATmega168 with the Arduino bootloader to run a program standalone?

(As the original firmware is not available, I don't suggest to do it, but wanted to know if it's possible or already done...)

@tep: Hello tep, perhaps you should post in the hardware/development section of this forum. I cannot reply to your question as I'm not a "PCB maker". Perhaps be more precise in describing what you want to do too.

Concerning my previous post: Seems Sparkfun modified its RGB bakpack and the 2 I bought are version 2(?). They have two 6pin connectors. (SPI input and SPI output). [See the product comments at Sparkfun website]

I managed to drive one standalone with my Arduino Duemilanove but did not manage to make the daisy chained feature to work correctly.

Following the procedure in the dcumentation don't seem to work. I found a post saying you have to send the escape commmand before every 64 byte frame when using daisy chain and tested it. It was better but one frame (last of the chain) is not correctly transmitted. (there is a shift and some noise too) I will try to contact Sparkfun support.

I saw several backpacks can be controlled separately by using a separate CS wire for each. Will try to test it.

@LaurentR: No problem, that was only to know if somebody did this!
Actually, looking at the schematic, nothing new, it should be fairly simple!
That should allow some simple electret based VU-meter or such.
Hm, have to think over it when I finish my current projects!

Hello again, Another addition concerning coding for 8x8 displays. Richard Prinz wrote a cool program to rapidly get font description in your code and design new symbols. This program is intended to people playing with displays on embedded systems. With this program called "8x8 Pixel ROM Font Editor", you can export the font in .asm text file and get an 8 bytes table description for each caracter. (Note the program comes with a library of classic fonts).

Here is the link (with the permission of the author), the program licence type is Creative Commons (see website).

http://www.min.at/prinz/software/pixelfont/

Here is an example of an 8 bytes description for one character:

byte happy_face[]={0x00, 0x66, 0x66, 0x00, 0x00, 0x42, 0x3C, 0x00};

Don't hesitate to post on the author site the new fonts or symbol libraries you create !

Hi,

I tried to chain four of the 8x8 LED Matrix with backpacks. After configuring each of them (not even sure if I did right), does anyone have some simple example code how to send data to four of them?

Thanks!

Elim

This what I did for configuration for each of the backpack, please point out if there’s anything wrong. Becuase after upload the code from arduino to the backpack, nothing happened. (is this correct?)

I copy the code from previous post

// Simple program to configure daisy chain for the Sparkfun RGB Matrix using the Arduino
// Each backpack must be configured separately (not physically chained) !! (See Sparkfun backpack doc)
// 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 2 bytes: char % (0x25 in hex) and a configuration number: 1 to 8 (1 means standalone backpack, 2 means daisy chain of two backpacks)
// Plesae change it accordingly in this program.
// 4) De-activate ChipSelect;
// 5) Wait 500microseconds

#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);
int idx = 0;
digitalWrite(CHIPSELECT,LOW); // enable the ChipSelect on the backpack
delayMicroseconds(500);

spi_transfer(0x25); // transfer the escape code %
spi_transfer(1); // transfer the number of matrix in the daisy chaine (1 for standalone, 2 to 8 for a daisy chain)

digitalWrite(CHIPSELECT,HIGH); // disable the ChipSelect on the backpack
delayMicroseconds(500);
}

And chenged the number 1 to number 4 for all of the LED because I want to chain 4 LED backpacks:
spi_transfer(1);

How do I know if I configure successful or not?

Thanks!

Elim

Hello Elim,

This code is only used to configure the backpack. Only one backpack at a time should be connected for the configuration code to be send correctly.

If I understand what is stated in the documentation, for 4 backpacks daisy chained, you have to send the escape code '%4' to your 4 backpacks but this has to be done separately for each one.

Configuration check : If you power up your backpack, you'll see six led lighted (2red,2green and 2 blue) = test pattern. I noticed taht if the backpack corectly received the '%4' -> it should display the test pattern with shifted by 3. (3 leds off and then the pattern).

Displaying on the chained backpacks : From my experience, I did not manage to display correclty data in a daisy chain configuration even with my backpacks correctly configured. If you get some more info on this, it wil help.

From what I understood from the documentation you have to :

Activate CS wait 500 ms transfert frame 1 (64 bytes) -> will be displayed on the last backpack wait 500 ms de-activate CS wait 10 ms actvate CS wait 500 ms transfer frame 2 (64 bytes) -> will be displayed on bacpack N°3 wait 500 ms de-activate CS wait 10 ms actvate CS wait 500 ms transfer frame 3 (64 bytes) -> will be displayed on bacpack N°2 wait 500 ms de-activate CS wait 10 ms actvate CS wait 500 ms transfer frame 4 (64 bytes) -> will be displayed on bacpack N°1 wait 500 ms de-activate CS

Note the documentation says that all displays show data only when all frames (4 in your case) are transmitted.

But sorry to say this did not work for me: I found a post saying you had to transmit the escape code ('%4' before every frame, respecting timing stated in the doc (500 ms before and after data and 10 ms between CS pulses). -> Quite works but shift and noise on the last frame. And this trick is not documented.

For now, I decided not to use the daisy chain feature. I use parallel cabling for clock, data, power and use a separate CS PIN for each backpack -> so my backpacks are rotated and I can only assemble them in one line as I can't plug them.

If you want more info, just ask.

hi LaurentR,

Thanks for your reply.

I think I configured them, although sometimes the 2 blue, 2 red and 2 green come from different locations.

The part I'm not sure I understand is:

Activate CS wait 500 ms transfert frame 1 (64 bytes) -> will be displayed on the last backpack wait 500 ms de-activate CS wait 10 ms actvate CS wait 500 ms transfer frame 2 (64 bytes) -> will be displayed on bacpack N°3 wait 500 ms de-activate CS wait 10 ms actvate CS wait 500 ms transfer frame 3 (64 bytes) -> will be displayed on bacpack N°2 wait 500 ms de-activate CS wait 10 ms actvate CS wait 500 ms transfer frame 4 (64 bytes) -> will be displayed on bacpack N°1 wait 500 ms de-activate CS

where do I do those parts? in code? How it would look like in an Arduino code? Do I need to plug or unplug anthing?

Thanks!!

E

Hello, I don't have time to reply detailled now as I'm going to work and in weekend by my parents (no Internet connection there).

If the config part is ok, you can daisy chain them. You have to write a different Arduino program (sketch ) to do the display. The other example code in my first post displays a test pattern on one display (you have to understand how it work and try to write a piece of code for displaying on 4 backpacks).

Did you already programmed with arduino platform and programming language like C ?

See you next week.

Ah I forgot the part you don't understand. It is not arduino code, just the way you have to program it. for example : to activate CS (chipselect) you have to code :

digitalWrite(CHIPSELECT,LOW);

Hello LaurentR,

I just started working with Sparkfun RGB LED Matrix… thanks to your code.

Can you (or anyone) have a look at the following code:

// 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

#define RED      0xE0 // For code readability.
#define GREEN      0x1C // Only 8 colors available
#define BLUE      0x07 // but variation possible with
#define ORANGE  0xFC // brightness (see Sparkfun doc).
#define MAGENTA      0xE3
#define TEAL      0x1F
#define WHITE      0xFF
#define BLACK      0x00

byte color_tst_tbl[] = {
MAGENTA,MAGENTA,ORANGE,ORANGE,ORANGE,WHITE,WHITE,WHITE,
MAGENTA,MAGENTA,MAGENTA,ORANGE,ORANGE,ORANGE,WHITE,WHITE,
RED,MAGENTA,MAGENTA,MAGENTA,ORANGE,ORANGE,ORANGE,WHITE,
RED,RED,MAGENTA,MAGENTA,ORANGE,ORANGE,ORANGE,ORANGE,
RED,RED,MAGENTA,MAGENTA,MAGENTA,MAGENTA,ORANGE,ORANGE,
RED,RED,MAGENTA,MAGENTA,MAGENTA,MAGENTA,MAGENTA,ORANGE,
RED,RED,RED,RED,RED,MAGENTA,MAGENTA,MAGENTA,
RED,RED,RED,RED,RED,RED,MAGENTA,MAGENTA,
}; // Table of color codes, one color duplicated to get 8 entries for test purpose.

byte pattern[] = {
0x18, 0x3C, 0x66, 0x66, 0x7E, 0x66, 0x66, 0x00, //0:A
0x7C, 0x66, 0x66, 0x7C, 0x66, 0x66, 0x7C, 0x00, //1:B
0x3C, 0x66, 0xC0, 0xC0, 0xC0, 0x66, 0x3C, 0x00, //2:C
0x78, 0x6C, 0x66, 0x66, 0x66, 0x6C, 0x78, 0x00, //3:D
0x7E, 0x60, 0x60, 0x78, 0x60, 0x60, 0x7E, 0x00, //4:E
0x7E, 0x60, 0x60, 0x78, 0x60, 0x60, 0x60, 0x00, //5:F
0x3C, 0x66, 0xC0, 0xC0, 0xCE, 0x66, 0x3E, 0x00, //6:G
0x66, 0x66, 0x66, 0x7E, 0x66, 0x66, 0x66, 0x00, //7:H
0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, //8:I
0x06, 0x06, 0x06, 0x06, 0x66, 0x66, 0x3C, 0x00, //9:J
0x66, 0x66, 0x6C, 0x78, 0x6C, 0x66, 0x66, 0x00, //10:K
0x60, 0x60, 0x60, 0x60, 0x60, 0x60, 0x7E, 0x00, //11:L
0xC6, 0xEE, 0xFE, 0xFE, 0xD6, 0xC6, 0xC6, 0x00, //12:M
0xC6, 0xE6, 0xF6, 0xDE, 0xCE, 0xC6, 0xC6, 0x00, //13:N
0x3C, 0x66, 0x66, 0x66, 0x66, 0x66, 0x3C, 0x00, //14:O
0x7C, 0x66, 0x66, 0x7C, 0x60, 0x60, 0x60, 0x00, //15:P
0x3C, 0x66, 0x66, 0x66, 0x6E, 0x3C, 0x0E, 0x00, //16:Q
0x7C, 0x66, 0x66, 0x7C, 0x6C, 0x66, 0x66, 0x00, //17:R
0x3C, 0x66, 0x70, 0x38, 0x0E, 0x66, 0x3C, 0x00, //18:S
0x7E, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x00, //19:T
0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x3E, 0x00, //20:U
0x66, 0x66, 0x66, 0x66, 0x66, 0x3C, 0x18, 0x00, //21:V
0xC6, 0xC6, 0xC6, 0xD6, 0xFE, 0xEE, 0xC6, 0x00, //22:W
0x66, 0x66, 0x3C, 0x18, 0x3C, 0x66, 0x66, 0x00, //23:X
0x66, 0x66, 0x66, 0x3C, 0x18, 0x18, 0x18, 0x00, //24:Y
0xFE, 0x06, 0x0C, 0x18, 0x30, 0x60, 0xFE, 0x00, //25:Z
};

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()            
{

//int letter = 8*4;
for (int n=0;n<26;n++)
{
   int index = 0;
   int letter = 8*n;
   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++)
      {
        if (bitRead(pattern[letter+i],j) == 0) //bitRead funcion is used to get each 8 bit of the 8 bytes pattern table (64 bits in total).
          { spi_transfer(BLACK);}       // bit is 0 -> Transfer Black color.
        else
          { spi_transfer(color_tst_tbl[index]);} // bit is 1 -> Transfer a color choosen in the color test table.
        index++;
      }                      
   }   // 64 bytes should have been transfered to the RGB matrix.
   digitalWrite(CHIPSELECT,HIGH); // disable the ChipSelect on the backpack
   // What you've send is displayed on the matrix.
   delayMicroseconds(500);
   delay(10);
}
}

I cannot figure out why the letters show at random.
Is it a timing issue?

Thank you in advance…