ATTENTION: There is an alternative firmware for this device, that allows you to display 4096 colors, instead of 255 with the default firmware. Please refer to https://github.com/fornellas/SFRGBLEDMatrix for more information on how to install it. Information below is for use with Sparkfun's default firmware.
ALTERNATIVE You can do 4096 colors with direct drive and shift registers only while enjoying support for the Adafruit::GFX library which allows you to write objects, fonts, and even scroll text. If you do not have the Sparkfun backpack hardware, you can do without by using Marc MERLIN's LED-Matrix library which offers software PWM for 3 colors as show here: https://www.youtube.com/watch?v=tKCOY1tTtM4 (github code: https://github.com/marcmerlin/LED-Matrix/ )
This page documents Arduino interfacing with Sparkfun's LED Matrix - Serial Interface - Red/Green/Blue product. The provided datasheet gives an overview, but the hardware has some particular behaviors not documented anywhere. Please read the datasheet first, then continue reading the next sections to understand its behavior.
Warning: the documentation here apply to firmware v4, not v5! Please read the caveats session below.
The hardware consists of an RGB LED Matrix on top of a PCB, which contains some additional hardware for easier use of the matrix. The matrix itself has 36 pins, but you will only need 3 wires (excluding GND and 5V) to communicate with it through the additional PCB. This is because the PCB has an ATmega168 micro controller, which can be interfaced through SPI. The micro controller comes pre-loaded with a firmware, which can be overwritten by the user. This however will require additional hardware.
Device characteristics:
The default firmware runs a frame buffer program, which reads image data via SPI and sends it to the LED Matrix. The datasheet states that the device behaves like this:
Also, the default firmware will show you a smile splash screen at the first 10 boots.
The board has connectors allowing you to attach one to another. You interface only with the first board, sending image data. When you send more data that can fit on the first board (64 bytes), the first board passes its buffer to the second board, and so on. When data has arrived to all of the boards, all of them show off their new image data.
To accomplish this, each board has a configuration, of how many boars exists in a row. The datasheet states that the following procedure must be done to reconfigure the boards:
Each board will then behave like this:
This behavior avoids tearing in a row.
Each board, when booted, will print a pattern on a corner (continuing on the row above if it can not fit), to show on the number of boards configured (L=black, R=red, G=green, B=blue):
and so on (up to 8).
The default firmware v4 has some caveats documented below. There is new version v5, fixing those bugs. You will have to follow the instructinos to update it.
Arduino support SPI communication needed to interface with the matrix. For example, Arduino Duemilanove support SPI communication specifically through pins 10 (SS), 11 (MOSI), 12 (MISO), 13 (SCK). If you have a different Arduino, please refer to your Arduino / micro controller datasheet SPI section to find the correct pins.
PS: Sparkfun's hardware has different labels for SPI pins than referred by Atmel's datasheets: SS=CS, SCK=SCLK.
A library for controlling the matrix is available at:
https://github.com/fornellas/SFRGBLEDMatrix/tree/sparkfun
The code below makes a "color showcase" and can be used as a start point to interfacing with the LED Matrix using an Arduino. It has been tested with Duemilanove, if you have a different one, please don't forget to confirm SPI pins on its datasheet!
Another sample code can be found here.
// Sample Arduino Duemilanove interface code for Sparkfun's // LED Matrix - Serial Interface - Red/Green/Blue // https://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((2<<5)&(1<<2)&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); } } |