<?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; Arduino</title>
	<atom:link href="http://www.jellard.co.uk/tag/arduino/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>
		<item>
		<title>Scout racing lights &#8211; naturally arduino powered!</title>
		<link>http://www.jellard.co.uk/2009/11/scout-racing-lights-naturally-arduino-powered/</link>
		<comments>http://www.jellard.co.uk/2009/11/scout-racing-lights-naturally-arduino-powered/#comments</comments>
		<pubDate>Mon, 16 Nov 2009 22:23:22 +0000</pubDate>
		<dc:creator>Ed</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[ambient light]]></category>
		<category><![CDATA[BlinkM]]></category>
		<category><![CDATA[scouts]]></category>

		<guid isPermaLink="false">http://www.jellard.co.uk/?p=101</guid>
		<description><![CDATA[Inspired by techcobweb&#8217;s SlotCarDuino, the night before our scout group&#8217;s &#8220;Pinewood Derby&#8221; (cars made by the kids from a block of wood race down a track, powered by gravity), I decided to make a traffic-light system, and an indicator to say which car one (as there&#8217;s sometimes a debate)!
So, in between power cuts (6 days on [...]]]></description>
			<content:encoded><![CDATA[<p>Inspired by techcobweb&#8217;s <a href="http://techcobweb.wordpress.com/2009/09/02/slot-car-challenge/">SlotCarDuino</a>, the night before our scout group&#8217;s &#8220;Pinewood Derby&#8221; (cars made by the kids from a block of wood race down a track, powered by gravity), I decided to make a traffic-light system, and an indicator to say which car one (as there&#8217;s sometimes a debate)!</p>
<p>So, in between power cuts (6 days on the trot of less than 8hrs of power per day), with only a few hours of awake time before the event, I dismantled my home automation system (no loss, given there&#8217;s barely any power for the heating) and connected up the breadboard, ambient lights and a couple of wires that will act as trip wires.  As there are no pull-down resistors, and I have absolutely no components, the trip-wire is connected to ground and then digital pin 3.  Running digitalWrite(3, HIGH); enables the pull-up resistor, so whenever the circuit is complete (i.e. car hasn&#8217;t driven through the wire) it reads 0.</p>
<p>The way I made the trip-wire was to stick one wire over the track, and rest it in a small uninsulated loop of wire.  A quick trip to the scout hut proved this worked, although was in serious need of some debouncing as the vibrations on the track caused the wire to jump around a little.</p>
<p><a href="http://www.jellard.co.uk/wp-content/uploads/2009/11/RaceSwitch.jpg"><img width="277" height="300" src="http://www.jellard.co.uk/wp-content/uploads/2009/11/RaceSwitch-277x300.jpg" class="attachment-medium" alt="Simple but reasonable effective race switch" title="Race Switch" /></a></p>
<p>The main loop of the code is very simple, it reads the two trip wire readings, and if one changes it increments a winning counter.  If that counter is more than 7000 (fairly random number that seems to work), it turns that lane&#8217;s ambient light green.  After that happens, when the next trip wire is broken, the appropriate light goes red.</p>
<p>I stole the one component I did have, a switch, from the B&amp;Q ambient light, and wired that up in a similar way to the trip wires.  At the start of the loop, it checks this value to see if it has changed (the button is a normal switch, not a temporary push-button), and if it has changed (after some debouncing), it resets some variables, checks the trip-wires have been reconnected (and if not, flash the appropriate light), then runs the red-amber-green starting sequence.</p>
<p>The kids seemed to like it, and other than the odd dodgy connection, and a particularly streamlined car going under the wire, it worked perfectly!!</p>
<p>Next year will be a little more high-tech as I&#8217;ll change the trip-wires to some kind of optical sensor, and possibly have one at the start of the race so we can display track times, speeds etc.  May even make an automatic releaser, we shall see&#8230;</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jellard.co.uk/2009/11/scout-racing-lights-naturally-arduino-powered/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Home Easy Interrupts everything!</title>
		<link>http://www.jellard.co.uk/2009/11/home-easy-interrupts-everything/</link>
		<comments>http://www.jellard.co.uk/2009/11/home-easy-interrupts-everything/#comments</comments>
		<pubDate>Sat, 07 Nov 2009 18:06:57 +0000</pubDate>
		<dc:creator>Ed</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Home automation]]></category>
		<category><![CDATA[AM comms]]></category>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[home easy]]></category>

		<guid isPermaLink="false">http://www.jellard.co.uk/?p=91</guid>
		<description><![CDATA[Ok, so all the parts of the arduino code work fine &#8211; just not all at the same time! The setup is as follows:
An interrupt procedure gets the home easy (HE) signal, and sends it to a callback function.  This converts the sender/recipient/state into strings, and then publishes the data to MQTT.  Problem with this [...]]]></description>
			<content:encoded><![CDATA[<p>Ok, so all the parts of the arduino code work fine &#8211; just not all at the same time! The setup is as follows:</p>
<p>An interrupt procedure gets the home easy (HE) signal, and sends it to a callback function.  This converts the sender/recipient/state into strings, and then publishes the data to MQTT.  Problem with this is it takes time, and may be interrupted by the next HE signal.  This problem is exaggerated by the HE motion detectors, which send about 15 on/off messages one after the other.   When this happens, MQTT is interrupted and it leaves the arduino in a very strange state &#8211; loop() is paused, and nothing happens until it receives another HE signal, which kicks the arduino back into action &#8211; but by that time, any signals like &#8220;turn off the central heating&#8221; will be lost, so my energy efficient house becomes boiling hot!</p>
<p>So, after lots of hitting my head against a wall, my solution is to add the data to a global &#8220;string&#8221;, and then in the loop() method, to read this string, split it up into the MQ topic and the data to send to it, and then send it.  I have found the WString library crashes the arduino, so it&#8217;s all done by manipulating individual characters in the array.  Really missing the simplicity of Java!</p>
<p>And there are more problems&#8230;</p>
<p><span id="more-91"></span>If the arduino receives a message via MQTT at the &#8220;same&#8221; time as it receives a message via HE, the MQTT message gets lost.  Doh.  I can&#8217;t think of a guaranteed way around this problem as there&#8217;s no way of knowing when either will happen.  Fortunately the fix should be done server-side, so it&#8217;s easier to do more complex things (Java).</p>
<p>What I&#8217;ve settled for is to also queue up messages to send to the arduino into a ConcurrentLinkedQueue.  I also store the timestamp of the last message received via MQTT notifying me of a HE signal.  A thread then sits waiting for a message to be put on the queue.  If there is one, and the last received HE signal timestamp is more than 10 seconds ago, it sends the message.  It then waits a few seconds and checks that there hasn&#8217;t been a more receent HE signal received &#8211; if there was, it waits and resends, and loops until there aren&#8217;t any HE signals 10s either side of sending.</p>
<p>So, by queueing everything at each end, I think I&#8217;ve found a reasonable solution to messages getting lost.  I guess I could add some handshaking in, but that&#8217;s for another time.  Very glad I use Java for my day-job, this C stuff is horrible!!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jellard.co.uk/2009/11/home-easy-interrupts-everything/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Arduino Central Heating Control (Home Easy Hack)</title>
		<link>http://www.jellard.co.uk/2009/11/home-easy-central-heating-control-hack/</link>
		<comments>http://www.jellard.co.uk/2009/11/home-easy-central-heating-control-hack/#comments</comments>
		<pubDate>Sun, 01 Nov 2009 15:15:57 +0000</pubDate>
		<dc:creator>Ed</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Home automation]]></category>
		<category><![CDATA[AM comms]]></category>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[central heating ctrl]]></category>

		<guid isPermaLink="false">http://www.jellard.co.uk/?p=71</guid>
		<description><![CDATA[An easy way to convert a home easy plug into a central heating controller - now your home automation system can control central heating...]]></description>
			<content:encoded><![CDATA[<p>Firstly, I have no qualifications in electronics, I do not totally understand all the different types of central heating programmers, so I accept no responsibility for you screwing up your system.  As I don&#8217;t have proper central heating cable, I the colour coding is way off &#8211; there are no earth wires, despite the pictures showing earth-coloured wires.  This is safe &#8211; neither the central heating programmer nor the home easy device need earths, so I use the earth wires as control lines.</p>
<p>However, with that over&#8230;  I&#8217;m on a quest to automate my home with arduinos, and central heating is something that &#8220;needs&#8221; automating.  Yes, I could buy a Home Easy central heating controller for £75, but I already have three plugs and in all honesty, nothing to do with them (yet).  After reading an article at <a href="http://www.instructables.com/id/BampQ_homeeasy_home_automation_central_heating_c/">instructables</a>, I decided to do something similar but hopefully a lot easier.  The final result I aimed for was to have my usual central heating/hot water programmer running as usual, but have the home easy plug sitting between it and the pump/boiler so I could make it act like a thermostat.  Then, by leaving the central heating on 24&#215;7 on the programmer, I can take full control over it via arduinos and an AM transmitter.  Naturally you could use any home easy remote to control the heating as well, but that&#8217;s not very exciting!  As I&#8217;m prone to playing, I also want to be able to bypass the home easy device and let the programmer work as usual &#8211; just in case the code/hardware fails!</p>
<p><span id="more-71"></span></p>
<p>So, step one was get the stuff out of the home easy plug (HE302S, for those that care).  I could have done what instructables said and ruin a screwdriver to unscrew the tamper-proof screws, or I could use brute force &#8211; the latter one.  Just pry it open from the end opposite the screws and yank.  Then stick a screwdriver by the two clips at the end opposite the plug and lever the circuit board out &#8211; much easier!</p>
<p><a href="http://www.jellard.co.uk/wp-content/uploads/2009/11/IMG_4473.JPG"><img class="attachment-medium" title="Central Heating Wiring" src="http://www.jellard.co.uk/wp-content/uploads/2009/11/IMG_4473-300x200.jpg" alt="Central Heating Wiring" width="300" height="200" /></a></p>
<p>After probing the wires above (while the programmer was on &#8211; had to extend the wires out the bottom), I saw that the right-most pin only went live when the central heating was turned on.  Hot water (second from right) went on when hot water or central heating were on.  So, all I&#8217;d need to do is interrupt the right-most pin, letting it go live when I want C/H, and dead when I don&#8217;t.</p>
<p>Left to right, Neutral, Live, Hot Water Off (is live most of the time), Blank, Hot Water on (live when either hot water or c/h is on) and Central Heating on.</p>
<p>The wires in the pic above with red are the new wires that I added, a permanent neutral, a timer controlled live feed (right-most pin) and the output wire from my device.</p>
<p><a title="Home Easy Central Heating and Override" href="http://www.jellard.co.uk/wp-content/uploads/2009/11/IMG_4475.JPG"><img class="attachment-thumbnail" title="Home Easy Central Heating and Override" src="http://www.jellard.co.uk/wp-content/uploads/2009/11/IMG_4475-300x200.jpg" alt="Home Easy Central Heating and Override" width="300" height="200" /></a></p>
<p>The home easy device needs a neutral, which I took from the C/H programmer&#8217;s neutral, a live, which came from the C/H programmer&#8217;s right-most pin &#8211; that way the home easy device only gets power when the programmer is telling the heating to go on, which will be 24&#215;7 once I&#8217;m happy.  And then the output of the home easy device should go back to the wire that was in the right-most pin on the C/H programmer.  But, I want an override switch, so put a two-way light switch in the middle of this.  Pictures speak a thousand words, so you should be able to see what&#8217;s going on in the picture.</p>
<p>I didn&#8217;t have to isolate the relay as mentioned in the instructables article &#8211; this solution seemed much easier&#8230;</p>
<p>Net result was in less than 30mins, I can use a remote or my arduino software to turn on/off the heating &#8211; and if all goes wrong, I can take the home easy device out of the loop <img src='http://www.jellard.co.uk/wp-includes/images/smilies/icon_smile.gif' alt=':)' class='wp-smiley' /> </p>
]]></content:encoded>
			<wfw:commentRss>http://www.jellard.co.uk/2009/11/home-easy-central-heating-control-hack/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Two-way communication via Nuelectronics ethernet shield&#8230;</title>
		<link>http://www.jellard.co.uk/2009/10/two-way-communication-via-nuelectronics-ethernet-shield/</link>
		<comments>http://www.jellard.co.uk/2009/10/two-way-communication-via-nuelectronics-ethernet-shield/#comments</comments>
		<pubDate>Fri, 30 Oct 2009 17:47:16 +0000</pubDate>
		<dc:creator>Ed</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Home automation]]></category>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[central heating ctrl]]></category>
		<category><![CDATA[home easy]]></category>
		<category><![CDATA[Viglen MPC-L]]></category>

		<guid isPermaLink="false">http://www.jellard.co.uk/?p=47</guid>
		<description><![CDATA[Struggling to get two way ethernet communication working with the nuelectronics ethernet shield, so have ordered an official one.]]></description>
			<content:encoded><![CDATA[<p>&#8230;is possible, and does work &#8211; but only sometimes.</p>
<p>I struggled last night for several hours trying to get reliable two way communications.  The idea is that every time the arduino receives a home easy command from a remote or motion detector, it sends a message to the MPC-L.  Then, with some funky programming, the server will decide what events to fire off.</p>
<p>Unfortunately while I can reliably receive messages, and reliably send messages, I can&#8217;t do both &#8211; it just hangs.  I&#8217;m thinking it&#8217;s the nuelectronics ethernet shield, the software certainly isn&#8217;t very nice, so as I&#8217;ve only been playing with this for a few days, I&#8217;m splashing out on an official shield.  As a by-product of this, it is supported by <a href="http://knolleary.net/arduino-client-for-mqtt/">Nicholas O&#8217;Leary&#8217;s MQTT code</a>.  So, moving away from last night&#8217;s PHP start, I&#8217;ll write a small java program to receive these, process them, and fire off any events if need be.</p>
<p>The logic for the event firing will end up being more complicated, but initially, I want a bunch of events/desired actions, and each event has a sequence of signals required, each of which have to happen within a changable amount of time.  Only if a path through the sequence is achieved in the right time will the action be fired.</p>
<p>For example, a motion detector in the hall, and a door open/shut detector on my front door.  An event (i.e. turn off all lights) with a sequence of 1. Motion detector fired, 2. Door opened will detect when someone has just left the house, but obviously you only want it to happen if the time between 1 and 2 isn&#8217;t too much, otherwise the person could have walked upstairs and someone else came in through the front door!</p>
<p>I got this working in PHP, so will Java-it-up tonight.  Then will code the more complicated (and more useful) central heating logic (i.e. I want the house at 18 degrees at 7PM, it’s now 16 degrees, and takes 45mins to warm up to 18degrees, so turn on centreal heating at 6.15PM).</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jellard.co.uk/2009/10/two-way-communication-via-nuelectronics-ethernet-shield/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>AM Transmitters Arrived</title>
		<link>http://www.jellard.co.uk/2009/10/am-transmitters-arrived/</link>
		<comments>http://www.jellard.co.uk/2009/10/am-transmitters-arrived/#comments</comments>
		<pubDate>Wed, 28 Oct 2009 19:47:29 +0000</pubDate>
		<dc:creator>Ed</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[Home automation]]></category>
		<category><![CDATA[AM comms]]></category>
		<category><![CDATA[automation]]></category>
		<category><![CDATA[home easy]]></category>
		<category><![CDATA[radio]]></category>

		<guid isPermaLink="false">http://www.jellard.co.uk/?p=24</guid>
		<description><![CDATA[The AM devices arrived, and thanks to some great blogs, I'm controlling home easy devices via a web page/arduino!]]></description>
			<content:encoded><![CDATA[<p>Farnell delivered two packages, ordered at 4PM, the next day via UPS &#8211; very impressive, must have costed more than the £8 it cost me (free P&amp;P).</p>
<p>So, with the help of the <a href="http://www.arduino.cc/playground/Code/HomeEasy">arduino playground</a> and <a href="http://code.google.com/p/homeeasyhacking/source/browse/#svn/trunk/Arduino">homeeasyhacking</a>, my arduino could receive and transmit home easy messages.</p>
<p><img style="float: right;" src="http://www.jellard.co.uk/wp-content/uploads/2009/10/IMG_4472-300x221.jpg" alt="Prototype" /></p>
<p>The photo shows my prototype of all parts of the project (ambient light &#8211; bit of paper coiled up, will be improved soon &#8211; and home easy controller).</p>
<p>Wire the data line of the receiver (any of the two work on my receiver) to pin 8, and the data line of the transmitter to pin 6, and connect power/ground/aerials accordingly (I haven&#8217;t used an aerial for the receiver yet).  A 23cm piece of wire works well as an aerial.  All my cables are strands from CAT5 &#8211; I&#8217;m a cheap-skate!</p>
<p>To use the following code, first download the HomeEasy package from  <a href="http://code.google.com/p/homeeasyhacking/source/browse/#svn/trunk/Arduino">homeeasyhacking</a>, add the .h and .cpp file (Sketch &gt; Add File), then copy and paste the following code.  Upload it, then start the serial monitor.</p>
<p>Press a button on a home easy remote and you should see the sender code &#8211; copy this, and replace &#8220;2427994&#8243; in the code below with yours.  Then restart the program, and whatever you programmed the first button on the first slider of the remote should turn off and on.  Make sure, unlike me, you haven&#8217;t plugged your computer into that device &#8211; I eventually got the code working only to kill my computer&#8217;s power, oops!</p>
<p>To control another device, change the setHEDevice(0) line.<br />
<span id="more-24"></span><br />
<code>#include "HomeEasy.h"<br />
HomeEasy homeEasy;<br />
int onOff = 0;<br />
bool bit2[26]={};<br />
bool bit3[4]={};<br />
int txPin = 6;<br />
</code><code><br />
void setup(){<br />
homeEasy = HomeEasy();<br />
homeEasy.registerAdvancedProtocolHandler(processReceivedRemote);<br />
homeEasy.init();<br />
pinMode(txPin, OUTPUT);<br />
Serial.begin(9600);<br />
setHEDevice(0);  //Set destination home easy device (first device, 0)<br />
itob(2427994,26); //Sender code from remote control - change this to match yours<br />
transmit(1);<br />
delay(10);<br />
transmit(1);<br />
delay(1000);<br />
transmit(0);<br />
delay(10);<br />
transmit(0);<br />
}</code></p>
<p><code>void loop(){<br />
//do nothing regularly<br />
}</code></p>
<p><code>void processReceivedRemote(unsigned long sender, unsigned int recipient, bool on, bool group) {<br />
Serial.print("Sender: ");<br />
Serial.print(sender);<br />
Serial.print("\nRecipient: ");<br />
Serial.print(recipient);<br />
Serial.print("\nOn: ");<br />
Serial.print(on);<br />
Serial.print("\nGroup: ");<br />
Serial.print(group);<br />
Serial.print("\n\n");<br />
}</code></p>
<p><code>void transmit(int blnOn) {<br />
int i;<br />
// Do the latch sequence..<br />
digitalWrite(txPin, HIGH);<br />
delayMicroseconds(275);     // bit of radio shouting before we start.<br />
digitalWrite(txPin, LOW);<br />
delayMicroseconds(9900);     // low for 9900 for latch 1<br />
digitalWrite(txPin, HIGH);   // high again<br />
delayMicroseconds(275);      // wait a moment 275<br />
digitalWrite(txPin, LOW);    // low again for 2675 - latch 2.<br />
delayMicroseconds(2675);<br />
// End on a high<br />
digitalWrite(txPin, HIGH);<br />
// Send HE Device Address<br />
for (i=0; i&lt;26;i++) {<br />
sendPair(bit2[i]);<br />
}<br />
// Send 26th bit - group 1/0<br />
sendPair(false);<br />
// Send 27th bit - on/off 1/0<br />
sendPair(blnOn);<br />
sendPair(bit3[0]); //MSB<br />
sendPair(bit3[1]);<br />
sendPair(bit3[2]);<br />
sendPair(bit3[3]); //LSB<br />
digitalWrite(txPin, HIGH);   // high again (shut up)<br />
delayMicroseconds(275);      // wait a moment<br />
digitalWrite(txPin, LOW);    // low again for 2675 - latch 2.<br />
}<br />
void sendPair(boolean b) {<br />
// Send the Manchester Encoded data 01 or 10, never 11 or 00<br />
if(b)  {<br />
sendBit(true);<br />
sendBit(false);<br />
}  else  {<br />
sendBit(false);<br />
sendBit(true);<br />
}<br />
}<br />
void sendBit(boolean b) {<br />
if (b) {<br />
digitalWrite(txPin, HIGH);<br />
delayMicroseconds(310);   //275 orinally, but tweaked.<br />
digitalWrite(txPin, LOW);<br />
delayMicroseconds(1340);  //1225 orinally, but tweaked.<br />
} else {<br />
digitalWrite(txPin, HIGH);<br />
delayMicroseconds(310);   //275 orinally, but tweaked.<br />
digitalWrite(txPin, LOW);<br />
delayMicroseconds(310);   //275 orinally, but tweaked.<br />
}<br />
}<br />
void itob(unsigned long integer, int length)<br />
{  //needs bit2[length]<br />
  // Convert long device code into binary (stores in global bit2 array.)<br />
 for (int i=0; i&lt;length; i++){<br />
   if ((integer / power2(length-1-i))==1){<br />
     integer-=power2(length-1-i);<br />
     bit2[i]=1;<br />
   }<br />
   else bit2[i]=0;<br />
 }<br />
}<br />
void setHEDevice(int integer) {<br />
int length = 4;<br />
  // Convert long device code into binary (stores in global sendDevice array.)<br />
  for (int i=0; i&lt;length; i++){<br />
    if ((integer / power2(length-1-i))==1){<br />
      integer-=power2(length-1-i);<br />
      hedevice[i]=1;<br />
    }<br />
    else hedevice[i]=0;<br />
  }<br />
}<br />
unsigned long power2(int power){    //gives 2 to the (power)<br />
 unsigned long integer=1;<br />
 for (int i=0; i&lt;power; i++){<br />
   integer*=2;<br />
 }<br />
 return integer;<br />
}<br />
</code></p>
]]></content:encoded>
			<wfw:commentRss>http://www.jellard.co.uk/2009/10/am-transmitters-arrived/feed/</wfw:commentRss>
		<slash:comments>5</slash:comments>
		</item>
		<item>
		<title>BlinkM Arrived</title>
		<link>http://www.jellard.co.uk/2009/10/blinkm-arrived/</link>
		<comments>http://www.jellard.co.uk/2009/10/blinkm-arrived/#comments</comments>
		<pubDate>Wed, 28 Oct 2009 01:36:17 +0000</pubDate>
		<dc:creator>Ed</dc:creator>
				<category><![CDATA[Arduino]]></category>
		<category><![CDATA[ambient light]]></category>
		<category><![CDATA[BlinkM]]></category>

		<guid isPermaLink="false">http://www.jellard.co.uk/?p=20</guid>
		<description><![CDATA[BlinkM turned out to be incredibly easy to get going, and will make a great ambient light source.]]></description>
			<content:encoded><![CDATA[<p>BlinkM, 6xAA power-pack container arrived from <a href="http://oomlout.co.uk/">oomlout</a> (arrived next day, despite being in the middle of postal strikes), along with a free RGB LED &#8211; seem like a good place to buy from.</p>
<p>Downloaded the <a href="http://thingm.com/products/blinkm">examples</a> and got it working within a few mins.  Slight gotcha was that after I told it to change colour, it changed, then did something else.  Turned out that  a sequence was still running, so I now stop the sequences in the setup() method with  BlinkM_stopScript( blinkm_addr );</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jellard.co.uk/2009/10/blinkm-arrived/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>First bits arrived</title>
		<link>http://www.jellard.co.uk/2009/10/starting-to-play-with-an-arduino/</link>
		<comments>http://www.jellard.co.uk/2009/10/starting-to-play-with-an-arduino/#comments</comments>
		<pubDate>Tue, 27 Oct 2009 01:39:57 +0000</pubDate>
		<dc:creator>Ed</dc:creator>
				<category><![CDATA[Arduino]]></category>

		<guid isPermaLink="false">http://www.jellard.co.uk/?p=3</guid>
		<description><![CDATA[My automated home has started - well, my computer can make a LED blink - more to come soon!!]]></description>
			<content:encoded><![CDATA[<p>Freeduino and nuelectronics ethernet shield arrived a couple of days ago, so spent the first evening setting up my machine with <a href="http://arduino.cc/en/Main/Software">Ardiouno 0017</a> (the development environment/serial monitor) and then started playing with the examples.  Appears to be reasonably simple to do relatively cool things.   Got the LED blinking, a simple webpage being hosted, reflectivity sensor working and ran out of things to do &#8211; need more hardware!</p>
<p>Initial plan is to monitor gas usage as I&#8217;m currently using currentcost to monitor electricity, so would be nice to get the full picture.</p>
<p>Ordered a BlinkM to start work on an ambient light that will be used to show power consumption, number of emails, traffic, weather &#8211; anything really!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.jellard.co.uk/2009/10/starting-to-play-with-an-arduino/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
