Ambilight Clone With TM1803 LED Strips - Need Help With Serial Comm

Hello-

I have been using Arduino for a couple of years but I must say, I'm still pretty green when it comes to coding from scratch. In the past, I have always been able to find existing code I could modify to suit my needs. This is my first project that I have started pretty much from scratch because nothing existed (that I could find, anyway) that would work for this. I have been Googling my a$$ off for the last four days and haven't been able to come up with much. So hopefully someone here can help.

What I'm trying to do is make a 20 LED ambilight system similar to many that you find on the net. I have two RadioShack led strips which each have ten TM1803 controllers with three LEDs per controller. Initially, I purchased one strip and had no problem getting it to work with Processing and Arduino. Pretty standard setup with Processing taking screenshots of ten different zones on the screen and sending averaged colors to the led strip. For this, I wrote the code for processing and just added the Serial.read stuff to the existing RadioShack code. It worked really well and I was even able to get a wireless link between Processing and Arduiono with no additional work.

So, if one strip worked well, two strips should be great. So I picked up another strip, added the additional code and plugged it all in. And of course, it didn't work, at all. From my limited knowledge, I believe that by doubling the number of LEDs I have caused the buffer to overflow which brings the whole program to a halt... if that even makes sense. I'm hoping someone here can shed some light on what I'm doing wrong and what I can do to make it right. I have read a lot on this and it seems like the more I read, the more confused it get. haha. I don't want to give up on this as I have put a lot of effort into it. Code in next post. Can't exceed 9500 characters?

Arduino code:

/
#include <avr/pgmspace.h>

// ******** DEBUG ==== should auto config to adapt different mother board *********
#define DATA_1 (PORTC |=  0X01)    // DATA 1    // for UNO
#define DATA_0 (PORTC &=  0XFE)    // DATA 0    // for UNO
#define STRIP_PINOUT (DDRC=0xFF)    // for UNO
#define numBufSize 6

unsigned char r0, r1, r2, r3, r4, r5, r6, r7, r8, r9, g0, g1, g2, g3, g4, g5, g6,
  g7, g8, g9, b0, b1, b2, b3, b4, b5, b6, b7, b8, b9, r10, r11, r12, r13, r14, r15, 
  r16, r17, r18, r19, g10, g11, g12, g13, g14, g15, g16, g17, g18, g19, b10, b11,
  b12, b13, b14, b15, b16, b17, b18, b19;

unsigned long color0, color1, color2, color3, color4, color5, color6, color7,
  color8, color9, color10, color11, color12, color13, color14, color15, color16, color17,
  color18, color19;

// ***********************************************************************************************************
// *
// *                            Power Up Init.
// *
// *
// ***********************************************************************************************************
void setup() {           

  Serial.begin(9600);  

  STRIP_PINOUT;        // set output pin - DEBUG: should auto detect which mother board for use

  reset_strip();
  //noInterrupts();

}



// ***********************************************************************************************************
// *
// *                            Main Loop 
// *
// *
// ***********************************************************************************************************
void loop() 
{
  interrupts();

/*I think this is the problem.  (Serial.available()>=40) (one strip) worked perfectly.  Changing to 80 made everything go dead (no output at all).  Changing to 64 allows the leds to light up, but they don't show the correct colors.  Isn't the Arduino serial buffer 64 bytes?*/

if (Serial.available()>=80) {   
    if(Serial.read() == 0xff){
      r0 = Serial.read();
      g0 = Serial.read();
      b0 = Serial.read();
    }
    if (Serial.read() == 0xff){
      r1 = Serial.read();
      g1 = Serial.read();
      b1 = Serial.read();
    }
    if (Serial.read() == 0xff){
      r2 = Serial.read();
      g2 = Serial.read();
      b2 = Serial.read();
    }
    if(Serial.read() == 0xff){
      r3 = Serial.read();
      g3 = Serial.read();
      b3 = Serial.read();
    }
    if (Serial.read() == 0xff){
      r4 = Serial.read();
      g4 = Serial.read();
      b4 = Serial.read();
    }
    if (Serial.read() == 0xff){
      r5 = Serial.read();
      g5 = Serial.read();
      b5 = Serial.read();
    }
    if(Serial.read() == 0xff){
      r6 = Serial.read();
      g6 = Serial.read();
      b6 = Serial.read();
    }
    if (Serial.read() == 0xff){
      r7 = Serial.read();
      g7 = Serial.read();
      b7 = Serial.read();
    }
    if (Serial.read() == 0xff){
      r8 = Serial.read();
      g8 = Serial.read();
      b8 = Serial.read();
    }
    if (Serial.read() == 0xff){
      r9 = Serial.read();
      g9 = Serial.read();
      b9 = Serial.read();
    }
    if(Serial.read() == 0xff){
      r10 = Serial.read();
      g10 = Serial.read();
      b10 = Serial.read();
    }
    if (Serial.read() == 0xff){
      r11 = Serial.read();
      g11 = Serial.read();
      b11 = Serial.read();
    }
    if (Serial.read() == 0xff){
      r12 = Serial.read();
      g12 = Serial.read();
      b12 = Serial.read();
    }
    if(Serial.read() == 0xff){
      r13 = Serial.read();
      g13 = Serial.read();
      b13 = Serial.read();
    }
    if (Serial.read() == 0xff){
      r14 = Serial.read();
      g14 = Serial.read();
      b14 = Serial.read();
    }
    if (Serial.read() == 0xff){
      r15 = Serial.read();
      g15 = Serial.read();
      b15 = Serial.read();
    }
    if(Serial.read() == 0xff){
      r16 = Serial.read();
      g16 = Serial.read();
      b16 = Serial.read();
    }
    if (Serial.read() == 0xff){
      r17 = Serial.read();
      g17 = Serial.read();
      b17 = Serial.read();
    }
    if (Serial.read() == 0xff){
      r18 = Serial.read();
      g18 = Serial.read();
      b18 = Serial.read();
    }
    if (Serial.read() == 0xff){
      r19 = Serial.read();
      g19 = Serial.read();
      b19 = Serial.read();
    }
  }
  delay(20);
  color0 = (g0*65536)+(b0*256)+r0;
  color1 = (g1*65536)+(b1*256)+r1;
  color2 = (g2*65536)+(b2*256)+r2;
  color3 = (g3*65536)+(b3*256)+r3;
  color4 = (g4*65536)+(b4*256)+r4;
  color5 = (g5*65536)+(b5*256)+r5;
  color6 = (g6*65536)+(b6*256)+r6;
  color7 = (g7*65536)+(b7*256)+r7;
  color8 = (g8*65536)+(b8*256)+r8;
  color9 = (g9*65536)+(b9*256)+r9;
  color10 = (g10*65536)+(b10*256)+r10;
  color11 = (g11*65536)+(b11*256)+r11;
  color12 = (g12*65536)+(b12*256)+r12;
  color13 = (g13*65536)+(b13*256)+r13;
  color14 = (g14*65536)+(b14*256)+r14;
  color15 = (g15*65536)+(b15*256)+r15;
  color16 = (g16*65536)+(b16*256)+r16;
  color17 = (g17*65536)+(b17*256)+r17;
  color18 = (g18*65536)+(b18*256)+r18;
  color19 = (g19*65536)+(b19*256)+r19;
        
  noInterrupts();
  send_strip(color0);
  send_strip(color1);
  send_strip(color2);
  send_strip(color3);
  send_strip(color4);
  send_strip(color5);
  send_strip(color6);
  send_strip(color7);
  send_strip(color8);
  send_strip(color9);
  send_strip(color10);
  send_strip(color11);
  send_strip(color12);
  send_strip(color13);
  send_strip(color14);
  send_strip(color15);
  send_strip(color16);
  send_strip(color17);
  send_strip(color18);
  send_strip(color19);
}



/* I don't think any of this code is needed for my application...
/*******************************************************************************
 * Function Name  : send_1M_pattern
 * Description    : Transmit pattern to whole 1 meter strip
 *                  
 * Input          : pointer to ROM pattern; pattern length; frame rate
 *                  
 * Output         : None
 * Return         : None
 *******************************************************************************/
void send_1M_pattern(unsigned long data, int pattern_no, int frame_rate)
{
  int i=0;
  int j=0;
  uint32_t temp_data;

  for (i=0;i<pattern_no;i++)
  {
    noInterrupts();
    for (j=0;j<10;j++)
    {
      temp_data=pgm_read_dword_near(&data);
      send_strip(temp_data);
    }
    interrupts();

    delay(frame_rate);
  }
}
*/
//Pre-existing RadioShack code.  This sends the RGB data to the strip.  But I don't really understand how it does it...
/*******************************************************************************
 * Function Name  : send_strip
 * Description    : Transmit 24 pulse to LED strip
 *                  
 * Input          : 24-bit data for the strip
 *                  
 * Output         : None
 * Return         : None
 *******************************************************************************/
void send_strip(uint32_t data)
{
  int i;
  unsigned long j=0x800000;
  
 
  for (i=0;i<25;i++)
  {
    if (data & j)
    {
           DATA_1;
      __asm__("nop\n\t");  //What is this?
      __asm__("nop\n\t");
      __asm__("nop\n\t");
      __asm__("nop\n\t");
      __asm__("nop\n\t");
      __asm__("nop\n\t");
      __asm__("nop\n\t");
      __asm__("nop\n\t");
      __asm__("nop\n\t");    
      __asm__("nop\n\t");
      __asm__("nop\n\t");
      __asm__("nop\n\t");
      __asm__("nop\n\t");
      __asm__("nop\n\t");
      __asm__("nop\n\t");
      __asm__("nop\n\t");
      __asm__("nop\n\t");
      __asm__("nop\n\t");
      DATA_0;
    }
    else
    {
      DATA_1;
      __asm__("nop\n\t");
      __asm__("nop\n\t");
      __asm__("nop\n\t");
      __asm__("nop\n\t");
      __asm__("nop\n\t");
      __asm__("nop\n\t");
      __asm__("nop\n\t");
      __asm__("nop\n\t");
      __asm__("nop\n\t");    
      DATA_0;
    }


    j>>=1;
  }


  
}

/*******************************************************************************
 * Function Name  : reset_strip
 * Description    : Send reset pulse to reset all color of the strip
 *                  
 * Input          : None
 *                  
 * Output         : None
 * Return         : None
 *******************************************************************************/
void	reset_strip()
{
  DATA_0;
  delayMicroseconds(20);
}

and the relevant parts of the Processing code:

//send
  port.write(0xff); //sync
  port.write((byte)(r0)); //red
  port.write((byte)(g0)); //green
  port.write((byte)(b0)); //blue
    
  port.write(0xff); //sync
  port.write((byte)(r1)); //red
  port.write((byte)(g1)); //green
  port.write((byte)(b1)); // blue
  
  port.write(0xff); //sync
  port.write((byte)(r2)); //red
  port.write((byte)(g2)); //green
  port.write((byte)(b2)); // blue
  
  port.write(0xff); //sync
  port.write((byte)(r3)); //red
  port.write((byte)(g3)); //green
  port.write((byte)(b3)); // blue
  
  port.write(0xff); //sync
  port.write((byte)(r4)); //red
  port.write((byte)(g4)); //green
  port.write((byte)(b4)); // blue
  
  port.write(0xff); //sync
  port.write((byte)(r5)); //red
  port.write((byte)(g5)); //green
  port.write((byte)(b5)); // blue
  
  port.write(0xff); //sync
  port.write((byte)(r6)); //red
  port.write((byte)(g6)); //green
  port.write((byte)(b6)); // blue 
  
  port.write(0xff); //sync
  port.write((byte)(r7)); //red
  port.write((byte)(g7)); //green
  port.write((byte)(b7)); // blue
  
  port.write(0xff); //sync
  port.write((byte)(r8)); //red
  port.write((byte)(g8)); //green
  port.write((byte)(b8)); // blue
  
  port.write(0xff); //sync
  port.write((byte)(r9)); //red
  port.write((byte)(g9)); //green
  port.write((byte)(b9)); // blue
  
  port.write(0xff); //sync
  port.write((byte)(r10)); //red
  port.write((byte)(g10)); //green
  port.write((byte)(b10)); //blue
  
  port.write(0xff); //sync
  port.write((byte)(r11)); //red
  port.write((byte)(g11)); //green
  port.write((byte)(b11)); // blue

  port.write(0xff); //sync
  port.write((byte)(r12)); //red
  port.write((byte)(g12)); //green
  port.write((byte)(b12)); // blue

  port.write(0xff); //sync
  port.write((byte)(r13)); //red
  port.write((byte)(g13)); //green
  port.write((byte)(b13)); // blue
  
  port.write(0xff); //sync
  port.write((byte)(r14)); //red
  port.write((byte)(g14)); //green
  port.write((byte)(b14)); // blue
  
  port.write(0xff); //sync
  port.write((byte)(r15)); //red
  port.write((byte)(g15)); //green
  port.write((byte)(b15)); // blue
  
  port.write(0xff); //sync
  port.write((byte)(r16)); //red
  port.write((byte)(g16)); //green
  port.write((byte)(b16)); // blue
  
  port.write(0xff); //sync
  port.write((byte)(r17)); //red
  port.write((byte)(g17)); //green
  port.write((byte)(b17)); // blue
  
  port.write(0xff); //sync
  port.write((byte)(r18)); //red
  port.write((byte)(g18)); //green
  port.write((byte)(b18)); // blue
  
  port.write(0xff); //sync
  port.write((byte)(r19)); //red
  port.write((byte)(g19)); //green
  port.write((byte)(b19)); // blue

The rest of the processing code is pretty standard and I know that it works. If the rest is needed, I can post it... just let me know.

I know there has to be a better, more efficient way of doing this but I just don't where to start. I tried messing around with fastSPI_LED2 as it works with this strip but I didn't have much luck with serial comm. I'm really not knowledgeable enough to truly understand whats going on with that library.

Any help would be great... I have been banging my head on the desk with this one.