Category : Technical

Raspberry Pi P6 Reset Hack

I’ve been trying to get some code running on my Pi 2. The code has been ‘problematic’ to get working, and I’m running into frequent hangs on the Pi where I cannot initiate a new SSH or console session. It’s also complicated because the Pi is outside in the garage (I have a GPS hooked up so it needs some visibility of sky). That means that every time it hangs I have to head out to the garage, pull the micro USB cable, reinsert it and then start the whole ‘Edit, Compile, Run, Head out to the garage to Reset’ cycle again.

Anyway, in an effort to simplify things I was looking around for a way of remotely resetting the Pi without having a connection to it. I found a ton of sites talking about the P6/RUN header on the newer boards, but this was mostly just about adding pins to short out with a jumper or adding a momentary switch to do the same. What I wanted was something more like connecting an Arduino pin, or a pin from another Pi to the P6/RUN on the target Pi and forcing a reset that way. What I wanted was a “Raspberry Pi P6 Reset Hack” – unfortunately AdaFruit don’t sell a kit for that.PiP6PullUpResistor

I was initially concerned about the current that the watchdog Pi would have to sink on the GPIO0 pin, but looking at schematics it seems the RUN pin is pulled up to 3.3V by a 10K resistor – a little bit of Ohms law says this will mean 3.3v/10K = 0.33mA will flow, well within the recommended limits of the GPIO pins 2mA to 16mA

I have an ESP8266-12 laying around just waiting for this kind of thing, but for the sake of speed I opted for another Pi I had (already hooked up, working and configured). So this essentially came down to :

  • Solder header pins on the target Pi (the one to be reset)
  • Connect the grounds of the target and ‘watchdog’ Pis together
  • Connect a GPIO pin from the ‘watchdog’ Pi (GPIO0) to the RUN pin on the target Pi
  • Putting together a small app to force the GPIO0 pin low for a few milliseconds and then high again.


For the app to be run on the ‘watchdog’ Pi, I’m making use of the excellent wiringPi library. Instructions for downloading and building it can be found at
The code for ‘reset-app’ is simply (nano reset-app.c):


#define <wiringPi.h>
int main (void)
    pinMode(0, OUTPUT);
    digitalWrite(0, HIGH);
    digitalWrite(0, LOW);
    digitalWrite(0, HIGH);
    return 0;

… then to build it just execute :

sudo gcc –Wall –o reset-app reset-app.c –lwiringPi

Now when my target Pi hangs I can just ssh into the watchdog one, and run sudo ./reset-app and the target Pi reboots.
Also, when I’m done with this testing/hanging stuff I may simply connect a switch to the header for ‘’future ‘just-in-case’ things…


This is a QuickAndNasty™ solution. I am not responsible for any damage to your Pi, your electrics, your health or anything else – anything you do as a result of reading this is at your own risk.
Using this to reset you Pi can result in SDcard corruption !!   All calculations are off the top of my head, and could be wrong.

There are a ton of things to improve it also:

  • It relies on the GPIO pin on the watchdog ‘floating high’ while it is an input – it really should be set as an output (HIGH) at startup.
  • I’ve not tested what happens when the watchdog Pi reboots – there’s a chance (likelihood?) that it will reboot the target Pi.
  • The ‘reset-app’ can be improved (drastically!!)

EDIT: I have tested what happens when the watchdog Pi reboots and, for me, it does not reboot the target Pi – however there is a chance (likelihood ?) that it will reboot the target Pi.
Anyway – enjoy, and let me know if you found it useful….

Git – Push to a new remote server repository

Short reminder to myself on how to create a new server repo and do the initial push to it from a workstation.

On the Server:

cd Repositories
mkdir Project.git
git init –bare

On the Workstation:

cd Project
git init
git add *
git commit “Initial commit”
git remote add origin
git push –u origin master


Baking Pi – Part 2

The first part of this ‘getting things up and running’ series can be found here.

In this post I wanted to outline what was required to set up Wi-Fi and to get a Microsoft LifeCam 6000 working, providing a web page with the camera image streaming.

So, Wi-Fi… I bought a £6.99 USB Wi-Fi dongle from eBay. After plugging it in and rebooting the Pi I opened a SSH session to it and typed ‘lsusb’ This lists all the usb devices, and I could see the Wi-Fi adapter in the list as a Ralink RT5370.

First thing was to get the drivers – doing an ‘apt-cache search ralink’ found me the correct package (firmware-ralink). On issuing ‘apt-get install firmware-ralink’ it told me that the version I had already up to date – great it seems the Raspbian ‘Wheezy’ image comes with it installed.

So, it was just a case of setting the Wi-Fi options and giving it an IP address (static). I do this directly in the interfaces file. So…

  • From the command line run sudo nano /etc/network/interfaces
  • Change "iface wlan0 inet dhcp" to "iface wlan0 inet static"
  • below this add…
  • address
  • netmask
  • gateway
  • also add the following Wi-Fi options
  • wpa-ssid YOUR_SSID
  • wpa-psk YOU_KEY
  • wireless-power off
  • Now reboot (sudo reboot)

You should now have a Wi-Fi enabled Pi.

lifecam6000For the webcam, things were a little trickier… A lot of people are using ‘motion’ for setting up security cameras, as it does motion detection and can spit out images or movies when some motion is detected as well as do time-lapse and provide a web based video stream for viewing in a browser. However, this was overkill for what I had in mind (just simple streaming of the video), and it also uses a lot of horsepower.
So instead I selected mjpg-streamer, an open source project hosted on SourceForge.

There are no prebuilt binaries for the Pi, so it’s a case of building it yourself – not too difficult…

First get all the dependencies…

  • sudo apt-get install libv4l-dev
  • sudo apt-get install libjpeg8-dev
  • sudo apt-get install imagemagick

I tried installing subversion to check out the code, but the svn urls have moved around and it wouldn’t let me do a checkout as it couldn’t find the correct url, so instead I just downloaded the zipped tarball and extracted it…

At this point I tried to do a ‘make’ but it failed stating it could not find linux/videodev.h. A bit of noodling around found that I had a videodev2.h file, so all that was needed was a symbollic link.

  • ln –s /usr/include/linux/videodev2.h /usr/include/linux/videodev.h

Now to build it…

  • make clean all

I did get a few error towards the end, but the key elements built correctly (I think it was just a plugin or two that failed to build, so I simple glossed over that).

Now you can start the application manually with the following command line:

  • ./mjpg_streamer -i "./" -o "./ -w ./www"

.. but what we really want is to start it automatically when the Pi boots so…

  • sudo /etc/init.d/webcam

… and add the following text to it…

# Provides: mjpg-streamer
# Required-Start: networking
# Required-Stop:
# Default-Start: 2 3 4 5
# Default-Stop: 0 1 6
# Short-Description: Starts mjpg-streamer
# Description:

#! /bin/sh
# /etc/init.d/webcam

# Start / Stop the webcam streamer
case "$1" in
    echo "Starting webcam streaming"
    /home/pi/mjpg-streamer-r63/mjpg_streamer -o "/home/pi/mjpg-streamer-r63/ -w /home/pi/webcam/mjpg-streamer-r63/www" &
    echo "Stopping webcam streaming"
    killall mjpg_streamer
    echo "Usage: /etc/init.d/webcam {start|stop}"
    exit 1

exit 0


Now the final touches of making it executable and making sure it get started…

  • sudo chmod 755 /etc/init.d/webcam
  • update-rc.d webcam defaults

.. and the final part is of course viewing your handiwork – so open a browser and type :8080">http://<your_pi_ipaddress>:8080 and you should be able to see the webcam image.


Pi Track – Overview

One of the things I’d been planning on since buying the Raspberry Pi is putting together some sort of robot (for the kids benefit you understand…)

Whilst the Pi does have a bunch of GPIO pins that can be used to interface to motor boards and sensors, the fact it runs on 3.3V and is so sensitive to incorrect voltages  has made me reluctant to interface directly from the Pi to other hardware.
Also the Linux OS isn’t great for some of the time sensitive stuff needed for robotics. I could have run a real time OS on it instead of Linux, but instead I thought I’d have it do the ‘intelligence’ and delegate the simple the motor and sensor control to an Arduino.

So I bought an Arduino Nano (V3.0) – this is a great little device, mini USB input to power and communicate with it, 20 odd IO pins and the like, and the IDE and development software that comes with it make it real simple to get started.
Add to that, the fact you can pick them up for around £10 and it’s a no brainer…

Anyway, I had a play around with both and got them talking to one another over I2C and all was good. At first I had jumper wires all over the place, but I had a spare ‘Humble Pi’ prototyping board so I used that to hardwire a Arduino slave connected to the Pi master, so now I have the best of both worlds…

I also took delivery of a Dagu Rover 5 tracked robotics base, connecting that up to a H Bridge motor controller and driving the H Bridge from the Arduino (based on commands send from the Pi over I2C) all worked without a hitch.

The ‘sketch’ I wrote for the Arduino is pretty simple, it sets the Arduino up as a slave on a particular address and when sent commands reacts to the (‘f’ for forward, ‘b’ for backwards, etc.)
On the Pi side it is a simple bit of C code that waits for user input and sends it over the I2C channel (making use of Gordons wiringPi library).

The outcome, this evening, was a robot that can now move in response to user commands from the Pi SSH session.
I’ll go into more detail about the wiring interconnect and the code for the Pi and Arduino in a future article, but for now here are some images:

2013-08-21 21.21.47    2013-08-21 21.23.17

Here is a view of the Arduino daughterboard thing I hacked together…

2013-08-21 21.23.43

I purchased a couple of Ultrasonic sensors from eBay (around £2.50 each), so future plans include some kind of distance measurement, obstacle avoidance and more autonomy for the bot, rather than ‘remote control’ via a SSH session.

Watch this space for more details…

Baking Pi – Part 1

After starting with a Raspberry Pi that was just too simple to set up as XMBC media centre for daughter #1 bedroom, it soon became a permanent feature there – meaning, of course, that I needed another…

I now have my second helping of Pi – again I got a Raspberry Pi Model B (512MB RAM).

I’m running this mostly headless and wanted to post a few pointers on my setup (so I can recall it when I trash the Raspbian OS and have to restart from scratch.

After a standard Raspbian install I am doing the following actions / configurations :

  1. Basic configuration via raspi-config
  2. Setting a static IP address
  3. Updating all packages
  4. Adding a custom port to listen for SSH on (for remote access through home router)
  5. Setting up vsftpd

Here is the step by step guide:

Basic configuration via raspi-config

  • Make an SSH connection to the device and login (pi / raspberry)
  • From the command line run sudo raspi-config
  • Upgrade raspi-config
  • Configure as required.

Setting up a static IP address

  • From the command line run sudo nano /etc/network/interfaces
  • Change “iface eth0 inet dhcp” to “iface eth0 inet static
  • imagebelow this add…
  • address
  • netmask
  • gateway
  • Now reboot (sudo reboot)

Updating all packages

  • From the command line run sudo apt-get update
  • From the command line run sudo apt-get upgrade
  • Now reboot (sudo reboot)

Adding a customer port to listen for SSH on

  • From the command line run sudo nano /etc/ssh/sshd_config
  • Add a line under where it says Port 22
  • Type Port xxxx on the new line (where xxxx is your desired additional port number)

Setting up vsftpd (FTP Server)

  • From the command line run sudo apt-get install vsftpd
  • Now edit the config file to change the port is listens on
  • From the command line run sudo nano /etc/vsftpd.conf
  • Under the line that reads listen=YES add the following lines
  • listen_port=xxxx (where xxxx is your desired port)
  • pasv_enable=YES
  • pasv_min_port=yyyyy (where yyyyy is the lower range of ports you want it to use)
  • pasv_max_port=zzzzz (where zzzzz is the upper range of ports you want it to use)
  • Now restart the vsftpd service with sudo /etc/init.d/vsftpd restart

All done. The Pi is now configured to allow SSH and FTP access on custom ports (with corresponding holes through the firewall to allow external access). Enjoy…

Starting with a Raspberry Pi

I eventually got round to ordering a Raspberry Pi Model B (512MB RAM). As you probably know this is a £25 ($35) computer running a 700MHz ARM processor and capable of decoding displaying HiDef 1080p video.

I got one to experiment with as a media player for daughter #1 room, so she could watch the videos / DVDs I’ve ripped to the home server. It took around 30 minutes to realise exactly how easy this would be and how powerful these little babies are.

I wont go into detail, but to get XBMC running on it is a case of downloading the SD card image, writing to the card, plugging it all in and off you go. Testing it on my main TV, I found that I could even control XBMC from the TV remote (CEC over HDMI) – however on daughter #1 TV that didn’t work so I bought one of these remotes : GMYLE® Windows 7 Vista XP Media Center MCE PC Remote Control and Infrared Receiver for Home, Premium and Ultimate Edition : plugged in the IR Receiver and it all worked seamlessly – amazing ‘out of the box’ experience.
I also bought a pink (Raspberry) case with a VESA mount that allowed me to mount it on the back of the TV : Case for Raspberry Pi with adaptor to fit to VESA 100 Monitor – Raspberry Colour

Anyway, it was so easy to use and so well received it is now in constant use – so I needed another to play with… which I also bought. This one I shall be using for projects (robotics with son #1 and fun programming with son+daughter). I’ve already ordered powered USB hub, case, cables, USB sticks and SD cards, as well as a GPIO breakout cable for linking up to a breadboard. Watch this space…

Multiple Machine Configuration

If you are anything like me you’ll find yourself using a number of different PCs through a typical week. I have my work laptop, my work Dev machine, my home PC, my netbook and some semi permanent virtual machines that I have. It can be a bit of a pain keeping my standard installed apps updated across all of these.

I’m getting too used to my Android phone and Tablet auto updating their apps with little or no interaction – what I wanted was the same for more of the apps I use on the various PCs I use.
I haven’t quite got a full solution for it, but I do have a big step toward it – Portable Apps.image

Portable Apps are pretty good at keeping themselves updated, but the pain is the configuration. For example when I add a command to Executor (my launcher of choice) I had to update it on all machines, same with adding a new site to the Filezilla Site manager or Putty – it needed to be updated across all machines.
I could of course store the Portable Apps on a memory stick and carry that everywhere – but then the challenge is – carrying it everywhere.

So I have a solution that brings the ease of Portable Apps with the omnipresence capabilities of my free 25GB SkyDrive account (but you could use any file sync/share application).

imageI have a folder in SkyDrive that I have installed my chosen Portable Apps to, so they turn up on every machine.
I also have an install folder with tools and scripts that I run on each new machine that I install SkyDrive on that gives me common locations for the apps (regardless of the user I am logged in as), updates the PATH variable, adds apps to the Start folder and the like

The script does a number of things :-

It creates symbolically linked folders so I can go to c:\apps instead of c:\users\kenh\skydrive\apps (or different usernames on each machine)

rmdir c:\tools
rmdir c:\apps
rmdir c:\scripts
mklink /d c:\Tools "%userprofile%\SkyDrive\Tools"
mklink /d c:\Scripts "%userprofile%\SkyDrive\Scripts"
mklink /d "c:\Apps" "%userprofile%\SkyDrive\Apps"

It adds some data to the registry

regedit.exe /f CommandPromptHere.reg

It uses a tool called xxmklink (from the makers of xxcopy) to add a shortcut to Executor to the start up folder so that it runs every time Windows starts.

xxmklink "C:\ProgramData\Microsoft\Windows\Start Menu\Programs\Startup\Executor.lnk" "C:\Apps\PortableApps\Executor\Executor.exe" "" "C:\Apps\PortableApps\Executor"

It starts some applications

START "C:\Apps\PortableApps\Executor\Executor.exe"
START "C:\Apps\Start.exe"

And the final thing it does (currently) is to update the PATH variable using pathman.exe

pathman.exe /as c:\tools

This makes my life much easier, I can be the same kind of productive regardless of the machine I am working on – they all have the same configuration, versions of software and paths, and the best bit is that when Portable Apps updates itself on one machine, it is reflected on all others within a few minutes.

I need to look at how I can extend this further, with introducing more portable apps to replace heavyweight desktop installs. I’ll keep you updated.

New Gmail Design

imageOkay, so I like the new Gmail design – cleaner and more whitespace – just looks much more modern that the existing one.

But it’s still bloody annoying !

The thing is, I hate having to go across to the little ‘back arrow’ reply icon, click the dropdown next to it, just to get to the ‘actions’ I can carry out on an email.

‘Forwarding’ is two clicks when I simply want a single click for it. I’m surprised no one has come up with a greasemonkey script that does this – maybe I need to stop whinging and write myself one.

Microsoft do a good job in the old Outlook Web Access (2003 and 2007) and in the newer Outlook Web App (2010)


What do you think ?

CurrentCost Power Monitor Software

cc128-large_01 I recently bought a device to monitor our household energy consumption. After looking at a few I lumped for a CurrentCost Envi. this is a great little device that comes in two parts – a transmitter with jaws that wrap around the main power cable coming into your home and a desktop display unit. The communication is all wireless and I have found that it works okay through two thick brick walls.

the reason for going with this particular unit was that it has a data port that can connect to a USB port and feed it’s readings to a PC – I wanted to be able to monitor the readings on my PC and chart/analyse them at will.

imageThe communication to the PC is basically via USB, but emulating a serial port COM connection – the CurrentCost website has links to the drivers you’ll need for this.

I wanted to, not only, record the readings but to chart them (on my website), get regular updates via various notification methods and a few other bits. Unfortunately, none of the software applications listed on their website covered all the items that I wanted – so I set about writing something myself…

My initial thoughts were around just sending the data to Google PowerMeter, but at that stage the API was not public and their forums/groups were not very active (6 posts in about 18 months), so I abandoned that and decided a ‘DIY’ approach was needed.
UPDATE: It looks like there may be some substance to it now, so that is another area to look at (another plugin)…

imageThe requirements were pretty simple – I wanted a service that grabbed the readings as they came in, decoded them into something intelligible and then pushed them out to a number of ‘modules’ that would do something with the reading. the ‘modules’ would be self contained and new modules could be added at any time. The initial modules would be :-

  • Tweet the reading at a regular interval
  • Record the reading (in a database, Xml file or the like)
  • Send the reading to a website / webservice

It seemed a simple Windows Service with a COM port would be enough to grab the reading, the readings are all in Xml so another class to parse the Xml would be needed and then for the ‘modules’ a ‘plugin’ type architecture was called for. I came up with an interface that all plugins would implement and a method of loading them in dynamically.

Each plugin would inherit from the IPowerMonitorPlugin interface and to load the plugins, each one would be specified in the app.config file with a filename and classname. The service would look at each plugin entry, load the DLL and create an instance of the plugin class :-

    private void LoadPlugins()
        plugins = new ArrayList();

        NameValueCollection appSettings = ConfigurationManager.AppSettings;
        foreach (string key in appSettings.AllKeys)
                string path = AppDomain.CurrentDomain.BaseDirectory;
                string[] config = appSettings.Get(key).Split(':');
                Assembly ass = Assembly.LoadFile(path + config[0]);
                IPowerMonitorPlugin plugin = (IPowerMonitorPlugin)ass.CreateInstance(config[1]);
                if (null == plugins)
                    plugins = new ArrayList();
                if (!plugins.Contains(plugin))


When the service was working and decoding the readings correctly, I started adding plugins – first was a simple ‘RawXmlWriterPlugin’ – this simple wrote the raw Xml reading data (Reading.RawXml) out to a text file – just to make sure it was working and we were decoding the Xml correctly.

imageThe next service was posting the data to a website – I found this great website ( which allows you to track environmental data measurements, have multiple feeds, multiple measurements and has a lot of options for getting data in and out. The API that they provide is pretty simple to push data into and their website allows plenty of ways to visualize the data – for example here is a link to my last 24 hours energy consumption in a chart format, here is my latest temperature reading and here is an archive of all the energy data I have ever posted. there are also mash up to things like iGoogle widgets, Google’s Visualization API, Google Sketchup, iPhone Apps, Android Apps and this rather neat gauge.

From there I started the Twitter service….



The plugin for posting to Pachube requires that you have already create a feed with two datastreams (datastream 0 is energy and datastream 1 is temperature). You will need an API Key and the feed id. Both these items are configured in the app.config file also.


The plugin for ‘tweeting’ to twitter is also pretty simple – all you need is an account (username and password) and the ‘handle’ of the person/account you want to send the message to (if you want to send a direct message). You also specify the message text you wish to send (with placeholders for the energy and temperature values) an the interval (in minutes) of how frequently you wish to send the tweets.

SQL / Xml Storage Plugin

Watch this space … 😉

Source and Package

For the time being either send me an email or post in the comments if you’d like access to the source code.

If you want to run this software yourself then here is a link to a zip file containing the full package. To get it installed, do the following :

  • imageUnzip the package contents into a folder (“C:Program FilesPowerMonitorService” would be good)
  • Open a command prompt and change to the folder above
  • Run the following command line…

“C:WindowsMicrosoft.NETFramework64v2.0.50727InstallUtil.exe” PowerMonitorService.exe (if you are running a 64 bit machine… or)
“C:WindowsMicrosoft.NETFrameworkv2.0.50727InstallUtil.exe” PowerMonitorService.exe (if you are running a 32 bit machine… or)


  • Open the PowerMonitorService.exe.config file (in Notepad) and edit your configuration as needed – save when done.
  • Now start the service (, find the one named PowerMonitorService, right click and choose “Start”)


GEO 51.4043388366699:-1.2875679731369

Install Windows from a USB Drive

USBdriveThis post is for my own benefit more than anything. I frequently have to ‘google’ for the instructions to make a bootable USB drive to install some version of Windows from. So, to save time in the future, here are the instructions :

Open a command prompt As Administrator. Run diskpart. Enter list disk – this will list all the attached disks, make note of the USB drive disk number (2 in my case, so substitute 2 in the commands below for whatever number it shows on your system :- image

  • select disk 2
  • clean
  • create partition primary
  • select partition 1
  • active
  • format fs=fat32 quick
  • assign
  • exit




GEO 51.4043388366699:-1.2875679731369