1
votes

I've spent days searching for information on the internet about this with no joy :( Really hoping someone can help.

I'm trying to create an ambilight clone using boblight, an Arduino Uno and an LED strip. This should cause the LEDs in my room to react and change colour with the colour on screen.

The main difference between what I'm doing and what others have done is that I don't have an LED strip with individually programmable LEDs. Instead of making the LEDs match the different points on the screen, I'm aiming for all the LEDs to be the same colour, based on the most dominant (or average?) colour on the screen.

My circuit is set up in a similar way to the image on this page, except without the resistors (apologies, I don't have enough reputation points to post the image into this post:

http://www.jerome-bernard.com/images/rgb-led-strips-mosfets.png

I've written a really simple sketch to change the colour of the LED strip and that works fine. I've also set up boblight on my Windows PC, including the .config file and I think that's ok too (although not really sure how to tell!)

The config file looks like this:

[global]
#interface  127.0.0.1
port        19333


[device]
name            arduino_ambilight
type            atmo 
output          "com3" 
rate            115200 
channels        3
interval        20000 
allowsync       on 
debug           on 
delayafteropen  10000000

[color]
name            red
rgb             FF0000

[color]
name            green
rgb             00FF00

[color]
name            blue
rgb             0000FF

[light]
name            main
color           red     arduino_ambilight 9
color           green   arduino_ambilight 10
color           blue    arduino_ambilight 11
hscan           0 100
vscan           0 100

The trouble is, I have no idea how to get the signal from boblight to my Arduino and how to write a sketch to interpret the boblight information.

UPDATE

I've followed John b's advice and uploaded the Adafruit LEDStream sketch to my Arduino. (see John b's post below for link to code). This is supposed to cause the LEDs to flash red, green, blue. Unfortunately it does nothing.

I imagine this is because my wiring is not set up as the Adafruit tutorial has recommended (for Adafruit wiring see http://learn.adafruit.com/adalight-diy-ambient-tv-lighting/wiring-1).

It's not possible for me to set up my wiring in this way as my strip of LEDs is different from those used in the Adalight tutorial. As mentioned above, my LEDs don't have an input and output and they don't have individually addressable LEDs. Instead I have a simple LED strip with a +12V, R, G and B.

How can I adapt Adafruit's LEDstream code to work with my wiring setup (see above link to image)? Either that or how can I adapt my wiring (given that I have to use my LEDs) to work with LEDStream?

Is there anyone out there who can help?

Many, many thanks,

Katie

2

2 Answers

1
votes

It's a bit late but here we go ):

 /* Ambilight Clone Variation Using boblight and 1 Red, 1 Green, 1 Blue Strips. 

Circuit is set up in a similar way to the image on this page.
http://www.jerome-bernard.com/images/rgb-led-strips-mosfets.png

Created 17 Feb 2014
By Chris O.
Ver. 0.50
*/

// constants won't change. Used here to set the PWM pin numbers / ONLY USE PWM~ PINS:
/* // Arduino Uno has 6 PWM pins.
const int Red_PWM_Pin =  3;      // RED 
const int Green_PWM_Pin =  5;    // GREEN
const int Blue_PWM_Pin =  6;     // BLUE 
*/
const int Red_PWM_Pin =  9;      // RED 
const int Green_PWM_Pin =  10;    // GREEN
const int Blue_PWM_Pin =  11;     // BLUE

// Set Serial Baud Rate here and in boblight.conf file.
// Use one of these rates: 9600, 14400, 19200, 28800, 38400, 57600, or 115200.
#define Baud_Rate 57600 

// Variables will change:
byte RedValue = 0x00; //HEX
byte GreenValue = 0;
byte BlueValue = 0;

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

  /* Test led strips on Power Up */ 
  analogWrite(Red_PWM_Pin, 127); //DEC / Set the pin to 50% (0~255)
  analogWrite(Green_PWM_Pin, 0x7F); //HEX
  analogWrite(Blue_PWM_Pin, 127); //DEC
  delay(1000);               // wait for a second
  analogWrite(Red_PWM_Pin, 0); //DEC
  analogWrite(Green_PWM_Pin, 0x00); //HEX
  analogWrite(Blue_PWM_Pin, 0); //DEC

  Serial.begin(Baud_Rate); //Serial.begin(115200);

}

// ***********************************************************************************************************
// *
// *                            Main Loop 
// *
// *
// ***********************************************************************************************************
void loop() 
{  
  if (Serial.available()>=4){ // if Serial Hardware Buffer has 4 or more bytes
    byte prefix1 = Serial.read(); // 1st prefix (HEX 0xFF) (DEC 255)
   // byte prefix2 = Serial.read(); // 2nd prefix (HEX 0x8F) (DEC 143)

    if (prefix1 == 0xFF){// && prefix2 == 0x8F){ // Do this only if we find the prefix 

      RedValue = Serial.read(); //read 2nd byte
      analogWrite(Red_PWM_Pin, RedValue);

      GreenValue = Serial.read(); //read 3rd byte
      analogWrite(Green_PWM_Pin, GreenValue);

      BlueValue = Serial.read(); //read 4th byte
      analogWrite(Blue_PWM_Pin, BlueValue);
    }
    else { // if no prefix found lets dump 1 byte of serial HW Buffer.
      byte dump = Serial.read(); 
      /* debug led */
      // Pin 13 has an LED connected on most Arduino boards, On Leonardo its PWM~ pin, on Uno it will go high if dump value is over 127
      // Pin 11 has the LED on Teensy 2.0
      // Pin 6  has the LED on Teensy++ 2.0
      // Pin 13 has the LED on Teensy 3.0
       analogWrite(13, dump); //debug led
      //Serial.println(dump);
    }
  }
}

// ***********************************************************************************************************
// *                             Copy This in to boblight.conf file 
// *                              for windows boblight 1.3 beta1
// *                            
// *             for windows boblight 1.3 beta1 go to The LiveLight Project http://www.livelightproject.com/
// *             http://www.livelightproject.com/downloads/Boblight/Boblight_for_V5.zip
// ***********************************************************************************************************
/*

[global]
timeout     20

#interface      127.0.0.1   not in use here
port            19333
# interpolation off   # on or off
# proportional  7.0
# saturation    5.0
# value     10.0
# valuerange    0.0 1.0
# use           no
# method        average
# threshold     20

[device]
name            arduino_ambilight
type            momo 
output          "com11"    # <-- set youre arduino port
rate            57600 # Use one of these rates: 9600, 14400, 19200, 28800, 38400, 57600, or 115200.
channels        3
prefix          FF # NOTE: this FF 8F prefix will not work in Win Boblight beta1.3 
# postfix       not in use here, will not work in Win Boblight beta1.3 
interval        40000 
# allowsync     on   not in use here
debug           off 
delayafteropen  20000000

[color]
name            red
rgb             FE0000

[color]
name            green
rgb             00FE00

[color]
name            blue
rgb             0000FE

[light]
name            main
color           red     arduino_ambilight 1
color           green   arduino_ambilight 2
color           blue    arduino_ambilight 3
hscan           0 100
vscan           0 100

*/
0
votes

below is the Github link for the Adafruit code. his is literally the code that you would run if you bought there system.

https://github.com/adafruit/Adalight/blob/master/Arduino/LEDstream/LEDstream.pde It is pretty well commented

Below is part of the code. The code is based around reading data from the serail port. If the index is in range the code saves the data in an array.

if((bytesBuffered < 256) && ((c = Serial.read()) >= 0)) {
  buffer[indexIn++] = c;
  bytesBuffered++;
  lastByteTime = lastAckTime = t; // Reset timeout counters
} else {
  // No data received.  If this persists, send an ACK packet
  // to host once every second to alert it to our presence.
  if((t - lastAckTime) > 1000) {
    Serial.print("Ada\n"); // Send ACK string to host
    lastAckTime = t; // Reset counter
  }
  // If no data received for an extended time, turn off all LEDs.
  if((t - lastByteTime) > serialTimeout) {
    for(c=0; c<32767; c++) {
      for(SPDR=0; !(SPSR & _BV(SPIF)); );
    }
    delay(1); // One millisecond pause = latch
    lastByteTime = t; // Reset counter
  }
}

Here is a place to start. You should ask questions about what you don't understand in the code