A lack of time, not a lack of motivation

Posted on

Unfortunately since my last update I have done very little with everything. Life does get in the way, but I am still very interested in learning more, which is something. I did however purchase a proximity sensor and got it up and running with my spark.io which is quite cool,  I did think about having that at the end of my hallway to turn on the philips hue when it detects movement. I will post the code and whatnot later on.

Another day, another pi

Posted on Updated on

So my second raspberry pi has stopped working, and this time I don’t think I am at fault. The symptoms were just a single red light with no ok green light or anything else. HDMI out did not work and it was just…. dead. Reading online, the red light with nothing else indicates that it is not reading the SD card, so I tried another without success. I confirmed that the SD card was fine so through excellent deductive reasoning it must be the Pi. Oh well, time to purchase my 3rd Pi.

I also decided to do some soldering. I bought a pi cobbler a while back, it essentially allows you to connect your raspberry pi gpio ports to a breadboard for easy working. I was quite impressed with the overall result

pi cobbler soldering

In slightly related news, I signed up for a couple of courses from coursera.com they are free online courses which I decided to give a go.The courses I went for were fundamentals of electrical engineering and Programming Mobile Applications for Android Handheld Systems and both of them started this week. It then transpired that the level of mathmatics you actually required for electrical engineering was far above my head, while I could understand small parts this is not very encouraging when you are in the first week. So I dropped that course, intending to take it at a later date and have signed up to Calculus One instead. Hopefully that will give me what I require.

As for the android course, I thought it would be good to learn something which could help me program and might have some greater use later on.

I will have another update shortly showing a motion detector that I bought and connected up to my arduino and spark core. Exciting times!


Brief Update part 2 – Spark.io and wifi plug

Posted on

Having built the relay I have not done anything with it yet, mainly out of apprehension that I am going to blow myself up with 230volts. Despite that I will press on with the question ‘how can I remotely control the relay?’

Enter spark.io which is essentially a wifi enabled microcontroller based on the arduino language (which is just a subset of c++)

I received my spark core last night, in a very fancy box with loads of extra goodies to play with. Quite a nice haul all in all!

spark core on a breadboard
spark core on a breadboard
spark core with all the stuff I received
spark core with all the stuff I received

The spark core is controlled from the internet, it has an online area for programming and flashing the unit so once you have connected it to your wireless network it is ready to go.

First things first, make a little blue LED on pin D7 flash.

int LED = D7; //initialise an integer called LED and assign it D7

void setup() { //this is the initialisation routine
    pinMode(LED, OUTPUT); //set up pin D7 as an output
 Serial.begin(9600);//this enables the device to appear on a connected computer

void loop() { //this method loops around forever
    digitalWrite(LED, HIGH); //set the LED high i.e. on
    delay(100); //wait 100 milliseconds
    digitalWrite(LED, LOW); //set the LED low, i.e. off
    delay(1000); //delay for 1 second

With this spark I could connect the relay and wire it in which I could then get my phone to send a command to trigger the relay and that will enable the plug

The second item I bought is a wifi enabled plug. Ingeniously called wifi plug I have not received this yet but there is an API available that should also allow me to achieve the same goal.

Now I am not a programmer by any means. I want to understand everything so that is something I must get into. Frankly pointers and all that in C has been a bit of a mystery but hopefully with time and effort I will get there.

Now the next steps really are to wire up more than just a single LED to the device, but I am not sure where.

I also signed up for an intro to electronics course at coursea it is a free course which hopefully will give me some further insights.

Now I just need to have some time to do all of this!

A minor victory with electronics

Posted on

Quick update. Four things I have learnt this evening

1) Never solder unless you are absolutely sure
2) Measure more than twice before you commit
3) Even if you measure, it doesnt mean it will actually fit
4) I am not very good with DIY

item 1 on my list is to do with electronics, items 2,3, and 4 are to do with some DIY I just attempted, and while it came out ‘okay’ it is not fantastic

Nevertheless I have had a minor victory with the electronics side so I am happy.

Thinking about home automation, originally I had planned to use z-wave devices, which is a wireless protocol which is baked into a fair few devices. The advantages are that you don’t really need in-depth electronics knowledge, just a bit of programming and you are done. The disadvantage is that because home automation is not popular with the masses, it is expensive.

I decided therefore to try and put my electronics stuff that I am learning to some use before I commit fully to z-wave devices.

A relay in electronics term is a bit like an electronic switch, but rather than completing one circuit, you are actually completing two separate circuits. It is difficult to explain, but imagine you have a simple battery connected to an LED, once that circuit is complete it will light the LED (assuming you have a resistor to not blow it up). Now imagine there is another circuit with a light dependent resistor on it which is waiting for a light source. Once the LED of the first circuit is on, the resistor on the second one drops its resistance and the second circuit is completed. That is essentially what a relay is (well it is exactly one type of solid state relay), except most of the time it is mechanical.

Because of this it is possible to control a 230v circuit, i.e. a lamp at home with a simple 5v arduino board.

I purchased this relay from proto-pic to see firstly if I could actually solder anything without burning myself or totally messing it up and secondly if I could actually control my lamps at home using either my arduino or raspberry pi.

I spent the best part of an hour soldering all the components on the board, and while it was difficult as the resistors and everything are so small I actually managed to solder everything correctly. Well everything except the LED. If I have not stated this before, the short leg of the LED goes to ground.

Proof that I got it to work

relay connected to the arduino
relay connected to the arduino

now the first time round, the LED didnt work. But the advantage of the giant relay in the middle is that you can tell if a connection has been made because you hear an audible click where the mechanical switch has clicked in on the 230v side.

I simply (hah!) de-soldered the LED and put it round the right way, and the results are what you see.

On the 5v side there are three inputs, corresponding to the 3 terminals of the transistor on the board. There is the positive 5v, the ground (which is negative) and the control. The control is what you use to determine whether the circuit is open (off) or closed (on). By having the control set to on, you are allowing the transistor to get over the resistance of the chemical inside and have an electron flow. Without that additional push, the 5v is not sufficient to bridge it. That is what I think happens anyway (I think it is an NPN transistor).

In the above picture, I simply had a wire going from control to the 5v so that the circuit was always on and I didnt have to program anything. On the arduino side I had one wire going from the 5v to the aforementioned 5v and control on the relay board, and then on the ground I had it going to one of the GND ports on the arduino.

That is as far as I have managed to get this evening. When I am feeling brave enough to deal with 230volts I might take it one step further. But one thing I have to also do, is make either the raspberry pi or the arduino take an input from the network to trigger the relay and somehow not blow myself up in the process! Fortunately I have something on order that should help with that 🙂

Brief update – tasker, lampshade.io and hue

Posted on Updated on

It has been a while since I posted, almost 2 months. Insert usual excuses here, been busy, been on holiday, etc.etc. I have not been that complacent however with looking at various home automation bits.

I ended up blowing 2 power supplies for my raspberry pi. I have an LED string (more information on this later) which was being powered by a 2A 5v power supply along with my raspberry pi but it transpires that I was drawing too much current. With 50 LEDs at a maximum of 60milliamps each that is a whole 3amps just for the LEDs! No wonder I blew up the supplies as I was drawing far too much current. I then purchased http://www.ebay.co.uk/itm/330958739671 which is a 50watt (so 10amp) 5v powre supply for them. So far so good, nothing has blown yet. Although I wont leave home with them turned on.

In other news I set up a tasker profile on my android phone. Tasker is an amazing app for android which allows you to trigger events based on conditions occurring. The equivalent for iphone is IFTTT (if this then that).

At the moment I have two profiles which are of use,

1) Turn on the hue lights when I get home. I might have gone over this before but I will expand on this. For this you require ssid selector as well as lampshade.io

Profile > State > wifi near > the ssid of your wireless network
Task >
SSID selector > the ssid of your wireless network
Tasker > Wait 999 miliseconds (this is because it takes a while to authenticate on your network, it is not instantaneous!)
Plugin > lampshade > configuration > all @ 100%

This then sets the bulbs on. I am going to alter this when I get the hue via the website working to be a gps location as it takes a while for the bulbs to actually come on whereas I would like them to come on when I am approaching home.

2) Flash the bulbs when a phone call is incoming
Profile > Event : Phone Ringing
Task >
Plugin > Lampshade > Group: All, Mood: Red Alert
Wait > 7 seconds
Lampshade > Group: All, Mood: Relax @ 100%

In lampshade.io I have two moods, red alert is an flashing red light, and relax which is just a calm one for the lamps to go back to. It would be nice to go back to the previous state they were in, which I might do at some point as it would require reading from the bulbs their current state and then going back which I think is beyond the current ability of lampshade.io to set via tasker.

Electronics wise I have not done much however, although I am planning to look at a relay with the arduino/pi later on in the week. A relay is essentially a switch for another circuit. Basicaully you can have a 5v DC circuit control a larger 230v AC circuit depending on whether it is on or off. My plan is to use the arduino to control whether my sidelamps are on or not.

I also plan to use Eagle to show some schematics of the stuff I am making.

Pi in Technicolor (TM)

Posted on

If like me you are a masochist, then vi or vim is the best text editor to use on linux. There are zillions of commands and I know roughly 3, but to make life easier when coding you can get vi/vim to show up text in lovely colours.


To do this run 

 sudo apt-get install vim 

then edit .vimrc in your home directory (either /root/.vimrc or /home/pi/.vimrc or whatever really) and put in it

 syntax on 





Vi and Vim in colour
Vi and Vim in colour

Frying the Pi Part 2

Posted on

So it transpires that I have blown the polyfuse on my old Revision 1 Raspberry Pi, although the potential difference (read voltage) across the fuse F3 is only around 0.3 volts there is no voltage going to the rest of the board (0.1 volts minimum needed is about 4.6) and the power LED comes on very dimly to begin with and then goes out. As soon as I short the fuse the power LED comes on.

So the revision 1 now can become a proper testbed, just need a soldering kit to play around with it!

The siblings
The siblings

So there is the revision 2 I purchased with 512megabytes of RAM and the Raspberry NoIR camera that I purchased but never got around to putting on. I also bought a new case for the second one off of amazon. Bit fiddly but I quite like the clear perspex and it is easier to do stuff with it.

To get the camera working I follow the tutorial on the official website

As root is disabled by default, if you want to run in the context of the administrator, you use sudo.

Either you can do

 sudo -i 

This puts you into a root style shell where you can run the commands

or you can do

 sudo apt-get upgrade 

This would run only this command in the context of root

because I am lazy, I always use sudo -i

Anyway to take a picture, just do

raspistill -o filename.jpg

it takes a few seconds to take, but the quality seems reasonable

Baldy heed
Baldy heed

There is my lovely face (read: urgh) taken with the camera. The colours are a little off as there is no infrared filter on the camera. I am hoping to create a lizard cam with my leopard gecko who is nocturnal so this would be a good way to use some infrared LEDs to catch what the Missus does late at night.

Frying the Pi

Posted on

I have not updated this in a couple of weeks. It is not because I am bored of it already, quite the opposite in fact. I have been playing around with various components and buying loads, too much in fact!

The raspberry pi is a great piece of equipment, it is very well built and the options you can have on it are great. Programming an LED to light from a button push though is still too complex, with lots of libraries required, SPI interfaces and whatnot. It is not intuitive (at least to me) to work out what is actually happening physically.

So I bought an arduino. Bought from here

An arduino is an open source piece of equipment, which I think is absolutely fantastic for the price. True it is quite significantly simpler, but I think that is a good thing. There are lots of examples where you program in C++ which is as close to the machine level as you can get without programming in assembler (which I intend to do at some point).

I am getting to grips with all the pull up/pull down resistors, how it is reading an input, what is happening with an output all that kind of good stuff. The next post hopefully in a few days will highlight this further along with some pictures.

I also decided to get a gertboard for the Pi which is also a great bit of kit. It allows you to have physical LEDs, switches, an ATMega controller (the same one on an arduino, so you can actually program it the same way if you want), a relay and more. Unfortunately the Pi, gertboard and me didnt exactly get on well and I managed to cause the Pi to stop working a few times.

Interestingly in this process I learned quite a lot about how the Pi powers itself.

One of the first components (if not the first) is a polyfuse called F3 on the underside of the Pi (pictures to follow). Now I had no idea what a polyfuse is, but it is a very cool fuse. It is a chemical fuse which when there is too much current going through it heats up. When it heats up it starts to chemically break down and so the resistance goes up, causing it to heat up further. It carries on until the circuit is broken or you stop supplying current. When it starts to cool down over the course of a day or two, the chemicals start to reform and so the circuit is reformed once again lowering the resistance.

The standard potential difference across the fuse is about 0.3 volts. You supply a 5volt feed to the Pi, and lose about 0.3 across the polyfuse meaning there is about 4.7volts available to the Pi. If the polyfuse resistance goes up, the potential difference across the fuse increases to the point where the Pi no longer works (and you get a burnt finger if you touch it). At about 0.35-0.4volts the Pi will no longer work correctly. Leave it a couple of days and providing you have stopped the short that you were causing it should be fine.

You can use a multimeter on the DC option (20v on the one I was using) to check how many volts are being lost across the fuse by touching both ends of the fuse and measuring.

I also managed to in the process wipe the SD card I was using, almost losing everything. Good thing I had some reasonable backups and this blog to recreate everything I had!

The Spark

Posted on

What caused all this fascination with how things tick?? I am glad you ask. I present to you, exhibit A


That lovely little one is my pet Leopard Gecko called Selma, also affectionally referred to as The Missus (TM).

Being an avid fan of kickstarter I was perusing one day, like I do on most days and came across this project Brewbit wireless PID controller as well as an earlier project which unfortunately did not get funded Moore’s cloud light both of these are projects which allow you to make things more intelligent in one way or another. The brewbit is all about temperature control, and lizards like to have their temperature toasty! The Moore’s cloud light was about making a standard light interactive more than just turning it on or off, and I really liked the idea of being able to change the colour, have it respond to events and do cool stuff with it. These ideas are all well and good, but the people that are building these devices have something that I lack (well quite a lot of things that I lack, but I will ignore the rest of them) and that is knowledge of how hardware and software work together. How do you create a simple circuit board which you can use to do various items? Beats me at the moment, although hopefully I will be enlightened.

One of the most basic parts of a computer are gates. The idea is than an output is derived from a set of inputs and depending on those inputs determines what you get out of the gate. There are many different types of gates, simple AND gates, which work in the way “if I have two inputs I will get an output” or an OR gate “if I have either input or both I will get an output”, but then you get into more difficult gates such as XOR which is an exclusive OR, simply put “I can have one input or another but not both”.

By using gates you can build up a rudimental system for taking input and having an output. I have been using the electronics set to slowly expand my knowledge, and right now I am onto transistors which are in the basis of gates as far as I can tell. Transistors are useful in a wide variety of ways, for example you can use a transistor to amplify the current you are delivering.

My next stage will be to get some gates actually hardwired.

Fun with Hue Part 2

Posted on

So last post on this topic I managed to fit them around my flat. I used lampshade.io to rename the bulbs and play with them. It has some default scenes and whatnot but I wanted more (as always). I did some looking on t’internet, and found phpHue this is quite a simple set of php pages which can control your bulbs. There were alternatives but they seemed very complex and a bit over my head at this point.

Using phpHue I was able to work out what was happening and start to be able to do my own stuff with it. For example I wrote gradual.php



        $target = 3;
        $command = array('bri' => 0);
        echo $command[0];
        setLight($target, $command);
usleep (100000);
        do {
        for ($i = 1; $i <= 254; $i = $i + 10) {
                echo $i;
                $command = array('bri' => $i);
                setLight($target, $command);
        } while (true);

This sends to bulb 3 (which is in my case the lounge light) and makes it get bright and dim reasonably quickly. As shown in the youtube vid in my previous post.

The way philips hue works is by sending json commands. Now as I have stated previously I am not a coder, but I am able to understand various bits and pieces and normally can munge stuff around.

Fortunately there is some good instructions on the philips hue developer site here An example of getting the status from one of my bulbs to see whether it is on in the image below

Checking the status of the bulb
Checking the status of the bulb

To do this you need to set up an account on the Hue so that you can access it using this as part of the url. As you can see I have set up an account called newdeveloper. To do this follow the instructions here