A sheared bolt and a mini adventure

On Thursday night last week my charge light didn’t go out. Since it was very wet I just assumed it was down to a slippy fan belt and decided to fix it at the weekend, provided the never-ending rains let up.
2014-02-16 15.02.07
After a huge fry-up at the farm, daughter and I set about fixing the problem – which turned out to be caused by the alternator completely snapping off! The 200Di conversion involved making a custom alternator bracket. Though the bracket itself is made from 10mm sheet steel welded to a chunky steel tube I made on the lathe, the weak spot is the M8 bolt which runs through it. This bolt had sheared off, leaving the alternator hanging loose. Luckily the fan belt didn’t fall off on the way home and I didn’t drive far enough to overheat the engine (the water pump must have stopped working as a result of the belt going slack).
2014-02-16 15.18.37
In the end I used a length of threaded bar instead of the stainless set screw that Emma is holding in the photo. Hopefully this will last a bit longer; stainless steel being notoriously brittle.
2014-02-16 16.39.27
I wasn’t allowed to start the engine “unless we’re going on a journey” so, once the fix was in, we headed up the road to Bucklebury Common. After the weeks of heavy rain and strong winds the common was pretty muddy and there were fallen trees and branches everywhere. I think the daughter enjoyed her introduction to Green Laning.
2014-02-16 16.39.30
In fact she took it so seriously she started compiling some pace notes!

The Wobbler

I made a Wobbler! A single acting, oscillating air engine, to be precise. I was inspired by the amazing Tubalcain, who’s YouTube channel has been the source of many top tips and the cause of many late nights. Though the design of the wobbler wasn’t new to me, the old Mamod steam engine I had when I was a kid used the same principle.

The wobbler is probably the simplest engine design there is. I tried to to a nice job of this one, though didn’t go overboard with the look of the thing – I don’t see the point of pretending it’s not made from some bits and bobs I has knocking about in the garage! Here are some photos:

2014-01-23 21.07.06

2014-01-23 22.04.21

2014-01-27 21.31.38

2014-01-27 22.03.00

2014-01-28 22.51.55

2014-01-29 22.14.48-1

2014-02-01 22.38.52

2014-02-01 22.39.06

Fixing the gear stick

For the last couple of weeks, gear changes in The Duke have been very hard work. The tiny pin which stops the stick spinning sheared off, adding a new element of drama to my commute.


The original pin had sheared and was stuck in the channel in the ball at the base of the stick.


So I had to strip the whole thing down.


The pin and the thread on the hole were totally ruined, so I had to think if something new.


I drilled out the hole


Then tapped it with an M8 thread. Much bigger and stronger than the old one.


Then turned down a set screw on the lathe


And heat treated it with case hardening compound, which will hopefully stop it getting squashed and bent.


I doubt there are many Land Rovers on the road with the original rubber blob on the base of the great stick. It’s meant to prevent vibrations but was totally worn away.


So I turned a replacement out of nylon and hammered it on.


At 19.3mm diameter is a snug fit on my spare gearbox and should help prevent rattles and make gears a bit easier to find.


All in all I’m very happy with my evening’s work. Just need the sun to come up so I can put it all back together again!

Shape Files and SQL Server

Over the last couple of weeks I have been doing a lot of work importing polygons into an SQL server database, using them for some data processing tasks and then exporting the results as KML for display. I thought it’d be worth a post to record how I did it.

Inserting polygons (or any other geometry type) from a shape file to the database can be done with the ogr2ogr tool which ships with the gdal libraries (and with Mapserver for Windows). I knocked up a little batch file to do it:

SET InputShapeFile="D:\Dropbox\Data\SingleView\Brazillian Polygons\BRA_adm3.shp"

SET SqlConnectionString="MSSQL:Server=tcp:yourserver.database.windows.net;Database=danTest;Uid=usernname@yourserver.database.windows.net;Pwd=yourpassword;"

SET TEMPFILE="D:\Dropbox\Data\Temp.shp"
SET OGR2OGR="C:\ms4w\tools\gdal-ogr\ogr2ogr.exe"
SET TABLENAME="TestPolygons"

%OGR2OGR% -overwrite -simplify 0.01 %TEMPFILE% %InputShapeFile% -progress

%OGR2OGR% -lco "SHPT=POLYGON" -f "MSSQLSpatial" %SqlConnectionString% %TEMPFILE% -nln %TABLENAME% -progress

The first ogr2ogr call is used to simplify the polygons. The value 0.01 is the minimum length of an edge (in degrees in this case) to be stored. Results of this command are pushed to a temporary shape file set. The second call to ogr2ogr pushes the polygons from the temp file up to a database in Windows Azure. The same code would work for a local SQL Server, you just need to tweak the connection string.

You can use SQL Server Management Studio to show the spatial results of your query, which is nice! Here I just did a “select * from testPolygons” to see the first 5000 polygons from my file.


Sql Server contains all sorts of interesting data processing options, which I’ll look at another time. Here I’ll just skip to the final step – exporting the polygon data from the database to a local KML file.


SET KmlFile="D:\Dropbox\Data\Brazil.kml"

SET SqlConnectionString="MSSQL:Server=tcp:yourserver.database.windows.net;Database=danTest;Uid=usernname@yourserver.database.windows.net;Pwd=yourpassword;"

SET TEMPFILE="D:\Dropbox\Data\Temp.shp"
SET OGR2OGR="C:\ms4w\tools\gdal-ogr\ogr2ogr.exe"
SET SQL="select * from TestPolygons"

%OGR2OGR% -lco "SHPT=POLYGON" -f "KML" %KmlFile% -sql %SQL% %SqlConnectionString%  -progress

Obviously you can make the SQL in that command as complex as you like.

Polygons here are from this site which allows you to download various polygon datasets for various countries.

Combining Shape Files

This is one of those things that’s easy when you know how. Just so I don’t forget, here’s how to combine shape files using ogr2ogr.

I wrote it as a batch file to combine all the OSGB grid squares from the OS VectorMap District dataset into a single large data file for use with MapServer.

echo off

set OGR2OGR="C:\ms4w\tools\gdal-ogr\ogr2ogr"
set inputdir="D:\Dropbox\Data\OS VectorMap"
set outputdir="D:\Dropbox\Data\OS VectorMap Big"


set layers=(Airport AdministrativeBoundary Building ElectricityTransmissionLine Foreshore GlassHouse HeritageSite Land MotorwayJunction NamedPlace PublicAmenity RailwayStation RailwayTrack Road RoadTunnel SpotHeight SurfaceWater_Area SurfaceWater_Line TidalBoundary TidalWater Woodland)

del /Q %outputdir%\*.*

FOR %%L IN %layers% DO (
%OGR2OGR% %outputdir%\%%L.shp %inputdir%\SU_%%L.shp

FOR %%T IN %tiles% DO FOR %%L IN %layers% DO (
%OGR2OGR% -update -append %outputdir%\%%L.shp %inputdir%\%%T_%%L.shp -nln %%L

After a little map file jiggery-pokery I can now render a huge map of the UK or tiles with smaller maps without the many layer definitions needed to use ~20 shape file sets.




Serial on Raspberry Pi Arch Linux

So the new version of Arch Linux doesn’t have runlevels, rc.d or any of that nonsense any more. It just has systemd. Super simple if you know how to use it, but a right pain in the backside if you don’t.

I have a little serial GPS module hooked up to my Raspberry Pi via the hardware serial port (ttyAMA0). My old instructions for getting this to work aren’t much use any more. Here’s the new procedure for getting serial data with the minimum of fuss:

1. Disable serial output during boot

Edit /boot/cmdline.txt using your favourite editor. I like nano these days.

sudo nano /boot/cmdline.txt

Remove all chunks of text that mention ttyAMA0 but leave the rest of the line intact. Bits to remove look like:

console=ttyAMA0,115200 kgdboc=ttyAMA0,115200

2. Disable the console on the serial port

This was the new bit for me. The process used to involve commenting out a line in /etc/innitab but that file is long gone.

Systemd uses links in /etc to decide what to start up, so once you find the right one, removing it is easy. You can find the files associated with consoles by doing:

ls /etc/systemd/system/getty.target.wants/

One of the entries clearly refers to ttyAMA0. It can be removed using the following command:

sudo systemd disable serial-getty@ttyAMA0.service

3. Check you’re getting data

I used minicom for this as it’s very simple to use. First of all, make sure you plug in your device (with the power off, if you’re as clumsy as me!).

sudo pacman -S minicom
minicom -b 4800 -o -D /dev/ttyAMA0

You should see a lovely stream of data. I my case it was a screen full of NMEA sentences. Great stuff!

WiFi, Raspberry Pi, My oh my

Downloaded and installed the latest Arch Linux image for the Raspberry Pi today, only to find that the whole world has changed since I last looked at wireless connectivity!

There’s no rc.d any more, there’s a totally new way to manage networks (wireless and otherwise) and everything I thought I knew is wrong. I think I’m getting old!

After hours of faffing about, it turns out I could have had this nailed with two very simple commands.

Assuming you have a recent Arch Linux, I think you just need to:

1. Use the GUI tool to connect to your WiFi

sudo wifi-menu -o

Select the right network and enter the password when prompted. When you exit the application you should be connected to your router and the tool will have saved a config file to /etc/netctl/wlan0-YourNetwork

2. Change to a static IP address

Weirdly, the above step fails first time with a dhcp error. It saves a valid config file but doesn’t manage to connect. It seems to want to bring up dhcp against eth0 not wlan0 as I’d expect/prefer. Didn’t manage to find out why this is or how to fix it (yet) so just swapped to a static IP!

Use your favorite editor (I like nano) to change the config file just generated removing…


…and adding this in it’s place…


After you’ve done that, repeat step 1 and proceed to step 3. Note that when you run wifi-menu the second time it will show that there is an existing config for your network. You might also find that step 1 works and you don’t need to do step 2 at all, because you might have downloaded a fixed Arch image. In which case, I salute your fortitude!

3. Install the config

Since you probably want to reconnect the wireless after reboots, you need to install the config using the funky new “netctl” tool.

sudo netctl enable wlan0-YourNetwork

Now you should have a working wireless connection after reboots and a raspberry pi that works like your old one did!

Rant: Who moved my cheese?

People always moan about Windows versions that are different to old Windows versions – why Windows 8 took away the start button, why Windows Vista did security totally differently, blah blah blah…

Today I spent several hours digging around looking for something that should be easy, only to find it is indeed very easy… when you know how.

So today I’m quite happy to argue that Linux does exactly the same thing as Windows. I like Arch Linux a lot, and I accept that it’s not for newbies, but things change as often in Linux world as they do in Windows world. On both sides of the fence, Google is your only hope if you want to keep up to date with the changing software that underpins everything you do.