Arduino based Ambilight for you computer :)

Thanks for the info and addition.

I see that it all about this piece of code, the use of Processing makes it a lot easier. :slight_smile:

for(i =0;i<1368; i=i+2){
for(j=0; j<928;j=j+2){
pixel = screenshot.getRGB(i,j); //the ARGB integer has the colors of pixel (i,j)

I use full HD so for me it would be 1920 x 1080
But iI can speed things up by skipping more pixels.

Do you think that 3 times a (smaller) screenshot is not to much an overhead in processortime?
I don't want the films I'm playing to stutter
I use XBMC as player.

FYI.
I use this kind of LED strip, works good I have made my Aquarium light with these LED's
http://www.dealextreme.com/details.dx/sku.41522

this is awesome :slight_smile:

great idea and implementation.

I have installed Processing on my Pc.
And because don't have the drivers at the moment i took one RGB LED witch I had as spare.
And yes it worked.
I changed the capture parameters for my screen. (1920x1080)

I think that it need some tinkering because not all types of RGB Led's are equal.
The LED did not get off with a black screen but stayed on more or less white coloured.
Red on the screen did not made a the LED very red
I think that the treshold for each color is differend and also depends on the type of LED (strip) that you are using.

But the begin is promising and Processing looks very much capable for this task.

Now searching for an "how to" to monitor the serialport while the Processing sends data to the Arduino
I want to see the values.
I think that I have to search in Processing :slight_smile:

Thanks fkeel!
@ NietGiftig
If you are using my code, you should be able to see the values in processing itself (the numbers being continuously printed at the black potion in the bottom of processing) Something of that sort (weak colors, not totally dark when black screen) happened when I initially used the non-PWM pins accidentally. Also happened when I didn't ground pin 8 of the ULN2003A chip (should be connected to ground of 12V power supply and also Arduino GND pin). Also, remember that since you changed the resolution you should also change the numbers you divide the total by when averaging.

r=r/(684*464); //average red (should change to r=r/(950*540) )
g=g/(684*464); //average green  (should change to g=g/(950*540) )
b=b/(684*464); //average blue   ((should change to b=b/(950*540) )

I hope this will solve the problem because I think LED strips functions more or less the same.

Thanks for the input royboy,

I had already changed the parameters, but its good to see them from you too.

I don´t see the numbers in the application screen, but I have add some print statements in the Processing code and now they are there. (I´m learning quick, after all its works almost the same as the Arduino code :slight_smile: )
The average color in the little screen however did work, that´s why I assume that it has to do with the Arduino - RGB Led combination.

When I bypass the average colour and feed the Arduino with zero's for all colours then the LED stays off, but when I increase the value to 1 then it´s lightning up.
I use the same pins as you did and I don´t use the driver yet, just a plain RGB led with resistors to the Arduino.
But I´m sure that I will find the problem, and more sure that its not in your code.

The part in your code :
r = r+(int)(255&(pixel>>16)); //add up reds
g = g+(int)(255&(pixel>>8)); //add up greens
b = b+(int)(255&(pixel)); //add up blues
is something i have to discover how it works because the are so many shades of red (and blue and green)

Just playing and discovering now, that's also a fun part for me.

Thanks for the answers Royboy!
I just ordered all the Arduino stuff last night.
Hopefully the wait won't be too long. Bluetooth was quite expensive so I got a Uno.

Sure I'll do a video!
Though I am between apartments so it will be after a move And after a renovation. So don't wait up.. :slight_smile:

You got great feedback on your blog!

You guys who are talking about 2,3 and 4 channels for your ambilights. There are videos on youtube with 64.
Search for "64 channel ambilight".

Royboy, are you still interested in this project and looking to improve it or do you see yourself as done and going for the next challenge?

chnics:
You guys who are talking about 2,3 and 4 channels for your ambilights. There are videos on youtube with 64.
Search for "64 channel ambilight".

Yeah that's pretty cool but the fade in/out is much too slow on it for my liking. Presumably that can be adjusted though :slight_smile:

I wouldn't have thought that doing a lot of channels would be too tricky.

I'm currently wondering about if some kind of VGA passthrough device would be possible, with a chip controlling the ambilight without the computer having to do anything.

Perhaps this is more easily possible for RGB video?

RGB video presumably would be relatively easy as the RGB is split up already.

mowcius:
I'm currently wondering about if some kind of VGA passthrough device would be possible, with a chip controlling the ambilight without the computer having to do anything.

Perhaps this is more easily possible for RGB video?

RGB video presumably would be relatively easy as the RGB is split up already.

The problem with RGB or VGA is that if you also have to divide the screen
If you want to get good Ambilight you extend the screen with the colours projected on the wall.
So you have to divide the screen where each side gets the colour of that portion of the screen.
Thats not posible with the RGB output from your Tv set without additional hardware to devide the screen as far as I know.

To take it a step further, i have seen a demo with thunder and explosions wich were directed to a seperate very bright LED wich pulsed on the explosions. :smiley:

NietGiftig:
The problem with RGB or VGA is that if you also have to divide the screen
If you want to get good Ambilight you extend the screen with the colours projected on the wall.
So you have to divide the screen where each side gets the colour of that portion of the screen.
Thats not posible with the RGB output from your Tv set without additional hardware to devide the screen as far as I know.

Yeah, that was the conclusion I came to after a while.

Is there anyway for the script to avoid averaging the black bars on widescreen movies?

Yes, define the screen portion that you need.

I'm curently developing a version with 4 the sides from the screen giving sepate outputs.
In that version I have a pixel offset feature, with that you can skip the black bars.

By the way most of the work must be done in Processing, not on the Arduino

@chnics "Royboy, are you still interested in this project and looking to improve it or do you see yourself as done and going for the next challenge?"

My aim was to quickly create a platform which is easy to understand and modify. My job is done here :slight_smile: I am quite happy with it :slight_smile: It will at most take a person a day of coding and a week of shipping materials to extend this to screen borders and so on. So good luck to everyone who wants to extend this further! And please post your code somewhere where everyone can find :smiley:

It is another weekend and thus time for me to work on something else :stuck_out_tongue:

edit: just tried this myself. 9.6 volts works just fine...

Has anyone tried powering these strips off 9.6 volts? I assume it should work, but the LED's will simply be dimm. Does that make sense? Can anyone who has a working setup and a 9v battey lying around quickly give this a try and tell me the results? I would like to incroporate this into an excisting project and dont have 12v available...

Well, if someone has the equipment to quickly check this out for me, it would be apreceated.

Cheers

P.

I tried that initially. My 9V battery couldn't drive even one channel.

Edit: I got this to work

I have the plus end of 9.6Volts (1600 mAh) connected to the power in of the LED strip and the minus connected to the ground of my arduino. I have the Red Green and Blue channels directly connected to digital pins 9,10,11.

In the arduino code, I inverted the values send to PWM (i.e. blue = 255 - Serial.read():wink:

and tada. It works like a charm.

Hey Royboy, maybe you can help me. I have now officially butchered your project, and it "almost" works. Now I am a completel lay person at this and I am having the trouble finding the error.

I have 9.6Volts (1600 mAh) connected to the power in of the LED strip. I have the Red Green and Blue channels directly connected to digital pins 9,10,11. The ground of the battery is connected to a ground pin in the arduino.

This setup works (and makes me feel like a butcher). I can do RGB as well as CMYK and White using simple on & off. However, when I run your code, it does respond to the screen, but in a slightly random manner. Almost as if it where ouputting inverse values. (gets bright on a white background and dark on a black one etc.) One of the things I have tried is subtrackting 20 from all the values, which, for some mysterious reason improves the result (as in, black will dimm them, white makes it bright, yellows and blues are spot on, rest is random again.)

edit: the values that processing sends out are correct. something is going wrong on the arduino end.

Any Idea why it should have this issue?

I have had problems with this particular arduino board before, I suspect it might simply be bad. On the other hand, what I am doing seems rather unrefined, though I just cant find a reason for it not to work. (not that I actually know what I am doing.)

any ideas would be apreceated.

Thanks

P.

@fkeel
Alright I looked at the ULN 2003 datasheet: http://focus.ti.com/lit/ds/symlink/uln2003a.pdf and the thing is that the first thing the chip does is that it performs a logical NOT on the input. Thus a +5V signal into the chip creates a 0V output signal and a 0V signal creates a 12V output signal in my setup. Now this is wonderful because the led is bright when the difference between the +12V common anode and the output signal from the chip is 12V. a.k.a. The led is bright when the output signal is zero cause by a 5V signal from the arduino. In your case this is switched because the if the arduino outputs a 5V, the difference voltage is 9.6-5 = 4.6 and the leds are off. while when your arduino output is a 0V, the difference voltage is 9.6V and your leds are on! So basically the whole ON/OFF of the leds is the opposite in your setup than my setup.

Now by doing (255-Serial.read), you are completely switching the ratio of the ON and OFF time in one duty cycle. So what the ULN2003 chip switches for me, you do the switching in your code instead; ending up with the correct result :slight_smile:

I hope my explanation is understandable.

yep. that explains it. and thanks for posting this - whil I figured out how to solve the problem, it still confused me...

btw. could you explain your reasoning for using the ULN2003 chip?

anyway. thanks for posting this project - as you see, you inspired me to mess around with this myself and I learned some things which have become really handy in another project I am working on right now.

cheers

p.

What code modifications would be needed to make it so that if processing wasn't sending it any data, the strip would slowly pulsate blue, but when processing started sending data again, it would become an ambilight again?

check the processing webpage for the exact code. Its a sample matter of doing

if serial is available, do amblight
else, pulsate blue.

you want this implemented on your arduino.

check the arduino reference material on "serial" & "if", and for the pulsating you may want to use a "for2 loop. its trivial, you should be able to figure it out...

If you need more help, tell me, and I'll give you more detailed instructions.

Would it be a serial.available that would serve this purpose?