Gandi said thanks :-)

gandi_tshirtWhat a lovely surprise! A T-shirt arrived in the post from the folks at

Gandi are the company that provide all my domain names and server hosting for work and play, including the hardware behind this blog.  I’ve been using them since 2009 and they’ve always super.  If you need domain names or hosting, I can recommend them with confidence.

They are always improving things and the side effect is small errors on the web site admin interface. Mostly, that means they’ve forgotten to translate a French word into English (eg, it displays Serveur instead of Server).  One of the recent improvements to their web site was to allow a table of information to show how much memory each of my servers was allocated, but it was showing the maximum amount that could be allocated.  A small error, but as always I sent an email with the details.  Not only did they fix it and say thanks, they sent me a Gandi T-shirt in the post.  Nice 🙂

Speaking of Gandi, they are always improving things.  Today, I’ve just been switched to their new IaaS platform (Infrastructure as a Service).  The previous platform style was to have VPS (Virtual Private Server) shares.  So my one rackspace dedicated server back in 2009 became 8 Shares of their VPS platform (actually, the VPS had more power, but could be scaled up and down on demand).  Over time they’ve increased the power. Couple that with some software improvements to my web sites and yesterday I was running on 2 VPS shares (which I had set as two servers) with a little extra memory as an extra and a ‘SimpleHost’ instance. Hosting is a lot cheaper today then I when I first moved to Gandi.

The new IaaS allows a more fine grained control of the resources allocated to my virtual servers. On the old platform if I needed more than one processor it would have to come with more disk space. Now I can just allocate more processors, or more memory, or more disk, all independently. The change also means they’ll be charging me less for the same resource as before.  So it’s still a virtual server, it just costs less.

The other new feature is a ‘web accelerator’. I haven’t played with this yet, but I think it will work like a Varnish Cache in front of my servers so that pages can be delivered faster with no alteration to the servers themselves. That will also mean I can reduce the power of the server and save more money.

This blog is hosted on the ‘SimpleHost’ platform they offer and has been since November last year. Essentially that’s a virtual server that they set up and control and has a lot of restrictions on what software will run on it, which version, and so on.  Its other restriction is that it can only process two simultaneous requests at a time (on the cheapest package that I have) but that really isn’t a problem. As the pages don’t change very often, the built in varnish cache has probably delivered the page your reading so the server never even got the request, and there’s no limit or delay in responses from the cache. Here’s a quick fact: In the last hour 73% of the requests that reached the server were robots or spammers trying to post. Even then, there are nowhere near enough of these to block both processes to real users.  I have other web sites on the simplehost server as well as this blog (just like you would a virtual server) and for the simple sites simplehost is great.


Extracting images from PDF (free, using command line)

This is a day when I love computers. I have a multipage PDF and I need to extract the images from it.

Option 1: Open the PDF on screen, capture each section, save each file.
No thanks, that’ll take far too long and lose quality (which already isn’t too great)

Option 2: Open the PDF using Adobe Illustrator. select each image, copy/crop/save as, etc.
No thanks, almost as bad as option 1

Option 3: Google for an answer to “Extract images from PDF”. Discover all the top results are for paid applications.
No thanks. I don’t mind paying for applications but this is a (probably) one off job and I feel sure someone would have written a script to extract all the images from a PDF.

Option 4: Try PDFtk, a PDF toolkit that takes instructions by command line.
Almost there. It can do all sorts of things to PDFs, but extract the image objects appears not to be one of them.

Option 5: Re-discover The Unarchiver
t works! It really was so simple. The Unarchiver views PDF files as if they were a compressed file. Select the PDF, tell it to extract all.  Voila! 652 tiff images from 44 pages of PDF.  20 minutes to find the solution. Maybe 2 seconds for unarchiver to run (oh, and I already had it on my Mac, probably from having to extract a less common file archive format).

One last note. It maybe that ghostscript could also do this task, that would have been my option 6…

Building an automatic infrared remote control for the shop

ArduinoUnoSmdMy second Arduino based project has been to build an infrared remote control that will turn on a TV when the TV is powered up and defaults to standby mode.

Here the background. I have a showroom that sells kitchens, bedrooms and bathrooms. On the second floor one of the displays has a TV that we use to play videos from suppliers along with our own youtube videos (which we still haven’t got around to creating).

However, we don’t get very many customers during the day (we’re a specialist shop) and so to save energy I had our electricians install an infrared timed switch for all the upstairs power.  The lights turn on automatically when people walk up the stairs and turn off 15 minutes later.  The original TV was connected to this power circuit and everything was good. Except it died. The replacement TV doesn’t automatically turn on when the power comes on but it does remember the channel that was selected.

So, I needed to find a way of turning the TV on when the power came on. I couldn’t find any off the shelf solutions so I built my own remote control using an Arduino.  Arduino is

“an open-source electronics prototyping platform based on flexible, easy-to-use hardware and software. It’s intended for artists, designers, hobbyists, and anyone interested in creating interactive objects or environments.”

For me, I treat it like a simple small computer. I can plug in various components like LEDs, flow meters and LCD display screens and program it to respond to events in the way that I want.  I’ve used an Arduino to build a flow meter for the showroom so we can compare the performance of different showers. I’ve realised I’ve never blogged about that so I may do later.  This weekend though I wanted to build an InfraRed remote control.

Buying some components.

componentsI ordered about £50 worth of parts on the internet.  The Arduino board was about £24, the IR receiver, LED IR emitters, a suitable resistor (all in pack quantities far larger than I needed) about £10 and a prototyping board and jumper cables made up the difference.

If you’re trying to replicate my remote, the important bits I bought are:
Infrared LED 5mm, 940nm 22deg Vishay TSAL5300
IR Remote Receiver 38KHz 45m Vishay TSOP38238
PR01 Resistor, A/P,AXL,1W,5%,39R Vishay PR01000103909JA100  [remember to size the resistor according to the LED you get]

Putting them together

It’s important to remember that I don’t work out all this stuff. I’m not that clever. I rely on a lot of googling and a little past experience.   For this project, I relied upon Ken Sheriff’s Multi Protocol Infrared Remote Library for the Arduino. You’ll want to read that blog post. It may be old (2009) but  it worked just like described there.  I also found a useful hint at this blog about prefixing HEX output.

I put it all together just like Ken Sheriff said. Well, almost. I had a different IR Receiver so I had a slightly different pin setup there. I had my IR Led connected to pin3 of the Arduino which is a requirement of the library.

buildandtestMy plan was to: 1) get the IR reciever working to record the code from my remote. 2) Send the IR code from the LED, make sure I’m receiving it. 3) Test it on the TV.

Step 1 worked very well. The sketches (example code) included with the IR library worked perfectly. I used it to get the power code from my remote (It reported the TV uses NEC codes and FE50AF is power).

Step 2 I thought worked very well, but I later discovered it didn’t work at all. I did read that the library could only send or receive and not do both at the same time. To test sending, you’d need a second Arduino.   So the code I wrote to send and receive wasn’t working and the result I got which I thought was a success was a coding error on my part.  See how I’ve lined my LED up with my receiver?  Well, don’t bother, it won’t work.

When it didn’t work on the TV I started to fault find. Seeing an IR LED is a little difficult.. seeing as our eyes can’t see it. Fortunately a camera can so I used my smartphone to see the LED. I couldn’t see it.  It took me a while to discover, because the LED is sending a command it’s modulating so fast and that on my smartphone it was very faint.  When I wrote some code to test the IR Led I was giving it full constant power so it was nice and bright on my screen. When I used the library to send a remote command it was dim, but working fine.  Here’s a video, if you look really closely, you’ll see the IR LED pulsing slightly.

So why didn’t my IR LED turn on my TV? I’d forgotten to prefix the HEX code with 0x.  I’ve learnt that before… but forgotten. Now I know it again, at least until I forget again.

With that fixed, my remote was working. All I had to do was tidy up the code, position the Arduino and LED somewhere in range of the TV and watch it work. Here’s what it looks like:


Here’s the code:

//Steve Root's IR signal to turn TV on when Arduino powered
//Created because our showroom TV doesn't turn on when the power comes on
//The power only comes on when people walk into the showroom
//So this arduino will pause for a short while then send the command
//TV_on via infrared to the TV.

#define NECPower 0xFE50AF //NEC TV power. the 0x in front is because FE50AF is hex

#include <IRremote.h>

IRsend irsend;

void setup()
//when the device is powered, pause then send remote TV on by IR
//15 second delay. the tv takes a while to wake up.
irsend.sendNEC(NECPower, 38);


void loop() {
//nothing to do here now.


Note for future me: IR LED connects pin 3 to ground