SPI RGB 5V 4xSMD 5050 LED Light Module for Arduino  




The SPI RGB board is 4 SMD 5050 board that can be purchased from Deal Extreme, at the following link

There wasn't much details on the site about how to use the board, however I did manage to eventually find this document DX RGB DOC (.doc). I also managed to find links to the ElcoJAcobs ShiftPWM library used for other RGB board.

After Playing with it, I managed to come up the the correct wiring for the board.



After playing around with the ShiftPWM LIbrary, I managed to get the basic functionality working, however it needed some improvements to deal with the specifics of the SPI RGB board. I connected 3 boards in series to get the setup I wanted for my end project.

I added the following methods on top of the ShiftPWM library to deal with the pairs of LEDs which are lit up (you can only address the LED's in pairs, not individually.)


*Note: I built the methods on top of the sample ShiftPWM sample program, and all credits for the ShiftPWM library should go to the original author.

/************************************************************************************************************************************
* ShiftPWM blocking RGB fades example, (c) Elco Jacobs, updated August 2012.
*
* ShiftPWM blocking RGB fades example. This example uses simple delay loops to create fades.
* If you want to change the fading mode based on inputs (sensors, buttons, serial), use the non-blocking example as a starting point.
* Please go to www.elcojacobs.com/shiftpwm for documentation, fuction reference and schematics.
* If you want to use ShiftPWM with LED strips or high power LED's, visit the shop for boards.
************************************************************************************************************************************/

//#include <Servo.h> <-- If you include Servo.h, which uses timer1, ShiftPWM will automatically switch to timer2

// Clock and data pins are pins from the hardware SPI, you cannot choose them yourself if you use the hardware SPI.
// Data pin is MOSI (Uno and earlier: 11, Leonardo: ICSP 4, Mega: 51, Teensy 2.0: 2, Teensy 2.0++: 22)
// Clock pin is SCK (Uno and earlier: 13, Leonardo: ICSP 3, Mega: 52, Teensy 2.0: 1, Teensy 2.0++: 21)

// You can choose the latch pin yourself.
const int ShiftPWM_latchPin=8;

// ** uncomment this part to NOT use the SPI port and change the pin numbers. This is 2.5x slower **
// #define SHIFTPWM_NOSPI
// const int ShiftPWM_dataPin = 11;
// const int ShiftPWM_clockPin = 13;

const int GREENOFFSET=0;
const int REDOFFSET=1;
const int BLUEOFFSET=2;
const int RED =0;
const int GREEN = 1;
const int BLUE=2;
const int ORANGE=3;
const int TURQOISE=4;
const int PURPLE=5;
const int WHITE=6;
const int LEDOffset=3;
const int ULTRAFAST=0;
const int REALLYFAST=1;
const int FAST=2;
const int SOMEWHATFAST=3;
const int MEDIUM=4;
const int MEDIUMSLOW=8;
const int SLOW=10;
const int ULTRASLOW=20;

// If your LED's turn on if the pin is low, set this to true, otherwise set it to false.
const bool ShiftPWM_invertOutputs = false;

// You can enable the option below to shift the PWM phase of each shift register by 8 compared to the previous.
// This will slightly increase the interrupt load, but will prevent all PWM signals from becoming high at the same time.
// This will be a bit easier on your power supply, because the current peaks are distributed.
const bool ShiftPWM_balanceLoad = false;

#include <ShiftPWM.h> // include ShiftPWM.h after setting the pins!

// Here you set the number of brightness levels, the update frequency and the number of shift registers.
// These values affect the load of ShiftPWM.
// Choose them wisely and use the PrintInterruptLoad() function to verify your load.
// There is a calculator on my website to estimate the load.

unsigned char maxBrightness = 255;
unsigned char pwmFrequency = 75;
int numRegisters = 6;
int numRGBleds = numRegisters*8/3;

void setup(){
Serial.begin(9600);

// Sets the number of 8-bit registers that are used.
ShiftPWM.SetAmountOfRegisters(numRegisters);

// SetPinGrouping allows flexibility in LED setup.
// If your LED's are connected like this: RRRRGGGGBBBBRRRRGGGGBBBB, use SetPinGrouping(4).
ShiftPWM.SetPinGrouping(1); //This is the default, but I added here to demonstrate how to use the funtion
ShiftPWM.Start(pwmFrequency,maxBrightness);
}

void loop()
{
// Turn all LED's off.
// ShiftPWM.SetAll(0);
// Print information about the interrupt frequency, duration and load on your program
// ShiftPWM.PrintInterruptLoad();
doTest();
}
void testFirstRow()
{
resetall();
ShiftPWM.SetOne(1,255); //Green
delay(350);
resetall();
ShiftPWM.SetOne(2,255); // Red
delay(350);
resetall();
ShiftPWM.SetOne(3,255); // Blue
delay(350);
// ShiftPWM.SetOne(4,255); //
resetall();
}
void testCycleBoards() {
ShiftPWM.SetAll(0);
SetRGBBoard(1,GREEN);
delay(350);
resetall();
SetRGBBoard(1,RED);
delay(350);
resetall();
SetRGBBoard(1,BLUE);
delay(350);
resetall();
SetRGBBoard(2,GREEN);
delay(350);
resetall();
SetRGBBoard(2,RED);
delay(350);
resetall();
SetRGBBoard(2,BLUE);
delay(350);
resetall();
SetRGBBoard(3,GREEN);
delay(350);
resetall();
SetRGBBoard(3,RED);
delay(350);
resetall();
SetRGBBoard(3,BLUE);
delay(300);
resetall();
}
void testCycleLEDS() {

ShiftPWM.SetAll(0);
for(int i=0;i<24;i++)
{
ShiftPWM.SetOne(i,255);
Serial.print(F("LED Num:"));
Serial.println(i);
delay(500);
resetall();
// ShiftPWM.SetOne(i,0);
}
delay(300);
}
void doTest(){

testFirstRow();
testCycleLEDS();
testCycleBoards();
testFlash();
testStrobe(20, true, false,false);
delay(200);
SetRGBBoard(1, RED);
SetRGBBoard(2, RED);
SetRGBBoard(3, RED);

testStrobe(10,true,false,false);
testStrobe(10,true,true,false);
testStrobe(10,true,true,true);
resetall();
testBounce(5,50);
testHeartbeat(20,1500,MEDIUM+2);
// testHeartbeat(0,0,ULTRASLOW);
testCop();
HelloHowAreYou();
}
void HelloHowAreYou(){
talk(1,BLUE,40,2,MEDIUM);
resetall();
delay(240);
talk(1,BLUE,50,3,MEDIUM);
resetall();
delay(2000);
}
void talk(int board, int color,int mydelay,int cycles, int myspeed){

for(int i=0;i<cycles;i++)
{
if (board==1)
pumpBoards(color, true, false,false, myspeed);
if (board==2)
pumpBoards( color, false, true,false, myspeed);
if (board==3)
pumpBoards( color, false, false,true, myspeed);
delay(mydelay);
}
}
void testHeartbeat(int internalDelay, int endDelay,int myspeed)
{
for(int i=0;i<5;i++)
{
pumpAllBoards(RED,myspeed);
resetall();
delay(internalDelay);
pumpAllBoards(RED,myspeed);
resetall();

delay(endDelay);
}
}
void testCop()
{
for(int i=0;i<5;i++)
{

pumpBoards(RED,false,true,false,FAST);
pumpBoards(RED,false,true,false,FAST);
resetall();
pumpBoards(BLUE,true,false,true,FAST);
pumpBoards(BLUE,true,false,true,FAST);
resetall();
pumpBoards(BLUE,false,true,false,FAST);
pumpBoards(BLUE,false,true,false,FAST);
resetall();
pumpBoards(RED,true,false,true,FAST);
pumpBoards(RED,true,false,true,FAST);
resetall();
//delay(500);
}
}
void pumpAllBoards(int color,int myspeed){
pumpBoards( color, true, true,true,myspeed);
}
void pumpBoards(int color,boolean board1, boolean board2, boolean board3,int myspeed)
{
int hold=myspeed;
for(int i=0;i<31;i++)
{
if (board1)SetRGBBoard(1, color, i*8);
if (board2)SetRGBBoard(2, color, i*8);
if (board3)SetRGBBoard(3, color, i*8);
delay(hold);
}

for(int i=1;i<31;i++)
{
if (board1)SetRGBBoard(1, color, (32-i)*8);
if (board2)SetRGBBoard(2, color, (32-i)*8);
if (board3)SetRGBBoard(3, color, (32-i)*8);
delay(hold);
}

}
void pumpBoard(int board, int color)
{
int mydelay=1;
for(int i=0;i<128;i++)
{
SetRGBBoard(board, color, i*2);
delay(mydelay);
}

for(int i=0;i<128;i++)
{
SetRGBBoard(board, color, (128-i)*2);
delay(mydelay);
}

}
void testBounce(int count, int delaytime){
for(int i=0;i<count;i++)
{
int b1=getBoardLedNum(1);
ShiftPWM.SetOne(b1+REDOFFSET,255);
delay(delaytime);
resetall();
ShiftPWM.SetOne(b1+REDOFFSET+LEDOffset,255);
delay(delaytime);
resetall();

b1=getBoardLedNum(2);
ShiftPWM.SetOne(b1+REDOFFSET,255);
delay(delaytime);
resetall();
ShiftPWM.SetOne(b1+REDOFFSET+LEDOffset,255);
delay(delaytime);
resetall();

b1=getBoardLedNum(3);
ShiftPWM.SetOne(b1+REDOFFSET,255);
delay(delaytime);
resetall();
ShiftPWM.SetOne(b1+REDOFFSET+LEDOffset,255);
delay(delaytime);
resetall();

//backwards

ShiftPWM.SetOne(b1+REDOFFSET,255);
delay(delaytime);
resetall();

b1=getBoardLedNum(2);
ShiftPWM.SetOne(b1+REDOFFSET+LEDOffset,255);
delay(delaytime);
resetall();
ShiftPWM.SetOne(b1+REDOFFSET,255);
delay(delaytime);
resetall();

b1=getBoardLedNum(1);
ShiftPWM.SetOne(b1+REDOFFSET+LEDOffset,255);
delay(delaytime);
resetall();

// ShiftPWM.SetOne(i,0);
}

}
void resetall(){
ShiftPWM.SetAll(0);
}
void testStrobe(int counter,boolean board1, boolean board2, boolean board3)
{

for(int i=0;i<counter;i++)
{
// Serial.println(i);
if (board1) resetBoard(1);
if (board2) resetBoard(2);
if (board3) resetBoard(3);

delay(50);
if (board1)SetRGBBoard(1, WHITE);
if (board2) SetRGBBoard(2, WHITE);
if (board3) SetRGBBoard(3, WHITE);
delay(50);

// ShiftPWM.SetOne(i,0);
}
resetall();

}
void testFlash()
{
// flash(1,RED,200,true);
// flash(1,BLUE,200,true);
// flash(1,RED,200,true);
// resetall();
flash(1,RED,0,false);
flash(2,BLUE,0,false);
flash(3,RED,0,false);
delay(500);
resetall();
flash(1,BLUE,0,false);
flash(2,RED,0,false);
flash(3,BLUE,0,false);
delay (500);
resetall();
flash(1,RED,0,false);
flash(2,BLUE,0,false);
flash(3,RED,0,false);
delay(500);
resetall();

}
void flash(int board, int color, int duration,boolean reset){
if (reset)
resetall();
SetRGBBoard(board,color);
delay(duration);
resetBoard(board);
}
void resetLED (int led)
{
ShiftPWM.SetOne(led,0) ;
}
void resetBoard(int boardNum)
{
int _led1 = getBoardLedNum(boardNum);
int _led2 = _led1 + LEDOffset;
ShiftPWM.SetOne(_led1,0);
ShiftPWM.SetOne(_led2,0);
}
int getBoardLedNum(int boardNum)
{
int board;
switch (boardNum){
case 1:
return(1);
break;
case 2:
return(9);
break;
case 3:
return(17);
break;
}
}
void setBoardRGB(int boardNum, int red, int green, int blue)
{
int _led1 = getBoardLedNum(boardNum);
int _led2 = _led1 + LEDOffset;
}
void SetRGBBoard(int boardNum, int Color)
{
SetRGBBoard( boardNum, Color, 255);
}
void SetRGBBoard(int boardNum, int Color, int Intensity)
{
int _led1 = getBoardLedNum(boardNum);
int _led2 = _led1 + LEDOffset;

switch(Color){
case GREEN:
ShiftPWM.SetOne(_led1+GREENOFFSET,Intensity); // green
ShiftPWM.SetOne(_led2+GREENOFFSET,Intensity); // green
break;
case RED:
ShiftPWM.SetOne(_led1+REDOFFSET,Intensity); // red
ShiftPWM.SetOne(_led2+REDOFFSET,Intensity); // red
break;
case BLUE:
ShiftPWM.SetOne(_led1+BLUEOFFSET,Intensity); // blue
ShiftPWM.SetOne(_led2+BLUEOFFSET,Intensity); // blue
break;
case ORANGE:
ShiftPWM.SetOne(_led1+GREENOFFSET,Intensity); // green
ShiftPWM.SetOne(_led2+GREENOFFSET,Intensity); // green
ShiftPWM.SetOne(_led1+REDOFFSET,Intensity); // red
ShiftPWM.SetOne(_led2+REDOFFSET,Intensity); // red
break;
case TURQOISE:
ShiftPWM.SetOne(_led1+BLUEOFFSET,Intensity); // blue
ShiftPWM.SetOne(_led2+BLUEOFFSET,Intensity); // blue
ShiftPWM.SetOne(_led1+GREENOFFSET,Intensity); // green
ShiftPWM.SetOne(_led2+GREENOFFSET,Intensity); // green
break;
case PURPLE:
ShiftPWM.SetOne(_led1+REDOFFSET,Intensity); // red
ShiftPWM.SetOne(_led2+REDOFFSET,Intensity); // red
ShiftPWM.SetOne(_led1+BLUEOFFSET,Intensity); // blue
ShiftPWM.SetOne(_led2+BLUEOFFSET,Intensity); // blue
break;
case WHITE:
ShiftPWM.SetOne(_led1+REDOFFSET,Intensity); // red
ShiftPWM.SetOne(_led2+REDOFFSET,Intensity); // red
ShiftPWM.SetOne(_led1+BLUEOFFSET,Intensity); // blue
ShiftPWM.SetOne(_led2+BLUEOFFSET,Intensity); // blue
ShiftPWM.SetOne(_led1+GREENOFFSET,Intensity); // green
ShiftPWM.SetOne(_led2+GREENOFFSET,Intensity); // green
break;
}
}
void rgbLedRainbow(int numRGBLeds, int delayVal, int numCycles, int rainbowWidth){
// Displays a rainbow spread over a few LED's (numRGBLeds), which shifts in hue.
// The rainbow can be wider then the real number of LED's.

ShiftPWM.SetAll(0);
for(int cycle=0;cycle<numCycles;cycle++){ // loop through the hue shift a number of times (numCycles)
for(int colorshift=0;colorshift<360;colorshift++){ // Shift over full color range (like the hue slider in photoshop)
for(int led=0;led<numRGBLeds;led++){ // loop over all LED's
int hue = ((led)*360/(rainbowWidth-1)+colorshift)%360; // Set hue from 0 to 360 from first to last led and shift the hue
ShiftPWM.SetHSV(led, hue, 255, 255); // write the HSV values, with saturation and value at maximum
}
delay(delayVal); // this delay value determines the speed of hue shift
}
}
}

 

.