RGB Matrix and backpack code help

All,

I’m pretty new to this, and I’m trying to find code examples to get my Arduino and the Sparkfun RGB Matrix with Backpack up and doing something interesting.

My eventual goal is to have a single matrix scroll messages across. I have searched around and found lot’s of YouTube videos with groovy things going on, but I can’t seem to find the code. Even the example code from the sparkfun product page isn’t really working for some reason. I get some bars, but not all the colors.

I’m not much of a programmer, more of a solder and communications protocol kinda’ guy, so I need something to take apart and see how it works.

Any help with code example, wiring advice, or links to “a complete idiots guide to the RGB LED Matrix and Backpack from Sparkfun” would be greatly appreciated.

Tom,

I have just bough some of these and am waiting for them to arrive. I found this site with test code to produce an image on the RGB Matrix w/backpack.

http://tokage.cafe24.com/ww/

(Ignore the bits in Japanese at the top)

Hope this helps… Nick

You can find some sample code here:

http://www.arduino.cc/playground/Code/RGBBackpack

Note that you can’t easily change the SPI pins to whatever set on the Arduino. SPI is only working on this set of pins from what I know.

#define CHIPSELECT 10//ss - CS on Backpack

#define SPICLOCK 13//sck - SCK on Backpack

#define DATAOUT 11//MOSI - DI on Backpack

#define DATAIN 12//MISO - DO on Backpack

I hope this helps.

/Camille

If it’s any help my 4 displays work fine using the pins Camille suggests. I have 4 CS pins (7-10).

Nick

I just got two of these and I’m trying to hook them up but I’m a little confused by the labels on the backpack.

The labels on the backpack and my connections on an Arduino diecimilanove are: (from top to bottom)

GND → GND

MOSI → 11

CS → 10

SCLK → 13

VCC → ?

VCC → 5V

This doesn’t seem to work if I connect the missing vcc to pin 12 doesn’t seem to help either.

all suggestions much appreciated

Hey Gonzillaaaaaaaa,

Looks like they redesigned the backpack since I bought it so you can plug 'em together.

You look ok with what you have. I guess you are using the test code like here: http://www.arduino.cc/cgi-bin/yabb2/YaB … 1236098804

You only need one VCC - i.e. you have 5 connections in total, GND, 5V and 3 data lines…

GND → GND

VCC → 5V

MOSI → 11

CS → 10

SCLK → 13

However one thing to note though is that code I linked to will only work with one matrix as it is - it only puts out enough bits for one. I’d try with just one plugged in to start.

To add a second you will need to modify the code to do that loop again and put out another set of data - the data gets pushed down the chain, from one matrix to the next - (at least I am guessing that’s how sparkfun have wired it)

Nick

That’s interesting is exactly what I had but no much luck. I’m using one display only to start with. How come the datain/miso line is not used?

in terms of code I’m using the example on the arduino playground you point to, also trying with the example on the sparkfun product page. With the Arduino code it doesn’t cycle through colours (it stays blue) with the sparkfun code only one row is lit up with different colours per column.

any ideas?

Data in is used to send data back to the arduino. We are just sending data out to the rgb modules and dont need to return anything so it is not used.

It sounds like you are all connected ok - that is what the sparkfun code does - show one colour per colum (one of the colors being black / off)

Looks like all you need to do is connect the other matrix and start experimenting with the code now!

ok after some time tinkering I am trying to put together a library to display graphics and text. I have the basic code to display graphics, I have methods to display rows, columns or target specfic leds etc.

I have started looking at displaying characters and scroll them but cannot build a functional sketch form the examples I’ve found around.

My main problem is how to translate the values from an ASCII table (hex) into a 8x8 matrix and the push that onto a queue for display.

The font is store in PROGMEM:

unsigned char ASCII_Char[52][8] PROGMEM = {
	{	0x0,0x44,0x44,0x7C,0x44,0x44,0x28,0x10},//A
	{	0x0,0x3C,0x44,0x44,0x3C,0x44,0x44,0x3C},//B
	{	0x0,0x38,0x44,0x4,0x4,0x4,0x44,0x38},//C

Etc

I can read from PROGMEM (developed from seedstudio’s examples on their Matrix, they include lower-case characters :slight_smile: ):

void loadChar(char character) {

	unsigned char ASCII;
	unsigned char tempword, row, AS;

	ASCII = character;

	if ((ASCII > 64) && (ASCII < 91))
		AS = ASCII - 65;
	else if ((ASCII > 96) && (ASCII < 123))
		AS = ASCII - 71;
	else if ((ASCII >= '0') && (ASCII <= '9'))
		AS = ASCII - 48;

	for (row = 0; row < 8; row++) {
		if ((ASCII >= '0') && (ASCII <= '9'))
			tempword = pgm_read_byte(&(ASCII_Number[AS][row]));
		else
			tempword = pgm_read_byte(&(ASCII_Char[AS][row]));

		
	}
}

Up to this point everything seems to be working, but then, how would you go about aggregating & converting tempword which is in Hex into the 8x8 matrix (array) I need to push into the queue for display?

All pointers much appreciated.

G.

ok I’ve started to figure it out I can now display static characters (the power of public monologue :slight_smile: ) I need to work out how to buffer charters onto display… all suggestions welcome.

void displayChar(char character) {

	clearMatrix();

	unsigned char ASCII;
	unsigned char tempword, AS, x, y;

	ASCII = character;

	if ((ASCII > 64) && (ASCII < 91))
		AS = ASCII - 65;
	else if ((ASCII > 96) && (ASCII < 123))
		AS = ASCII - 71;
	else if ((ASCII >= '0') && (ASCII <= '9'))
		AS = ASCII - 48;

	for (x = 0; x < 8; x++) {
		if ((ASCII >= '0') && (ASCII <= '9'))
			tempword = pgm_read_byte(&(ASCII_Number[AS][x]));
		else
			tempword = pgm_read_byte(&(ASCII_Char[AS][x]));

		for (y = 0; y < 7; ++y) {
			if (tempword & (1 << y)) {
				color_buffer[y + (x * 8)] = RED;
			} else {
				color_buffer[y + (x * 8)] = 0;
			}
			Serial.println(y + (x * 8));
		}
		updateMatrix();
	}
}

Interesting - I have a slightly different approach.

I have designed my font using bytes to save memory. Each bit in a byte is represents an LED being on or off. My characters are 5x7, so number 0 is stored as:

B01111100,

B10001010,

B10010010,

B10100010,

B01111100,

You can see the 0 if you turn the above 90 degrees to the right and imagine the 1’s as LEDs that are illuminated.

All my characters are in an array in progmem in a setup sketch. In this sketch I use the EEPROM routine on the Arduino site to write them to EEPROM memory. I then upload my main sketch instead which reads them from EEPROM thus saving precious Progmem for other uses other than storing characters.

In the mains sketch I then have a look up table of where each character is in EEPROM consisting of the start byte and the number of bytes that make it up. E.g. for “0” then (assuming 0 is the first character in EEPROM mem) read start is set to byte 0 with a length of 5 bytes. For case “1” read start is set to byte 6 and length 5 bytes. A long switch statement has all these start and lengthes in for each character. E.g. case “0” start = 0; len = 5; etc…

When a character is selected via the switch, the relevant bytes are read from EEPROM into an array:

 //read char from eeprom into array called 'data' where x = start byte
 //and len = len of bytes to read

  byte data[8]; 
  for (byte x = 0; x < len; x++){
    data[x] = EEPROM.read(x+start);
  }

Then using the bitmask technique also in the examples the 8 bits in each byte are read out one by one and plotted onto the main display. If it reads a 1 it sets the LED to on. Code below has been simplified but should give you an idea…

  byte mask = 1; //bitmask

  //for each byte (y) in char where len = num bytes making up char
  for (byte y = 0; y < len ; y++) {       
    
    //x counts which bit we are reading in the byte 
    byte x = 7; 

    //iterate through bit mask
    for (mask = 00000001; mask>0; mask <<= 1) { 

      if (data[y] & mask){ // if bitwise AND resolves to true plot point
    
            //plot point on screen with whichever colour 
            display[x][y] = led_colour;
          
      }  
      //next bit
      x--;
    }

To scroll I repeat the above for each character in the text string - changing the start plot points for each one so they aren’t printed on top of each other and up until they exceed the width of the screen (no point drawing stuff outside the display). Then I pause for a few hundred milliseconds, clear the screen, and repeat the above but moving the start point of each character by one pixel

Hope this is of some help!!

[/code]