Archive for the ‘tech’ Category

DIY Ambient Orb

Saturday, July 19th, 2008

Take one garden light bought at M&S for £3.50 and dissect it:

Dissected Ambient Light

Connect a BlinkM up to an arduino and set it running:

BlinkM

Combine the two and you have a home-brew ambient orb:

Next step, do something interesting with it.

I’ve been on the lookout for suitable materials to make an ambient orb for a while - particularly something to diffuse the light. My original plan, which I may still do, was to take an ordinary lightbulb and put an RGB led inside it. However, modern lightbulbs prove quite tricky to take apart without shattering something. When I spotted these lights in M&S last week I knew they were exactly what I wanted. So I bought three.

They were pleasingly easy to dissect - just some gentle persuasion with a craft knife. The led’s they come with, which you can see here, are going to be handy to reuse in the future.

I still need to work out how best to mount the BlinkM beneath it. Given their I2C interface, it is going to be very easy to chain lots of them together, working as a group.

Ambient orbs are fascinating interfaces - they provide an abstraction that can convert an data source into a simplified, yet powerful, source of information.

Converting data into information is something I have been meaning to write about for a while. But given it’s my wife’s birthday and we’re heading out for the evening in 5 minutes, that post will have to wait for another day.

Words with style

Saturday, June 14th, 2008

From Roo’s del.icio.us stream, I came across Wordle by IBM Research’s Jonathan Feinberg.

It is “a toy for generating ‘word clouds’ from text that you provide”. The results it produces are absolutely stunning. Tag clouds are quite a common thing these days - it would take a couple clicks to add one in the sidebar of this blog. But they are often quite dull. Wordle shows this doesn’t have to be the case.

The site lets you specify a list of words to generate the cloud from, or it will do it from your del.icio.us tags. You can see my tags in the cloud above.

At the moment it is a java applet - but it would be great to see it run as a web service so these clouds can be integrated more readily.

Google Treasure Hunt

Monday, May 19th, 2008

Earlier today, I spotted a tweet from @thomasj about the Google Treasure Hunt. This was followed later in the day by a series of tweets from @graham_alton (warning: spoiler in tweets!) that picqued enough interest that I decided to have a go.

In summary, the challenge is to state how many unqiue paths there are across an arbitrarily sized chessboard from the top-left corner to the bottom-right corner, but only moving down or right at each step. Graham has written up his solution, along with the original question on his blog.

He has gone straight for the proper solution using a simple formula… and some perl to handle the fact the numbers involved are beyond most desk calculators.

I decided to go for a bit more of a brute force approach… and some python to handle the fact I haven’t touched perl in a while.

Here’s my solution:

#!/usr/bin/python
# the dimensions of the board
w=54
h=30
lr = [1]*w
for y in range(1,h):
   lc = 1
      for x in range(1,w):
         lc = lc + lr[x]
         lr[x] = lc
print lc

The secret here is that for any given square on the board, the number of unique paths is equal to the sum of the number of unique paths from the squares immediately to the right and below.

Here’s an attempt to express it slightly more formally:

f(x,y) = f(x+1,y)+f(x,y+1)

where f(w,y) = f(x,h) = 1

The next question of the treasure hunt is due any minute now…

Power Graphing

Monday, May 5th, 2008

Since getting my meter online, it has been sending its readings to a server in the sky so charts like these can be produced. To really play with the data, I needed to start logging it locally and producing my own graphs. Here is a rambling rundown of how I got from XML being spat out by the device every 6 seconds to something like this:

Step One - Parsing the data

This was the easy part; AndySC had already put together a perl script for reading the serial port and doing the necessary parsing.

Step Two - Publishing the data

Again, not much for me to do here as Andy’s script already publishes the data to a set of topics over MQTT.

Step Three - Logging the data

Finally, something for me to do. A couple years ago, I would have joined Andy’s perl script with one of my own, but python is more my thing these days. I already had a piece of python that subscribes to the appropriate topics and posts the temperature values to twitter. It didn’t take much to get the same script to subscribe to the power data and dump it into a MySQL database on the local machine.

+----------------+---------+
| when           | power |
+----------------+---------+
| 20080502231747 |    0.34 |
| 20080502231753 |    0.33 |
| 20080502231804 |    0.34 |
+----------------+---------+

The table in the database is a very simple one at the moment; logging the power along with a timestamp. An entry is added to the table for every reading from the meter and having been running for 3 days there are just over 11,000 of them. I’ll have to keep an eye on this to make sure it doesn’t run away with my free disk space.

Step Four - Graphing the data

Roo showed me some stuff he’s been playing with using the Google Chart API. Whilst I generally prefer to roll my own (aka, reinvent the wheel), I couldn’t ignore just how easy it is to produce pretty graphs this way.

Before delving into the API, I needed to decide just what I wanted to produce. As there is such a range of chart types available, there are plenty of interesting things that could be done. Initially, however, I decided to stick with the traditional “power-usage-in-the-last-24-hours” chart.

The API has a limit on the amount of data that can be passed to it. So I needed to find a meaningful way to reduce the 4200 data points generated in 24 hours to around 100 at most. I soon settled on using the average value for each 10 minute period. This loses some resolution in the data, but it still shows the trends.

Generating the averages is a simple question of the right query on the database. With some trial and error, I eventually got to:

select concat(substring(substring(`when`,1,11),9,4),'0'), truncate(avg(`power`),3) from currentcost where `when` > SUBDATE(NOW(), INTERVAL 1 DAY) group by substring(`when`,1,11) order by `when`;

Simple huh?

This produces results like this:

+------+-------+
| 2240 | 0.714 |
| 2250 | 0.637 |
| 2300 | 0.406 |
+------+-------+

With that in place, all it took was to throw it together into an appropriate URL for google to generate the image:

http://chart.apis.google.com/chart?chg=100,20,1,7&chxt=y,x&
chxl=0:|0|1|2|3|4|5| 1:|2100|2300|0100|0300|0500|0700|0900|1100|1300|1500|1700|1900& chxp=1,2,11,19,27,36,44,53,61,69,78,86,95&chs=400×200 &cht=lc&chds=0,5&chm=B,f3f3f3,0,0,0&chco=aaaaff& chd=t:0.348,0.348,0.319,0.311,1.285,0.683,0.338,0.349, 0.398,0.39,0.356,0.477,0.274,0.264,0.572,0.637,0.406, 0.382,0.368,0.324,0.325,0.917,0.322,0.358,0.342,0.318, 0.191,0.124,0.209,0.204,0.192,0.213,0.205,0.196,0.374, 1.753,1.537,0.976,0.552,0.556,0.513,0.433,0.363,0.341, 0.575,0.46,0.188,0.123,0.248,0.204,0.195,0.116,0.215, 0.207,0.226,1.574,0.636,0.214,0.206,0.209,0.204,0.648, 0.694,0.628,0.599,0.689,0.743,1.222,0.278,0.394,0.326, 0.394,0.225,0.184,0.13,0.145,0.23,0.226,0.222,0.133, 0.133,0.237,0.231,0.223,0.13,0.234,0.229,0.222,0.203, 0.197,0.193,0.17,0.198,0.176,0.275,0.328,0.287,0.212, 0.159,0.192,0.19,0.212,0.292,0.298,0.418,0.332,0.789,0.894,0.719

Again, simple huh? Well, maybe not so much. Here’s a break down of what that does (and just to confuse matters, this is in a different order to where things appear in the url above…)

http://chart.apis.google.com/chart?

This is base url of the Google Charts api - all the magic comes from here.

chs=400×200

Set the size of the image.

&cht=lc

Set the type of chart - a line chart.

&chg=100,20,1,7

Gives the chart a grid in the background.

&chxt=y,x

&chxl=0:|0|1|2|3|4|5| 1:|2100|2300|0100|0300|0500|0700|0900|1100|1300|1500|1700|1900

&chxp=1,2,11,19,27,36,44,53,61,69,78,86,95

Describes the axis labels. 0 to 5 on the y-axis, and the relevant times along the x-axis. The script figures out approximate positions along the axis for the labels.

&chds=0,5

Specifies the minimum and maximum values for the data - although I occasionally go over 5Kw, I decided it wasn’t worth squeezing the data for 99% of the time when it is below that.

&chm=B,f3f3f3,0,0,0

Fills the area under the line with a light gray.

&chco=aaaaff

Draws the line with a light blue.

&chd=t:0.348,0.348,0.319,0.311,1.285,0.683,0.338,0.349, 0.398,0.39,0.356,0.477,0.274,0.264,0.572,0.637,0.406, 0.382,0.368,0.324,0.325,0.917,0.322,0.358,0.342,0.318, 0.191,0.124,0.209,0.204,0.192,0.213,0.205,0.196,0.374, 1.753,1.537,0.976,0.552,0.556,0.513,0.433,0.363,0.341, 0.575,0.46,0.188,0.123,0.248,0.204,0.195,0.116,0.215, 0.207,0.226,1.574,0.636,0.214,0.206,0.209,0.204,0.648, 0.694,0.628,0.599,0.689,0.743,1.222,0.278,0.394,0.326, 0.394,0.225,0.184,0.13,0.145,0.23,0.226,0.222,0.133, 0.133,0.237,0.231,0.223,0.13,0.234,0.229,0.222,0.203, 0.197,0.193,0.17,0.198,0.176,0.275,0.328,0.287,0.212, 0.159,0.192,0.19,0.212,0.292,0.298,0.418,0.332,0.789,0.894,0.719

Specifies the data points.

What next?

  • Chris has started doing some interesting data analysis to see if he can automatically spot ‘events’ on the graph. Will be interesting to see what can be achieved here.
  • Andy’s twittering house got some linkage last week from both Earth2Tech and Wired Science. They mention the power orb that was written about last year. I really like the idea of an ambient device for displaying this information - another project for the arduino list.

Getting the doorbell online

Sunday, April 13th, 2008

Following Andy’s example, I have setup a twitter account for my own house to share its thoughts with the world on.

So far, it is busy twittering the changing temperature of my living room, as measured by the CurrentCost meter. At the moment it only tweets when the temperature changes at least 10 minutes since the previous change. This reduces some of the noise, but I think there is more to do. I don’t necessarily care if the living room is 16°C rather than 17°C but do care if it is too cold or hot. This is a subject I will come back to another time once I have done some more experiementing.

More immediately, I set myself a challenge this weekend; to get the doorbell twittering.

To begin with I bought a cheap wireless doorbell set from Wickes to play with. This came with two receivers; a portable battery-powered one and a mains-powered one. Wasting no time I took one of them apart to find this:

The circuit has a very conveniently packaged daughterboard containing the wireless receiver. The clue was the aerial connecting to it (the white wire to the right) and even better, in the top left corner are the four pins connecting to the rest of the circuit. With my trusty multimeter, and the labels printed on the board, it didn’t take long to work out the leftmost pin is ground, the rightmost pin is +3v and the other two are the magic data pins.

With my newly acquired arduino, itself a topic for another day, I hooked-up the four pins and fairly instantly had the arduino writing over its serial link to my laptop whenever the doorbell button is pushed. Of the two data pins, I found the one labeled “DAT” is the best trigger to use; the other one, “IDEL”, seems to be more noisy and needs investigating.

The doorbell lets you pick from one of 15 channels to ensure you don’t get interference from the neighbours. It also lets you pick one of three chimes to use, from the traditional ding-dong to the full Big Ben. As that setting is on the button itself, it must be sending it over the wireless signal. Currently my circuit triggers regardless of the channel setting of the button. I assume I need to do some more signal analysis on both the DAT and IDEL pins to figure this part out. For now, it works enough to prove the idea.

Here is the sketch I used. It does some simple debouncing by not triggering twice within 3 seconds.

int potPin = 5; // Connected to 'DAT'
int val = 0;

long time = 0;
long debounce = 3000;

void setup() {
  Serial.begin(9600);
}

void loop() {
  val = analogRead(potPin);

  if (val > 0) {
    if (millis()-time > debounce) {
      Serial.print("ON:");
      time = millis();
    }
  }
}

From this point, a bit of python and mqtt magic and the doorbell would be twittering. I say “would” as I haven’t done this final piece of plumbing yet. I only have one arduino at the moment and I am not yet ready to dedicate it to any one task. Clearly I need to order a second arduino - its always good to have separate development and production systems.

Going power crazy

Thursday, April 10th, 2008

As a part of the “CurrentCost craze” that is rife at Hursley these days, I’ve had mine up and running for a few days and am very excited by the possibilities.

The CurrentCost meter gives you a real-time display of how much electricity your house is using. On its own, this would be interesting, but hard to relate to anything. One of its cool features is its awareness of how much electricity actually costs - being told your usage costs £17 per month is much more effective than saying you’re using 1.23kw.

I’m not the only one who has got this meter setup and then obsessively gone around the house to reduce how much is being wasted.

What is great about this particular device, and what appeals to the Hursley crowd, is the ability to plug it into a PC and capture the information it produces. It doesn’t take much plumbing to get the data being graphed online - something which does raise an interesting issue.

I can now see when Jo has got home from work as I see the spike of the kettle being used, but equally, anyone can get a pretty good idea if we’re in the house. Is that a genuine concern? There are certainly easier ways of working out if we’re in or not.

That aside, the graph it produces definitely does give food for thought. Here’s a snapshot of the graph from today (click through for a fully annotated version on flickr):
Power Usage

This graph has left me intrigued to find out what the 100watt-ish blip is that happens every 2 hours; there is a PC running all the time, which has the meter connected - I wonder what cron tasks are configured.

The meter has definitely left me feeling slightly guilty for the 600watts of halogen spot-lights we put in the new kitchen.

Playing (and winning) the MP3 game

Wednesday, February 13th, 2008

For a long time there hasn’t been a viable option for linux users to buy main-stream DRM-free music in the UK. I have looked at the various independent stores out there, but they simply don’t have the music I want. I have been eagerly waiting for Amazon to launch its MP3 store - something they recently confirmed would happen at some point this year.

Adele - 19

But today, out of nowhere, play.com have just launched their own music store. That’s right - I didn’t say ‘announced’ or ‘promised’; they have actually launched it today and I have bought my very first MP3 album (for the record, Adele’s 19).

Their FAQ have all the gory details; music is availble at either 192Kbit/s or 320Kbit/s depending on the recording, can be redownloaded a (limited) number of times and are unencumbered of any DRM. They only have content from EMI and some independent labels at the moment, but this is certainly a good start.

According to The Register, where I first heard the news, all tracks will be 320Kbit/s eventually, with the average price being 70p/track or £6.99/album.

All considered, play have won the race as far as I am concerned. Amazon will have to do something pretty special to make me look their way.

Pure Evoke-1S

Saturday, February 2nd, 2008

Jo and I didn’t do a good job of buying each other Christmas presents last year, so we agreed to by ourselves a joint something or other. We soon settled on a digital radio for the newly refurbished kitchen.

Before rushing out to buy one, we borrowed one from my parents so we could see if the reception in our kitchen was good enough. They have no reception where they are in Devon so weren’t doing much with it.

When I first tried it a couple weeks ago all I seemed to get was Hampshire Radio. That was good enough for some background music whilst cooking, but didn’t offer quite the range of stations we wanted. What it did prove was how often we would listen to the radio if it worked.

This morning I moved the radio to the window sill in the kitchen and suddenly found it could receive all the stations we could possibly want. With that discovery, we headed into town to finally buy our present; only a month and a bit late.

We had already picked out the one we wanted; the Pure range of radios have always caught my eye as objects with some style and the Evoke-1S is the perfect radio to have in the kitchen. The only short coming is the single speaker; the mono-sound was noticeable after the stereo of my parent’s borrowed radio. However, Pure do sell an optional added speaker that we held off from buying initially, but will be getting the next time we’re in town.

S3, EC2, SQS - The AWS Triumvirate

Tuesday, June 5th, 2007
Amazon Web Services

The Amazon Web Services have been on my radar for a while now, but a recent talk at Hursley by Jeff Barr renewed my resolve to have a play. Jeff works in Amazon’s Web Services Evangelism team and if there is one thing Jeff does well, it’s evangelism. I left his talk impressed by how they are delivering the on-demand vision for web services that IBM has talked about for so long.

They offer a global storage architecture with S3, scalable computing capacity with EC2 and web-scale messaging with SQS. This full house of web services gives you most of what you want to build highly scalable systems without having to invest in hardware. Jeff cited an example of a podcasting site, whose name I forget, that managed to get their IT infrastructure in place for $100 in one week. They have no hardware costs, no maintenance, no 2am wake-ups when a hard-disk fails.

Whilst I don’t currently have a need for a scalable-web-architecture of my own, I have been looking at the storage side of things to provide some remote backup to my photo collection. At the moment they are dotted across various machines with little backup or redundancy. I had considered getting a NSLU2 with some disks attached, but whilst I don’t rule out this option for the future, with a house move imminent I decided the time was right for an off-site solution.

The one sticky issue with S3 is that you can’t just use it; Amazon provide an API but you have to rely on third-party applications to make use of it. Here is where my fun began.

The first tool I looked at was the ruby-based s3sync. Following some instructions google found for me on John Eberly’s blog, I set about creating a storage bucket and began uploading the 1.5Gb of photos from my main server. Unfortunately, this server runs an old version of debian which, as it’s also my TV, is not about to be updated. This left me with the wrong version of ruby, so I moved to the python based tools provided by Hanzo. Besides, I’m more a python guy these days.

After a couple hours of uploading, I decided to play some more with the API; I wanted to see how to change the permissions of the files so that I could share them publicly. After reading more of the documentation, it appeared that the only way to do this is via the REST or SOAP APIs. I soon found another python library to try - this time one available on the Amazon site itself - that would do the job. However, every attempt I made failed as it couldn’t find the bucket I had created. Getting quite frustrated with it I eventually found the problem; to access a bucket via HTTP, the it’s name needs to be all lowercase - which was not the case with the bucket I had created. Given the inability to rename an existing bucket, I stopped uploading, deleted the bucket and started again.

That mistake cost me about $0.10. Not exactly the end of the world.

24 hours, 1 internet outage and $0.34 later, 1800 photos and a handful of videos from April 2003 to August 2005 are now safely stored and accessible from anywhere with an internet connection.

Just another 4000 to go - once I get them copied off the various laptops.

My (Google) Maps

Monday, April 9th, 2007
My First Google Map

My First Google Map

Google have added a new feature to their maps service; the ability to create your own annotated maps that can not only be shared with others but also that will show up in the search index.

The maps can be annotated with markers, lines drawn to mark routes and areas highlighted to… well, whatever you want.

This is a really useful service to have. In the past, I’ve used Pin In The Map to share places with others, but that is quite limited in comparison. I’ve also tried using Microsoft’s Live maps service which lets you share maps, but after my first map came up blank with all I shared it with, I soon gave up.

Google also lets you download your maps in kml format so they can be used within Google Earth.


For my first foray into My (Google) Maps, here is a short walk Jo and I often go on to escape the sofa and get some air in our lungs.