Project updates

Things have been a little quiet as of late due to me being busy.

The various projects have been progressing nicely in the background and I’ll be getting their progress written up into blog posts as soon as time permits.

In the interim here is a quick update on where things are at:

Wireless thermostat

My Arduino YUN has arrived. This is going to be the perfect piece of equipment for completing my WiFi thermostat project. It takes away the need to worry about hooking up a separate wireless shield. I’ll just need to attach one of my touch screen shields to it and hook up a relay and thermistor and it will be ready to go.

My next wireless thermostat post will go into more detail on this.

Ethernet Thermostat

The Ethernet thermostat is almost complete. The next post on this will detail each component I used, how to set it up and will also discuss connecting it to baseboard heaters and the types of relay needed.

Thermostat controller

The Java based thermostat controller running on the Pi is coming along nicely. The next posts on this will tie in with my earlier post on parallel computing.

The controller is going to leverage Hadoop which is running on other devices in my home to process temperature data. Expect a guide to setting up Hadoop on the Raspberry Pi and also a further look at MPI for C based applications that can also leverage spare processing capacity.

There will also be code uploaded to BitBucket which you can download and use as a base for your projects.


Upcoming reviews

I have some upcoming reviews on the Arduino YUN, the Pebble smart watch and Mint floor sweeper.



MPI (Message Passing Interface) – Part 1


In a previous post I touched on the fact we would be examining HPC (High Performance Computing), parallel processing and Hadoop in relation to Home Automation.

As our home network grows with multiple devices, tablets, microprocessors and similar running on it we reach a point where we have many CPU’s which are often sitting dormant. Being able to leverage this spare computational power for working on other tasks in our home poses an interesting challenge.

One method we can use in the case of multiple Raspberry Pi units is to use applications that run using MPI (Message Passing Interface). The MPI provides us with a set of base routines and functionality for communicating between multiple CPU’s.

Originally written with C and Fortran in mind, there are many libraries for languages including Python and Java that allow us to implement MPI based applications.

MPI has eight basic concepts, these are:

Communicator – An object that connects groups of processes in the MPI session.

Point-to-point basics – Allows process to process communication

Collective basics – Performs communication amongst all processes in a process group

Derived datatypes – Used for dealing with datatypes in MPI applications

One-sided communication – A set of operations used for dealing with scenarios where synchronization would be an inconvenience for example the manipulation of matrices and calculating matrix products.

Collective extensions –  For example non-blocking collective operations (A combination of non-blocking point-to-point functionality with collective basics) which can help reduce the over-head on communications.

Dynamic process management –  The ability for an MPI process to help with the creation of new processes or establish communication between MPI processes.

MPI-IO – The abstraction of the I/O management on parallel systems to the MPI

These eight concepts can help us to decide what functionality we wish to use in our home automation applications that implement MPI.

To give an example of how this may be useful in the home let’s look at the following example.

Redundant media unit and thermostat controller

In this scenario we have a thermostat controller running on a Raspberry Pi that calculates various temperature data and adjusts the thermostats, blinds and similar as needed. This thermostat controller for example may also use weather data to decide whether a device that acts as a damp/water sensor should be switched on or off based upon predicted rain fall levels.

Over time as we store more historical data and get weather streams via the web we have an ever increasing amount of data to work with. More data should hopefully provide more precision. However working with more data also means we are crunching more numbers and thus placing an ever increasing burden on the CPU of the Raspberry Pi.

We can optimize our code and database in order to help tackle performance issues, however this will only get us so far.

Now let’s imagine we have a second Raspberry Pi running XMBC in our home, which we use on occasions to watch streamed TV from the web. This Raspberry Pi may be sitting idle for much of the day, so it would be great if we could leverage it’s CPU to crunch our weather data while it is sitting dormant.

This is where using MPI can help. A program written using MPI can check if the media unit is being used and if not set its CPU to work on processing temperature data.

Using the eight basic concepts of MPI we can write an application that will handle the communication between the thermostat controller and XMBC RPi and pass calculations back and forth.

This model also allows us to add further devices to our network that can be used by the thermostat controller for parallel processing.


Our thermostat controller is being written in Java and will run on Tomcat, therefore in the next post on MPI we will look at its Java implementation and how we can use this in our code.

We will explore the techniques used for writing distributed applications and look at a scalable model that allows for the addition of extra devices to the network.

Raspberry Pi Home Automation with Arduino

So the book has finally been published!

Raspberry Pi Home Automation with Arduino - book cover

Raspberry Pi Home Automation with Arduino

The title is: Raspberry Pi Home Automation with Arduino and it is available from Packt publishing at the following URL:


A bit about the book

Raspberry Pi Home Automation with Arduino is a basic introductory guide for using your Raspberry Pi technology and the Arduino Open Source framework, for building small home automation projects. The book will walk you through the basics of getting setup, trying out some basic electronic components such as photo-resistors and DC motors and building some introductory projects.

I’ve tried to keep the book accessible to beginners and steered clear of anything too complex. Once you are comfortable with the material in the book you’ll be able to move onto the more challenging projects.

Some of the topics covered in the book include:

  • Install an operating system for your Raspberry Pi
  • Set up the Raspberry Pi and Arduino bridge shield
  • Learn how to work with electronic components to build small circuits
  • Develop applications that interact with your circuits
  • Use thermistors and photoresistors to monitor and control your surroundings
  • Control your own mains power with a relay shield and even connect a motor to your Raspberry Pi

Cooking Hacks shield 

Due to delays in the Gertboard shipping, when originally writing the book I found an excellent replacement for this component. This is the Cooking Hacks Raspberry Pi to Arduino connection bridge shield, which can be found here.

As you may have seen in some of my earlier posts I have given some video examples on the bridge shield being used to connect a Arduino Relay and Arduino Motor shield to the Raspberry Pi.

I would recommend checking this component out if you plan to do any home automation projects with your Raspberry Pi and want to re-use existing Arduino shields.


If you have any question or queries feel free to post them here. If you spot any Errata (yes the dreaded typo as well) you can send through a correction form here.

Raspberry Pi powered TV and dd-wrt router configuration


Yesterday the snow hit so I decided to try to knock off some projects that had been on the back-burner.  Two of these were related to one another, the first being setting up my spare wireless router as a client bridge and the second setting up a Raspberry Pi with raspbmc.

Completing these two projects would allow me to create a Media Center for television and music.

Wireless router – client bridged mode

I had spent several days deciding  whether to use the wireless router I had spare to create a second network at home (not connected to the Internet), or to use it in client bridged mode.

In the end I opted for client bridged mode. The wireless router has a number of Ethernet ports located on it and would be perfect to place next to my TV as this is nowhere near my existing Ethernet switch. With this in place I could then run a short Ethernet cable from my Raspberry Pi into the wireless router and then stream TV over the wireless connection back through the Ethernet connection to the RPi and then over HDMI to the TV.

This image from the dd-wrt website shows an example of a network setup using two wireless routers one in client bridged mode:


Client Bridge example from

Setting up the wireless router was fairly straight forward. I used a Cisco Linksys E4200 router and installed the dd-wrt software onto this.

Linksys E4200

Linksys E4200

You can check your wireless router to see if it is supported at the following link:

Once you have found your router download the firmware and follow the instructions on the dd-wrt site. There are a number of warnings on there to help you avoid ‘bricking’ (screwing up the router so it as much use as a brick) your router.

I would recommend following these as it will cause you less pain in the long run.

Once you have the router setup, follow these steps to set up the router in client bridged mode:

If everything goes well you will now have a second wireless router connected to your primary wireless router and can then use it with the Raspberry Pi.


Raspbmc is a version of the Debian Linux distro specially compiled for the Raspberry Pi to turn your Pi into a XBMC media center.

Installing it is fairly straight forward. Format  an SD card and then follow the steps located here depending on what machine you are using to format the card.

Once you have the SD card ready to go you can hook up your RPi to the wireless router, TV and power and get things started.

Raspberry Pi

Raspberry Pi

Note: If you have problems with the HDMI cable not displaying a picture, try the steps at this link:

When the Pi boots up it will run through the Raspbmc installation process.

Raspbmc splash screen after installing

Raspbmc splash screen after installing

Once the installation is complete you will now have the XMBC media center ready to start using.



Accessing the IP# of your Raspberry Pi via a web browser on port 80 will give you access to the ‘remote control’


From here you can navigate through the menus on your TV and access content.

A wide variety of content is available on Raspbmc ranging from BBC iPlayer through to Hulu.



You can find instructions on installing the various TV networks software from the UK, US, Canada, France etc. at these following links:

General plugins:

UK TV specific:

Some content will not work in your area due to restrictions, for example BBC iPlayer TV content is not available outside of an UK IP address range (however radio is). seems to be a popular choice for circumnavigating this – Disclaimer: I’m not sure what the legalities of this are so you use these services at your own risk, if you don’t know it is probably best to avoid it.


So there we have it, a simple XMBC media center running on your Raspberry Pi that you can use to stream TV, radio and other media from.

You can read more about XMBC’s features and quick start guide at the following URL:

I have  Gertboard ready to build for this Pi as well, so I will be looking at what I can use this for in my media center.


Raspberry Pi to Arduino connection bridge experiment – DC Motor

I’ve been doing some experimentation with the Cooking Hack Raspberry Pi to Arduino connection bridge for the upcoming book.

Here is a quick sneak-peak of an experiment I conducted when testing out some of the hardware.

The video below shows a combination of a Raspberry Pi, the Cooking Hacks shield, an Arduino motor-shield  a small DC motor and a circuit consisting of a resistor and photo-resistor.

The software in the background is processing the feedback from the photo-resistor and deciding when to turn the motor on and off, and in which direction. This software also generates the necessary PWM for the motor.

In the video I cover the photo-resistor to turn the motor clockwise and then uncover it to turn it counter-clockwise.


P.S Thanks to Andy C on the Cooking Hacks forum for pointing me in the direction of using C threads for PWM.

Raspberry Pi to Arduino Bridge

I came across this neat little board the other day:

The Bridge looks like an Arduino shield and connects to the GPIO pins on your Raspberry Pi. After setting up the software you can then hook up Arduino shields to your RPi.

This obviously opens up all sort sof possibilities as there are an array of Arduino shields out there that are capable of some great functionality.

This is also open up the Raspberry Pi for building sensor projects, something I will be exploring in latest posts.

Quick updates


For those of you not familiar with it, the Gertboard is a microcontroller kit for the Raspberry Pi that comes with a variety of add ons (motors, sensors etc.)

It hasn’t shipped in the US yet, however I have pre-ordered it and will be doing a review once the equipment arrives.

In the meantime you can read more about it at the Element14 site.

Potential book

As a result of this blog there is the potential for a book in the works, more on this when/if it develops further.

Punching cable

I recently got a crash course in punching cable and wiring up Cat 5 and phone cable. There is a post in the works on this, where I will explain the relevance for home automation.

Temperature Database Prototyping – Hardware, Postgresql and HTSQL


In this post I am going to detail prototyping a test Postgresql database server, installing Postgres support on the Raspberry PI (for HTSQL) and then serving up the contents of the DB server via HTSQL over http.

The purpose of this task is to familiarise ourselves with each of the components in the system before we design how the actual database server will be setup and built out.

Throw away test machine

I like to keep a couple of old Windows machine on hand for building out quick test servers that I can use to prototype a system and then wipe out ready for my next project. I find this saves a lot of cost of going out and buying hardware, only to discover your original plan has changed for some technical/design reason and then having to purchase more equipment.

For this task I am using an old Pentium 4 machine running XP with about 60 Gigs of HDD space. I’ve hooked it up with a monitor and keyboard and plugged it into my router via a network cable. At this point it is worth grabbing the IP address of the machine you have just plugged in. This should be available via your routers DHCP table.

Consult your router documentation on how to access this information if you are not familiar with the process. Note: I checked my DHCP table after installing Ubuntu – since this is the only Ubuntu machine on my network currently, it appeared as “ubuntu” in the table

Now my first step is going to be to set it up as a dual-boot machine and load Ubuntu desktop edition onto it.

Ubuntu setup

Depending on the type of machine you use for prototyping the instructions below will obviously be different, for those of you with an old XP machine at hand, the steps below should work for you.

  1. Downloaded Ubuntu’s latest version windows installed here.
  2. Run the installer and follow the on-screen instructions – Note: select your OS type as Ubuntu.
  3. Once your machine has rebooted into Windows follow the next steps:
  4.  Right click My computer and select Properties
  5. Select the Advanced tab from the pop-up box
  6. Under Start-up and Recovery select Settings
  7. Select Time to display list of operating systems checkbox – change the drop-down to 10 seconds
  8. Select the Default operating system drop-down and change this to “Ubuntu”
  9. Save your changes and re-boot your machine into Ubuntu.

Setting up Postgresql

Our Ubuntu machine is going to act as a database server, a Postgresql one in fact. For those of you not familiar with Postresql, it is a powerful, free, open source relational database and has been around for 15+ years. You can read more about it here.

Your first step will be to install the necessary software on Ubuntu.

Follow the instructions below to set up Postgresql

1. Open Terminal in Ubuntu and type the following command:

sudo apt-get install postgresql postgresql-client postgresql-contrib

2. The above command once it has completed running will have installed all the necessary components to start a Postgresql server on your Ubuntu machine.

3. Navigate via the command line to the following directory:


Note: depending on the version of Postgres you have installed the directory 9.1 may be different. As of August 26, 2012 9.1 is the latest version installed via the apt-get command above.

4. You will now need to edit the postgresql.conf in order to tell Postgresql to listen on the IP address assigned to your new dev machine via DHCP. Using vi type:

sudo vi postgresql.conf

Once you have the file open, edit the following line (you may have to un-comment it, and it will probably be set to localhost):

listen_addresses = 'ip address from dhcp table'

Save the file and exit.

5. We can now login to the “template1” DB that comes setup by default with pgsql

sudo -u postgres psql template1

From here for example we can change the password of the postgres account:

ALTER USER postgres with encrypted password 'my_new_password';

6. We now want to create a test database to serve via HTSQL, to do this we type the following:


7. With our new database created we can add a dummy table and a dummy row of data:

CREATE TABLE temperature (code char(5) );
INSERT INTO temperature (code) VALUES ('12345');

Feel free to add some more test rows.

8. Now we can quit postgresql and edit the configuration in order to allow remote access to the DB. In order to do this, you will need to edit the pg_hba.conf file

Change the configuration to include the following (you can use Vi):

local   all         postgres                          md5
host   all         postgres              samenet            md5

Then save and exit

9. We now need to restart our postgresql instance to pick up the changes, this can be done by:

sudo /etc/init.d/postgresql restart

Once the instance has restarted, we are now ready to make some configuration changes on the Raspberry PI.

Raspberry PI configuration

In order to connect our HTSQL server to our newly built Postgresql DB we need to install some extra packages on the Raspberry PI. First of all you will need ssh into the RPI.

Once logged in, follow the steps below:

1. Install python developer packages and the HTSQL postgres package as follows:

sudo apt-get install libpq-dev python-dev
pip install HTSQL-PGSQL

Once these have successfully been installed you should now see:

Successfully installed HTSQL-PGSQL psycopg2

Now we can connect to the postgresql instance.

2. We can test our connection to the testtemp database we created as follows:

htsql-ctl shell -p pgsql://postgres@host:port/database

The host above should be replaced with the IP address of the Ubuntu server you setup with postgresql installed on it. Also remember to include the port number after the IP address, by default postgresql runs on 5432. The final option is the database we created – temptest.

Once you can log in via the HTSQL shell to the DB instances then you are good to go with actually running a server.

3. Exit out of the HTSQL shell and then create a HTSQL server as follows:

htsql-ctl server 'engine://username:password@host:port/database'

engine should be replaced with pgsql, username and password are those that you set on the DB server, host and port are the DB servers IP address and postgresql port (as mentioned above this will probably be 5432) and finally database is our temptest database.

Once you have started the server you will see:

Starting an HTSQL server on raspberrypi:8080 over temptest

4. We can now check that everything is running as expected. Load up your web browser and in the URL bar type:  http://<ip of raspberry pi>:8080

If everything is working as expected you will see

Welcome to HTSQL!

Please enter a query in the address bar.

5. You can then hit the test table we created as follows:

http://<ip of raspberry pi>:8080/temperature

And see some test data (note I have added a few extra rows to my temperature table of random test data)

1 12345
2 1245
3 56789

6. And that’s it, you now have HTSQL running on the Raspberry PI, pointing to a database server.


The above demonstrates the process of setting up a database server and using HTSQL on the Raspberry PI to communicate with it.  However this is only the beginning of what is required in order to build a system that can record our thermostat temperature data.

Using a prototype is useful for the purposes of ensuring we are building a modular system, where each component can be swapped out as necessary. Now we have demonstrated that we can plug a database into the system, we can concentrate on sourcing the right hardware that will replace the prototype.

Of course whilst our Raspberry PI now runs HTSQL, there is still a lot of work to be done on that end of things. We need to configure the RPI so that it is secure and also build out our controller software – which will use the data stored in the Postgres DB to tune our heating system.

The next steps then are going to be to complete the setup of the Raspberry PI and use our prototype DB server to test this configuration against. Once this is complete we will then concentrate on designing a relational database for the heating data, and building out the server hardware.