Illuminations


It’s lasted a few years but sadly our old Christmas tree failed the strictest quality control standards required for indoor duties. Luckily there was an opening for front garden decoration, so it’s not out of work just yet. Doing a fine job too I think:

The lights are plugged in to a Home Easy socket, so I may be dusting off the arduino to control them, which would be an ideal excuse to give a Pachube Dashboard a try… as soon as I’ve finished the Christmas shopping that is!

Living with polar bears


Well, the polar bears have begun their migration back north to the loft. It was my first experiment with an ambient device and the Christmas tree was certainly hard to ignore, especially when Jo complained the bears had gone off again! As a result, I updated the arduino sketch a bit to just briefly flash the bears off every three minutes when our energy use was high instead of turning them off completely. Still annoying apparently (kind of the point!) but the bears did manage to stay under arduino control all Christmas with only a few breaks on manual! A few observations now that the experiment is over:

  • I don’t think having a display like CurrentCost’s in the house makes a huge difference after the initial discovery phase. That’s not to say that the display is pointless: it is much easier than checking the meter, and the cost estimate is great, but after I found out what wastes the most energy, I rarely look at it. Is that the same for most people?
  • On the other hand, having a Christmas tree flashing when a lot of energy is being used is much harder to ignore! Not really an all year round solution but I’m sold on the idea of ambient devices. I hope to have a more compact one soon. It would be nice to have a simple indication near the front door as well for quick checks that everything is off before going out.
  • Energy use alone wasn’t enough information to tell whether the house was occupied or not. I had planned to leave the lights on automatic all the time, so they would turn on when we arrived home and off when we were out. A daft idea with hind sight because the fridge and central heating were enough to confuse the poor polar bears.
  • The arduino does a great job controlling Home Easy devices. I had it set up to send ‘reminders’ on a regular basis, which seems like a good way to make sure things are in the right state without any acknowledgements from the Home Easy receivers. (Also quite entertaining when the lights pop back on after someone turns them off with the normal Home Easy remote! I’m easily amused!)
  • This was the first project I ‘completed’ with the the arduino, and it was almost useful! Well, I enjoyed it at least, and it’s got me thinking more about the next project: the ambient orbs if Farnell ever ship the TLC5940 I ordered, or a wireless programmable thermostat.

Techno Bears


I was only planning to have a quick play with the LCD display I bought recently, but ended up finishing off my Arduino + Home Easy polar bear controller project as well. Not that it actually needed a display you understand, but I’d wired it up, so why not!

…complete with a manual override should it annoy Jo a bit too much! I finished a bit ahead of schedule in the end; the polar bears aren’t actually out yet… because it’s not Christmas! I have dug the tree up though, and as soon as it’s indoors we’ll have some ambient bears to tell us when to turn something off. Here’s the sketch so far, warts and all:

#include <Bounce.h>
#include <HomeEasyCtrl.h>
#include <Messenger.h>
#include <LiquidCrystal.h>

#define WIRELESS 6
#define BUTTON 7
#define LED 13

// Define a metronome
unsigned long previousMillis = 0;

// Set the default interval to every 3 minutes -
//   enough time for a cup of tea
unsigned long interval = 180000;

// Instantiate a Bounce object with a 5 millisecond debounce time
Bounce bouncer = Bounce(BUTTON,5); 

// Instantiate Home Easy controller with transmitter on pin 4 and LED on 13
HomeEasyCtrl lightController(WIRELESS,LED);

// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 10, 5, 4, 3, 2);

// Instantiate Messenger object with the message function and the default separator (the space character)
Messenger message = Messenger(); 

// Flag indicating the desired state of the lights
bool deviceOn = false;

// Flag indicating whether bears are on manual!
bool manual = false;

// Last energy reading in watts
int watts = 0;

// Energy use messages
int energyUse = 0;
char* energyUseMessages[]={"Energy: low", "Energy: normal", "Energy: high"};

// Define messenger function
void messageCompleted() {
 int elementCount = 0;
 int last = 0;
 Serial.println("Message received");

 // Loop through all the available elements of the message
 while ( message.available() ) {
 elementCount++;
 int value = message.readInt();

 if ((value == 0) || (elementCount > 2)) {
 Serial.println("Oops");
 return;
 }

 Serial.println(value, DEC);

 // wait for same value twice for simple
 // error checking
 if (value == last) {
 watts = value;
 } else {
 last = value;
 }
 }
 Serial.println("Watts");
 Serial.println(watts, DEC);

 checkEnergyUse();
}

void checkEnergyUse() {
 if (watts < 50 || watts > 350) {
 deviceOn = false;
 previousMillis = millis();
 // Don't mind waiting for things to go off
 if (watts < 50) {
 energyUse = 0; // low
 } else {
 energyUse = 2; // high
 }
 } else if (watts > 100 && watts < 300) {
 deviceOn = true;
 previousMillis = millis();
 energyUse = 1; // normal
 // Want things to come on immediately
 lightController.deviceOn();
 } // otherwise, no change

 updateDisplay();
}

void updateDisplay() {
 lcd.clear();

 // 1st line
 if (manual) {
 lcd.print("Manual override");
 } else {
 lcd.print(energyUseMessages[energyUse]);
 }

 // 2nd line
 lcd.setCursor(0,1);
 if (deviceOn) {
 lcd.print("Polar bears: on");
 } else {
 lcd.print("Polar bears: off");
 }
}

void setup() {
 pinMode(BUTTON,INPUT);

 // Initiate Serial Communication
 Serial.begin(9600); 

 // set up the LCD's number of rows and columns:
 lcd.begin(16, 2);
 lcd.print("Ready");
 lcd.setCursor(0,1);
 lcd.print("Polar bears: off");

 // set up incoming message processor
 message.attach(messageCompleted);
}

void loop() {

 // Check push button for manual override
 if ( bouncer.update() ) {
 if ( bouncer.read() == LOW) {
 if (!manual) {
 manual = true;
 deviceOn = true;
 lightController.deviceOn();
 } else {
 if (deviceOn) {
 deviceOn = false;
 lightController.deviceOff();
 } else {
 manual = false;
 checkEnergyUse();
 }
 }
 updateDisplay();
 }
 }

 // The following line is the most effective way of
 // feeding the serial data to Messenger
 while ( Serial.available( ) ) message.process(Serial.read( ) );

 // Keep the device in the desired state
 if ( millis() - previousMillis > interval ) {
 previousMillis = millis();

 if (deviceOn) {
 lightController.deviceOn();
 } else {
 lightController.deviceOff();
 }
 updateDisplay();
 }
}

No polar bears have been harmed in the making of this post. At least not yet anyway.

Update: Seems to be working quite well, although the manual override button seems to have problems- it seems to randomly flip back on when I want it to stay off. Still, the button works well enough to pair with a Home Easy socket which is the main thing. Tree and polar bears should be up this weekend. (16 Dec 2009)

Arduino Home Easy controller library


I’ve been having another look at controlling Home Easy devices recently, after some encouraging successes from other people on twitter and the Home Easy page on the Arduino wiki. There was already a class for receiving Home Easy signals but I’m plotting some techno polar bears at the moment so wanted a simple Arduino library for sending Home Easy signals.

After digging out an ancient C++ book I’ve now got working library, complete with example. I kept it very simple to start with so there are a few more bits still to add, like setting a specific controller id or sending a specific device code, but I’m quite pleased with the result. Here’s the sample for using the library…

#include <HomeEasyCtrl.h>

// This is the Home Easy controller
// This example will use a 433AM transmitter on
// pin 4 and will flash an LED on pin 13 when
// transmitting
HomeEasyCtrl easy(4,13);

// This is just a pin which has a push button
// connected, to trigger a Home Easy device
const int buttonPin = 6;

int buttonState = 0;

void setup()
{
 pinMode(buttonPin, INPUT);
}

void loop()
{
 buttonState = digitalRead(buttonPin);

 if (buttonState == LOW) {
 easy.deviceOn();    // turn on device 0
 delay(3000);        // wait 3 sec
 easy.deviceOff();   // turn it off again
 }
}

Just get in touch if you want the library.

Updated: managed to upload the library to the Arduino Home Easy wiki page.

Meet the team


It looks 2009 is the year for people I work with to start blogging, and they’re all on Twitter… coincidence? So if you’re looking for a good read, you might like to check them out. Starting with the newest blog…

February 2010 (the power of peer pressure brings out another blogger in the team in 2010!)

Iain’s Blog (@iainduncani)

A web 2.0 skeptical geek all rounder planning to write about technology, politics, growing vegetables, board games and walking.

October 2009

Ed’s World (@ejellard)

Off to a flying start with some great home automation with arduino, Home Easy, MQTT and a helping of hackery.

Limboworld’s blog (@jaylimburn)

Conducting a scientific experiment in to the value of blogging, so make sure you get as many people to read it as possible! Some good DIY posts to kick things off. (There would have been a few DIY posts here if I’d started this blog before fitting the kitchen!)

September 2009

The World Of Gavin (@gavinwillingham)

Definite technology slant with an enjoyable hint of grumpy old man which I’m definitely hoping will continue!

April 2009

Cobweb (@techcobweb)

Some really varied arduino projects in addition to home automation and tweeting cats. While the only circuit I’ve cobbled together recently is sitting in an ice cream tub in the porch, Mike is a master at packaging projects- his scalextric race timer is a work of art!

May 2006 (so blogging way longer than the rest of us!)

Nigel’s blog (@planetf1)

Not as easy to sum up given the number of posts but a distinct focus on technology of various kinds. Probably need to run it through wordle to get a better idea!

The trouble with making lists like this is that I am bound to have missed a few! I’ll just sneakily add more if I have… which reminds me, I was going to make more of an effort with a blogroll at some point soon.

Updated: another blog for 2010! (8 March 2010)

Home Easy Hacking Wiki


I recently discovered that someone has created a useful looking Home Easy Hacking Wiki to pull together what information there currently is about hacking a range or related home automation hardware. Unfortunately it doesn’t yet answer Jerd’s question about the automatic protocol, so if you’ve got something working, it would be fantastic if you could add a few more details to the wiki.

Hoping to get back to finishing off a Freeduino Home Easy controller before too much longer- I didn’t even get as far as unwrapping the transmitter last time! I’m currently wondering if the Finite State Machine library that Mike used in his latest project would be useful to handle transmitting and receiving from the same controller.

If you’ve done anything like this before, any tips would be most welcome!

Update: maybe the Southampton Hack Day (via Benjie) would be a suitable opportunity to work on this. (4 Sept 2009)

Update: Thanks to Paul’s post I’ve just discovered another page documenting various 433 MHz AM signals, including devices using PT2262/PT2272 encoder/decoder chips, which klik-aan klik-uit uses apparently. (24 Sept 2009)

And there’s more:

Must get round to finishing this off myself sometime soon! Here are a couple more people who have Home Easy working with the Arduino:

(29 Oct 2009)

Home Easy page on Arduino Playground


Largely thanks to @barnybug, the Home Easy Arduino hacking has been going really well. Making an LED blink is one thing, but making it blink by pressing a button the other side of the house is quite another! I’ve currently just been receiving signals, but when I’ve got the transmitter going as well, I want to do things like only relaying an on command to the socket if the current energy use isn’t too high. (Would be nice to have that working in time for Home Camp, but no promises.)

Should anyone else want to get going with some Home Easy hacking as well, I’ve created a Home Easy page on the Arduino wiki. So far it’s mostly just the sketches from Barnaby but I’m working on using interrupts instead, with the eventual aim of creating a Home Easy library for the Arduino. (There’s a Google code project for many RF protocols at once, but I just have Home Easy.)

Here’s what I have for receiving a Home Easy message with interupts so far which, with some even messier code, seems to do the trick. I would like to be able to register functions to call for specified controller/device codes, but not looked in to how that would work yet.

ISR(TIMER1_CAPT_vect) {
unsigned int pulse_width = ICR1;

if( !bit_is_set(TCCR1B ,ICES1)) { // falling edge was detected
// start over if the high pulse was out of range
if(pulse_width < min_high_width || pulse_width > max_high_width)
{
pulse_count = 0;
}
// don’t need to do anything with high pulses as long
// as they’re ok; should all be the same width
}
else { // raising edge was detected
// start over if the low pulse was out of range
if(pulse_width < min_low_width || pulse_width > max_low_width)
{
pulse_count = 0;
} else {
if(pulse_count < max_low_pulses) {
rx_wire_bits[pulse_count++] = pulse_width > bit1_low_detect ? 1 : 0;

if(pulse_count == max_low_pulses) {
message_received = receiveMsg();
pulse_count = 0;
}
}
}
}

// reset the counter
TCNT1 = 0;

// toggle bit value to trigger on the other edge
TCCR1B ^= _BV(ICES1);
}

Another Arduino Oscilloscope


On a bit of a tangent from my Home Easy hacking, I’ve been experimenting with an alternative to the poorman’s oscilloscope. The arduino + processing hack is brilliantly simple but it wasn’t much use with the signals I was trying to look at.

Zelscope looks quite interesting but it’s a trial download, plus I wanted to keep the arduino end of the poorman’s oscilloscope hack the same if possible. The Universal Real-Time Software Oscilloscope GUI DLL Library didn’t initially look as interesting since I was hoping not to have to write any code. On closer inspection, it does have a test .exe which will import data, which only needed a tiny change to the arduino sketch from the original hack:

Serial.print( val );
Serial.print(“\t0.0000000000\t0.0000000000\n\r”);

So just get the data from the serial port, into a file and import it… either I’m missing something or getting data from a serial port on Windows is a bit of a pain. I ended up using PowerShell to do the job, starting with some instructions for reading from a serial port on the PowerShell blog. Unfortunately that doesn’t seem to work, but getting rid of the add_DataReceived line and using ReadLine() did the job:

[string]$str = $port.ReadLine()
Add-Content “C:\Temp\Data.txt” $str

I do wonder if I could use the oscilloscope GUI DLL library directly from PowerShell. I get the impression that might be possible- I expect Dale will know the answer! For now, here are the results importing a file:

arduinoscope

Not bad, although I’ve yet to see if it makes finding the signal I want any easier. Next week I’ll be at my mum’s house trying to find an actual oscilloscope which I used to have!

Home Easy -duino


So I’ve done a bit of playing with the Freeduino and I can see why people like Arduinos so much: they really are simple to get working. It might only start with a blinking LED but it’s nice to feel you’ve achieved something so quickly. I wish more software was like that!

The reason for getting an arduino was to experiment with some more home automation, so I’ve ordered 433MHz AM transmitter and receiver modules which look (to the untrained eye) like they should work with my Home Easy sockets. Hopefully they’ll also be simple to wire up to the arduino as well! I’ve found a couple of projects which look like they might help get me started with the code:

In fact, combining infrared with Home Easy, to turn off a couple of sockets when putting the TV on standbye for example, might be interesting. The first thing I want to try (assuming I get it working at all!) is forwarding commands via the arduino. So, for example, the arduino could relay an on command to the living room lamp, but only if the CurrentCost reading is low enough (i.e. the kitchen lights aren’t still on)!

I’ve been using the simple oscilloscope hack to do some prototyping while I wait for the AM modules to arrive, and I’ve managed to ‘send’ a sample signal that looks about right. I’m not so sure about how good the timing is going to be though, and I’m still pondering about receiving Home Easy commands. Any suggestions about the best way to do this kind of thing would be most welcome!

Freeduino SB


I recently gave in to the temptation to get an arduino. I managed to put off buying one long enough for tinker.it to run out of the useful looking starter kits so I decided go for a bit of variety and ordered a Freeduino SB instead. It arrived ahead of schedule today and it looks like a really nice part assembled kit- I dug out my soldering iron at the weekend, and I’ve got a fresh reel of solder, so I’m all set to put it together as soon as I get a chance:

freeduinosb

Assuming it works when I’ve finished with it, and I can get an LED to flash, I’m hoping to try and get it communicating with my Home Easy sockets (getting an LED to come on using the Home Easy transmitter might be the first step).

Being a complete arduino novice, I think I’m going to need some help to get that working! My plan so far is to get a 433MHz AM transmitter and receiver module (there’s an RS Trade Counter near me) and try getting the arduino to understand the Domia Lite specification. So that’s more of a vague idea than an actual plan really! If you can help, either with what not to do when connecting an arduino to those modules, or how to program the darn thing, that’d be great- please leave a comment below!

Update: Just soldered the last few parts on the freeduino, and it blinks! (27 Jan 2009)

freeduinoblink

(I’m going to stop watching the blue flashing light any minute now…)

Update: now with spinning green thing! (28 Jan 2009)

freeduinospin

What next? Something useful?!