Wednesday, November 11, 2009

Daisy Chaining works

video

The two megabrites are being operated only in single channel mode right now. I am working on controlling them individually. David and I had problems with the daisy chaining when we tried the example code given in the megabrite page. I am yet to use that code effectively to control them separately. Need to experiment on clock cycles and register shifting.

Here is the modified code that I got them working with: (removed no. of LEDs variable for now)

#define clockpin 13 // CI - ClockIN
#define enablepin 10 // EI - EnableIN
#define latchpin 9 // LI - LatchIN
#define datapin 11 // DI - DataIN

int LEDChannels[1][3] = {0}; //3 channels R,G,B for each LED
int SB_CommandMode;
int SB_RedCommand;
int SB_GreenCommand;
int SB_BlueCommand;

void setup() {

pinMode(datapin, OUTPUT);
pinMode(latchpin, OUTPUT);
pinMode(enablepin, OUTPUT);
pinMode(clockpin, OUTPUT);
SPCR = (1< digitalWrite(latchpin, LOW);
digitalWrite(enablepin, LOW);


}

void SB_SendPacket() {

if (SB_CommandMode == B01) {
SB_RedCommand = 120;
SB_GreenCommand = 100;
SB_BlueCommand = 100;
}

SPDR = SB_CommandMode <<>>4;
while(!(SPSR & (1< SPDR = SB_BlueCommand<<4>>6;
while(!(SPSR & (1< SPDR = SB_RedCommand <<>>8;
while(!(SPSR & (1< SPDR = SB_GreenCommand;
while(!(SPSR & (1<
}

void WriteLEDArray() {

SB_CommandMode = B00; // Write to PWM control registers
SB_RedCommand = LEDChannels[0][0];
SB_GreenCommand = LEDChannels[0][1];
SB_BlueCommand = LEDChannels[0][2];
SB_SendPacket();

delayMicroseconds(50);
digitalWrite(latchpin,HIGH); // latch data into registers
delayMicroseconds(50);
digitalWrite(latchpin,LOW);

SB_CommandMode = B01; // Write to current control registers
SB_SendPacket();
delayMicroseconds(50);
digitalWrite(latchpin,HIGH); // latch data into registers
delayMicroseconds(50);
digitalWrite(latchpin,LOW);

}

void loop() {

LEDChannels[0][0] = 1023; //R
LEDChannels[0][1] = 640; //G
LEDChannels[0][2] = 0; //B

WriteLEDArray();
delay(200);

LEDChannels[0][0] = 640; //R
LEDChannels[0][1] = 0; //G
LEDChannels[0][2] = 1023; //B

WriteLEDArray();
delay(200);

}

--

Just upload this code to your arduino.
Plug in two megabrites in a daisy chain. (arduino to input pins & output pins on megabrite1 to input pins on megabrite2. output on megabrite2 is free without connections for now)
and plug in a 7.5 V powersupply to the arduino.
You'll see RG to RB blinks on both the LEDs synchronized every 200 ms.

--
Results:

Power dissipation was much better with this code, I don't know yet what caused the LEDs to nearly smoke last time (maybe some mistake in the code or circuit connections?). I think one of the megabrites started smoking after prolonged use last time around. These two seem stable(I was testing for heat, they never got as hot as when we tested them in class, maybe 9V is a bit too much) for a while(1 or 2 mins). They were extremely bright, brighter than when we saw in class.


Tomorrow's TODO:

x Test with IDE ribbon cable.
x Control both of the LEDs separately in different channels
x Add more shiftbrites to the chain and figure out power circuit

1 comment:

  1. Actually now the LEDs work in separate channels too. I tested them.

    I am now off to test the IDE cable.

    ReplyDelete