Go Down

Topic: Help with Sparkfun RGB Matrix (Read 1 time) previous topic - next topic

xlivewire7x

Hey everyone :) I just received an RGB matrix with the SPI backpack from Sparkfun and I need help figuring out how to use it. Currently, I have it hooked up to my Arduino Duemilanove as follows:
SPI Input:
MOSI -> Pin 11
CS -> Pin 10
SCLK -> Pin 13

SPI Output:
MISO -> Pin 12
Gound -> Ground

I ran the test code located in the Arduino playground and every time, I just get some random combination of blue, green, and red lights. To my understanding, that's not whats supposed to happen so correct me if I'm wrong. I've programmed with the Arduino before but just basic things (flashing lights, countdown timers, and motion sensors) so I'm really new to this matrix. If anybody could write up a basic tutorial or point me to one, I would really appreciate it.
(Not sure if this is in the right area so sorry if its not)

halley

Did it come with any datasheets?  The stock datasheet on their site suggests you really need a bit of decoupling for the power to the board (since current draw will change by quite a bit as you change the lights).  It doesn't explicitly say if the SPI lines need pullups, but look for other SPI typical applications to see if that's required.

xlivewire7x

#2
Feb 14, 2009, 11:25 pm Last Edit: Feb 14, 2009, 11:25 pm by xlivewire7x Reason: 1
It turns out that the backpack that is displayed on Sparkfun's webpage and datasheet does not match mine. The one that I have has SPI input on one side and SPI output on the other side. All pins are the same on each side (GND, MOSI, CS, SCLK, VCC, VCC) except for MISO instead of MOSI on the output side. Now, if I were to use a resistor, which pin would I hook it up to? I have looked in SOOOO many places and can't find any help. Let me know if you need any pics, would be glad to post some.
Oh, and no, it didn't come with any datasheets strangely.

AZRobbo

I have the same modules as you - they are a new V2 module and have new controller code on the controller (supports up to 196 colors)!

You still communicate with the backpack the same way via SPI, but now the color is controlled via bit encoding (3x3x2).  The top three bits control red, the next three control green, and the bottom two control blue.  

It's much more powerful, the only downside of this is virtually every sample program that you'll find is not written for this new firmware.

See the post near the end of this thread by CTaylor from Sparkfun:  http://www.sparkfun.com/commerce/tutorial_info.php?tutorials_id=91


xlivewire7x

#4
Feb 15, 2009, 12:02 am Last Edit: Feb 15, 2009, 12:25 am by xlivewire7x Reason: 1
Thank you so much! That makes sense now. I was wondering why my boards was showing different shades of colors and on the data sheets it said that there were only 7 colors. Do you have a sample piece of code that I could look at? Also, that piece of code that CTaylor posted, is that supposed to work for my version of the matrix? I tried pasting the code into the Arduino window and it gives me errors about variables not being declared in certain scopes.

AZRobbo

#5
Feb 15, 2009, 12:39 am Last Edit: Feb 15, 2009, 12:59 am by 33Warlord Reason: 1
The code from that thread is the new firmware that's actually running on the backpack, so you don't need to run it on the Arduino.

For testing you can start with any of the samples for the old version of this board, as the SPI communication stuff is still the same.  You just need to create your own subroutine for setting the colors.  To start, you might want to set the whole board to the same color using a binary number (ex: 0b11100000 is Red) to get an understanding of what bits control what colors.

Unfortunately, I haven't had a chance to do anything with mine yet, or I'd share my code with you.

I love SparkFun, but it seems like their products are coming out before the documentation more and more often.

xlivewire7x

Alright, thanks a lot for the help, gonna give your advice a shot. If you do write any basic code for it, I'd love to see it so feel free to PM me.

xlivewire7x

#7
Feb 15, 2009, 03:02 am Last Edit: Feb 15, 2009, 03:04 am by xlivewire7x Reason: 1
Okay, I've been able to make the matrix go completely red, completely green, and completely blue. The problem with blue and green is that the LED's flash constantly, but don't do that when the LED's are red. Also, how would I go about making arrays for the matrix to create images? Would I just do something like:
int data[] = {
0b11100000,0b00011100,0b00000011,
... etc etc
}
Or is there an easier way to do this?

AZRobbo

#8
Feb 15, 2009, 04:37 am Last Edit: Feb 15, 2009, 04:51 am by 33Warlord Reason: 1
I just noticed this - disconnect ALL the wires from the SPI output on the LED Matrix!  (that may be causing all of your problems).  You are only supposed to use those if you're piggyback other LED matrixes.

Try this sample - it is from somewhere in the forums, but I cannot find the original.  I apologize to the original thread author for re-posting their work.

Also, you do not need to state the color number in binary, every time.  I suggested that you test with it until you understood which bits where controlling which color - but stating the same value in hex is usually more common.  

The program below draws a heart on the LED Matrix.  Note that it specifies a 1 for the color (blue), and that each 1 is a BYTE not a bit.  SO when you setup a matrix to display a picture/letter in this manner, you are taking up 64 bytes of memory.  This is not ideal if you wanted to store a large number of images (say the entire alphabet).

I'm working on making some code to define some standard colors, and look into storing alphabet characters in bitfields, that can later be extracted and sent as bytes before transfer.

Anyway here's the program - it should work fine on your backpack.  If it doesn't work then re-check your wiring, power and ground lines.  Note - there is no wire for Pin12 and the backpack doesn't use/need it.

(Sorry about the long post - the new 'copy for forum' tool in IDE 13 doesn't work with the code notation.)

Quote

// 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++;                  
  }
  digitalWrite(CHIPSELECT,HIGH); // disable the ChipSelect on the backpack
  delayMicroseconds(500);
}

xlivewire7x

Okay, the code that you gave me works great! The only thing is is that when I go to change the background color around the heart (change the 0's to 100's) the colors start to change sporadically. Do I need a resistor to fix this or is this just part of the issue that this code doesn't work for this matrix?

AZRobbo

Quote
The only thing is is that when I go to change the background color around the heart (change the 0's to 100's) the colors start to change sporadically.


This should not be happening, so check for typos in your code.   If that isn't it, re-check your wiring.  How are you powering the LCD module?  Make sure its connected directly to a 5V source and not an Arduino output.  Do you have both Vcc lines connected to 5V?   (Perhaps turning on more LEDs is consuming more power than your source can provide.)

The only thing that has changed with this version of the LED Matrix is what byte you send it for what color.  All of the other communication code is exactly the same.  

When I change the 0's in the data matrix to 100 (as shown below), the heart displays just fine.  However, instead of drawing a blue heart on a black background, its now a blue heart on a redish-orange background.

This code reflects the changes that I made to the code that was originally posted above:
Code: [Select]
int data[] =
{100,100,100,100,100,100,100,100,
100,100,1,1,100,1,1,100,
100,1,100,100,1,100,100,1,
100,1,100,100,100,100,100,1,
100,100,1,100,100,100,1,100,
100,100,100,1,100,1,100,100,
100,100,100,100,1,100,100,100,
100,100,100,100,100,100,100,100};

xlivewire7x

Okay, now I feel like an idiot. I didn't even have the VCC lines attached to a power source at all :D What's the problem with having the VCC connected to the Arduino's 5v? I tried using that along with your code and it works like a charm. I would use a different supply but all I have are 9volt batteries.

AZRobbo

#12
Feb 16, 2009, 01:52 am Last Edit: Feb 16, 2009, 01:59 am by 33Warlord Reason: 1
New Update - Fix to SPI Clock Rate

I just discovered that the SPI rate was setup too fast in the sample code i was using.  Try changing this line in setup:

Code: [Select]
SPCR = B01010011;             //SPI Registers

The (incorrect) code was working fine for me originally, but as I was trying to add more modules I started to have problems.

And to answer your question above:
Quote
What's the problem with having the VCC connected to the Arduino's 5v?


I was trying to state that you should NOT connect it to an output pin (say digital pin 13) and using the digital output to power it.  It's okay to connect to the Arduino 5V pin, but be aware as the Datasheet mentions, it can dray up to 300mA of power.

xlivewire7x

Thanks, that would have caused me many problems if I ever tried adding more modules. Also, for scrolling messages, is there an easier way to make them other than making a whole bunch of "still images" and putting them in sequence?

xlivewire7x

If anybody has some example code they would like to post for the new matrix, please feel free to do so. I would love to have some code to look off of and mess around with.

Go Up