<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Ed&#039;s World &#187; boblight</title>
	<atom:link href="http://www.jellard.co.uk/tag/boblight/feed/" rel="self" type="application/rss+xml" />
	<link>http://www.jellard.co.uk</link>
	<description>Bringing data into real life in a meaningful way</description>
	<lastBuildDate>Fri, 14 May 2010 15:00:43 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.9.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Creating an Ambilight mood light for your television</title>
		<link>http://www.jellard.co.uk/2009/12/creating-an-ambilight-mood-light-for-television/</link>
		<comments>http://www.jellard.co.uk/2009/12/creating-an-ambilight-mood-light-for-television/#comments</comments>
		<pubDate>Thu, 03 Dec 2009 23:01:58 +0000</pubDate>
		<dc:creator>Ed</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[ambilight]]></category>
		<category><![CDATA[BlinkM]]></category>
		<category><![CDATA[boblight]]></category>
		<category><![CDATA[perl]]></category>
		<category><![CDATA[tv]]></category>

		<guid isPermaLink="false">http://www.jellard.co.uk/?p=120</guid>
		<description><![CDATA[In the struggle to find more cool things to do with the arduino, I thought I&#8217;d do what someone on twitter had done, make an &#8220;Ambilight&#8221;, an ambient light behind your TV that colours whatever is behind your TV the same colour as the average colour on your screen &#8211; pretty cool!  Some Philips TV [...]]]></description>
			<content:encoded><![CDATA[<p>In the struggle to find more cool things to do with the arduino, I thought I&#8217;d do what someone on twitter had done, make an &#8220;Ambilight&#8221;, an ambient light behind your TV that colours whatever is behind your TV the same colour as the average colour on your screen &#8211; pretty cool!  Some Philips TV have this, but I&#8217;m not willing to spend extra on that (and I have a TV).  I read <a href="http://geekswithblogs.net/kobush/Default.aspx">Szymon Kobalczyk&#8217;s Blog</a> and thought I&#8217;d give it a whirl.  Currently I&#8217;m using one of my existing BlinkMs, but I&#8217;ve ordered two RGB LED strips and the necessary (hopefully) components from farnell.</p>
<p>The core idea is:</p>
<ul>
<li>Run &#8220;Boblightd&#8221;, which monitors the screen (excuse the pun) and calculates the average colour, passing it to a program that sends the message via serial to&#8230;</li>
<li>An arduino listening for colours, and changes the colour of the BlinkM/RGB LED strip accordingly</li>
</ul>
<p>This is the result of mine on my computer monitor, looks much better in real life (skip to 30-40s for best demo).  Will be even better when the RGB LED strip arrives &#8211; that&#8217;ll be going behind my 42&#8243; TV downstairs.</p>
<p><object width="425" height="344"><param name="movie" value="http://www.youtube.com/v/uG-n-HkXHG4&#038;hl=en_GB&#038;fs=1&#038;"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param><embed src="http://www.youtube.com/v/uG-n-HkXHG4&#038;hl=en_GB&#038;fs=1&#038;" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="425" height="344"></embed></object><br />
<span id="more-120"></span><br />
<strong>Installing Boblightd on Ubuntu Karmic</strong></p>
<p>Installing Boblightd wasn&#8217;t quite so straightforward as I&#8217;d hoped as it requires a whole bunch of dependencies, and on my two machines, it needed a different bunch (despite both being the most up to date Ubuntu Karmic).  For some reason, the boblightd webserver is blocking my IP address (not a static IP address) but fortunately, downloads still work &#8211; I&#8217;m using <a href="http://www.xs4all.nl/~loosen/boblight/boblight-1.3.tar.gz">version 1.3</a></p>
<p>First, the dependencies:</p>
<p>sudo apt-get install libx11-dev libxpm-dev x11proto-xext-dev libxext-dev libx11-dev libxrender-dev libavcodec-dev libavformat-dev libswscale-dev libavdevice-dev libportaudio-dev mesa-common-dev</p>
<p>Then, run ./configure, make and sudo make install</p>
<p>Grab my <a href="http://www.jellard.co.uk/wp-content/uploads/2009/12/popen.conf" target="_blank">config file</a> and change the script location to wherever you will be putting the following script.</p>
<p><strong>The Perl Script</strong></p>
<p>Boblightd runs a specified program, and prints three floats to stdin, space separated, and then a new line, and repeats.  This perl script is one loop that gets the standard in, splits it on the space, converts the floats to ints, and then to hex, and then writes it to the serial port (after checking it is different from the last one, just to save arduino processing time).  Change ttyUSB1 to wherever your arduino is.</p>
<pre>#!/usr/bin/perl -w
use Device::SerialPort qw( <img src='http://www.jellard.co.uk/wp-includes/images/smilies/icon_razz.gif' alt=':P' class='wp-smiley' /> ARAM :STAT 0.07 );
use Time::localtime;
my $PORT = "/dev/ttyUSB1";

my $ob = Device::SerialPort-&gt;new($PORT);
$ob-&gt;baudrate(115200);
$ob-&gt;write_settings;
open(SERIAL, "+&lt;$PORT");
$lastOutput = "";
while (1) {
        $in = &lt;STDIN&gt;;
        @rgb = split(/ /, $in);
        $r = int($rgb[0] * 255);
        $g = int($rgb[1] * 255);
        $b = int($rgb[2] * 255);

        $rHex = sprintf("%02X", $r);
        $gHex = sprintf("%02X", $g);
        $bHex = sprintf("%02X", $b);

        $output = "$rHex$gHex$bHex\n";
        if ($lastOutput ne $output) {
                print SERIAL $output;
                print $output;
                $lastOutput = $output;
        }
}</pre>
<p>If you haven&#8217;t already got Device::SerialPort, run these (as root):</p>
<p>perl -MCPAN -e shell</p>
<p>install Device::SerialPort</p>
<p><strong>The Arduino Code</strong></p>
<p>The Arduino code is very simple, hacked from the BlinkM Tester example.  Remember to Sketch &gt; Add File and include the BlinkM_funcs.h file before trying to run this.  Change blinkm_addr to the address of your BlinkM (probably 0&#215;09).</p>
<p><code> </code></p>
<pre>#include "Wire.h"
#include "BlinkM_funcs.h"
#define BLINKM_ARDUINO_POWERED 0
byte blinkm_addr = 0x01;
#include
char serInStr[30];

void setup()
{
  BlinkM_begin();
  delay(100);
  Serial.begin(115200);
  BlinkM_stopScript( blinkm_addr );
  BlinkM_setRGB( blinkm_addr, 0,0,0);
}

void loop()
{
  if( readSerialString() ) {
     byte r = toHex( serInStr[0],serInStr[1] );
     byte g = toHex( serInStr[2],serInStr[3] );
     byte b = toHex( serInStr[4],serInStr[5] );
     BlinkM_setRGB( blinkm_addr, r,g,b);
  }
}
#include
uint8_t toHex(char hi, char lo)
{
  uint8_t b;
  hi = toupper(hi);
  if( isxdigit(hi) ) {
    if( hi &gt; '9' ) hi -= 7;
    hi -= 0x30;
    b = hi&lt;&lt;4;
    lo = toupper(lo);
    if( isxdigit(lo) ) {
      if( lo &gt; '9' ) lo -= 7;
      lo -= 0x30;
      b = b + lo;
      return b;
    }
  }
  return 0;
}
uint8_t readSerialString()
{
  if(!Serial.available()) {
    return 0;
  }
  delay(5);
  int i = 0;
  while (Serial.available()) {
    serInStr[i] = Serial.read();
    i++;
  }
  serInStr[i] = 0;
  return i;
}</pre>
<p><strong>Putting it all together</strong></p>
<p>Upload the arduino code.</p>
<p>Run boblightd -c popen.conf</p>
<p>Run boblight-X11</p>
<p>And now watch a movie, simple!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jellard.co.uk/2009/12/creating-an-ambilight-mood-light-for-television/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
