Arduino and Boblight?

I have some code that is suppose to make arduino work with boblight. I have no idea how to make it work… Any help would be greatly appreciated. I am a pro at fixing Servers, but a moron at programming.

#define F_CPU 8000000

#include <stdlib.h>
#include <avr/io.h>
#include <avr/pgmspace.h>
#include <inttypes.h>
#include <avr/delay.h>
#include <avr/interrupt.h>
#include <avr/signal.h>

#define USART_BAUDRATE 9600
#define BAUD_PRESCALE (((F_CPU / (USART_BAUDRATE * 16UL))) - 1)

#define bit_on(BYTE, BIT) BYTE |= 1 << BIT;
#define bit_off(BYTE, BIT) BYTE &= ~(1 << BIT);

//########################### LED VARIABLEN
//-------cluster1 variables
//volatile int rinc, ginc, binc;
volatile int rpwm, gpwm, bpwm, schritte;
volatile int time=0;
/*
volatile int fadedelay, fade, fadetime, schritte;
volatile int pressed, pressed2;
*/
volatile char led_out=0;

char i;

int main (void)
{

// ############################USART VARIABLEN

UCSRB |= (1 << RXEN) | (1 << TXEN); // Turn on the transmission and reception circuitry
UCSRC |= (1 << URSEL) | (1 << UCSZ0) | (1 << UCSZ1); // Use 8-bit character sizes

UBRRL = BAUD_PRESCALE; // Load lower 8-bits of the baud rate value into the low byte of the UBRR register
UBRRH = (BAUD_PRESCALE >> 8); // Load upper 8-bits of the baud rate value into the high byte of the UBRR register

UCSRB |= (1 << RXCIE); // Enable the USART Recieve Complete interrupt (USART_RXC)
sei(); // Enable the Global Interrupt Enable flag so that interrupts can be processed

//############################### VARIABLEN INITIALISIEREN
i=1;

//--------initialisierung variable cluster1
rpwm=255;
//rinc=1;

gpwm=255;
//ginc=1;

bpwm=255;
//binc=1;

//---------------fade variablen
/*

fadedelay=20;
fade=1;
fadetime=200;
*/

schritte=255; //Anzahl der PWM stufen (bei übertragung von einem Byte sollte es 255 sein.

DDRC=0xFF; //Port C as Ausgang definieren
PORTC=0x00;

DDRD = 0x00; //Port D as Eingan definieren
PORTD |= (1<<PD6) | (1<<PD7);

//Timer0 8Bit setup , zuständig für die PWM
bit_on(TCCR0, CS00); //Int. CLK
bit_off(TCCR0, CS01);
bit_off(TCCR0, CS02);

/* Timer 2 wird nicht benötigt
bit_on(TCCR2, CS01); //Int. CLK/1024
bit_off(TCCR2, CS00);
bit_on(TCCR2, CS02);
*/

TCNT0 = 0x00; //Timer-Reg. löschen

bit_on(TIMSK, TOIE0); //Overflow-Int. enable

//#####################################################################

for (;:wink: // Loop forever
{

/*
_delay_ms(20);

if (!( PIND & (1<<PD7)) && pressed2==0){
fadetime=fadetime+50; pressed2 = 1;
}

if ( PIND & (1<<PD7)) {
pressed2=0;
}

if (!( PIND & (1<<PD6)) && pressed==0){
fade ^= (1<<0); pressed = 1;
}

if ( PIND & (1<<PD6)) {
pressed=0;
}

if(fadedelay>=fadetime && fade==1 ){

//-----------------cluster1

gpwm=gpwm+ginc;
if (gpwm>=schritte) ginc=-((TCNT2/80)+1);
if (gpwm<=-60) ginc=(TCNT2/80)+1;

bpwm=bpwm+binc;
if (bpwm>=schritte) binc=-((TCNT2/100)+1);
if (bpwm<=-40) binc=(TCNT2/100)+1;

fadedelay=0;

}

fadedelay++;

*/

} //for

//#####################################################################

} //main

// ################################### USART INTERRUPT ROUTINE

ISR(USART_RXC_vect)
{
volatile int ReceivedByte;

ReceivedByte = UDR; // Fetch the recieved byte value into the variable “ByteReceived”

if (i==1) rpwm = ReceivedByte;

if (i==2) gpwm = ReceivedByte;

if (i==3) { bpwm = ReceivedByte; i=0; }

UDR = ReceivedByte; // Echo back the received byte back to the computer
UDR = i;
i++;

}

SIGNAL(TIMER0_OVF_vect) // ############# PWM TIMER INTERRUPT ROUTINE

{

TCNT0=128;

time++;

if(time>=schritte) time=0;

//--------------------------Cluster1
if(time>=rpwm)
{
bit_off(led_out,0);
}

else
{
bit_on(led_out,0);
}

if(time>=gpwm)
{
bit_off(led_out,2);
}

else
{
bit_on(led_out,2);
}

if(time>=bpwm)
{
bit_off(led_out,1);
}

else
{
bit_on(led_out,1);
}

//---------ausgabe Port

PORTC = led_out;
}


The second set of code should work, but only one color works for me, and it turns on red green and blue on at the same time, when I look at a green image.

int bluePin = 9;
int redPin = 10;
int greenPin = 11;

char controlChar[9];

void setup() {
analogWrite(redPin, 0);
analogWrite(greenPin, 0);
analogWrite(bluePin, 0);

Serial.begin(9600);

// I put this in case there are some “leftovers”, but I’m quite sure it’s not needed
while (Serial.available() > 0) {
Serial.read();
}
}

void loop() {

// ** BobLight **
//An int to store the average colors in the following pattern:
//Red = L, Green = G, Blue = B
//Left = L, Top = T, Right = R
//{RL,RT,RR,GL,GT,GR,BL,BT,BR}

if (Serial.available() >= 9) {
for (int i = 0; i < 9; i++) {
controlChar = Serial.read();

You could start by explaining what boblight is and what you're trying to do. Copying a huge program for the more general AVR architechture isn't going to help much. Nobody is going be able to read that and figure out what the problem is, especially since you haven't said what the problem is or what you are trying to do with the code.

I just want to make boblight talk to my arduino. Boblight is an application that replicates "ambilight". It takes a position on the screen and takes the average color of that section and shoots it out to the arduino. Which in turn produces the same color. These are the control characters boblight pushes out.

analogWrite(redPin, controlChar[1]); analogWrite(greenPin, controlChar[4]); analogWrite(bluePin, controlChar[7]);

Hi ksmith102683, I only ran across your post today, so my apologies for not noticing this before. I actually have a Windows-based setup running with Arduino and Boblight. The setup is not as elegant as creating a dedicated sketch that listens directly to Boblight, but it works and is relatively easy to understand (certainly does not require you to build your own controller board and mess with AVR code). Note that I created this setup 2 years ago when there was not that much interest in Boblight yet.

I am using Eltima's Virtual Serial Port software to route the RGB signal from Boblight to VVVV where I am using the patch from MrBenefit at VVVV.org with Firmata to read the signal and send it to 2 (IKEA) RGB led lamps connected to the Arduino board. You can find a bit more info on my setup, the modified VVVV patch and a video here: http://www.welivelikethis.net/2007/07/diy_ambilight.html#more.

2 things I would like to implement moving forward: - support for the Diecimila+ boards with the additional 3 PWM outputs so I can do the left- and right side of the screen with my 2 lamps (right now I am using the top signal that Boblight sends out) - A Mac version of Boblight now that it has gone open source and a Linux version is already available

Cheers, Robert K.