All posts by Pete

Tweet your Candidate is back!

Following the initial joy and elation at discovering we’ve got yet another chance to express our electoral opinions I’ve updated TweetYourMP.com to now include candidate information for the forthcoming 2017 snap General Election, and I’ve even managed to secure yet another dot com – TweetYourCandidate.com includes the details of over 3,000 candidates standing in the 650 constituencies across the UK.

Fortunately this time around I’ve been able to make use of the very useful candidate data from The Democracy Club which has saved a lot of time and made it possible to turn update the site in a very short space of time.

This time around there’s a new feature to play with: the campaign generator makes it possible to create your own pre-filled twitter campaigns to share.

As an example I created a very simple campaign – posing possibly the easiest question to people vying to be your Member of Parliament:

As I live in the Vauxhall constituency of former MP Kate Hoey I have had a number of replies:

First to reply was Harini Iyengar for The Women’s Equality Party:

and now without the ringer:

Then Mark Chapman for the Pirate Party:

George Turner for the Lib Dems:

and Gulnar Hasnain for the Greens

Sadly I’ve yet to receive replies from Kate Hoey (The former Labour MP) nor Dolly Theis who is the Conservative and Unionist Party candidate, although in the case of the latter I did tweet later as my initial candidate list didn’t include her twitter details. UKIP are not running in Vauxhall.

So far a number of campaigns have made use of the tool – which is provided free of charge, as a spare time project.

To ask the same question to your candidates visit TweetYourCandidate.com

Countdown to Christmas with the Arduino advent calendar!

This year, as part of the publicity for their Christmas charity gifts, Concern Worldwide (who I’m lucky enough to work for) commissioned an artist to come up with a design for an advent calendar.

The resulting design by Robert Fiszer is really rather lovely (you can check out the campaign here)- and lends itself rather well to be illuminated as a Christmas decoration for the Concern office.

Concern Advent Calendar designed by Robert Fiszer
Concern Advent Calendar designed by Robert Fiszer

So as a spare tinkering time project I thought I would have a go at building an Arduino controlled LED advent calendar that illuminates the relevant day and counts down to the 24th.

My requirements needed it to be powered by USB, and that it’s a standalone project with it’s own date clock – as the office IT department would frown upon me installing things on my work PC to run Christmas decorations from. In order to do this I needed to read up on using a battery backed up RTC (Real Time Clock) and a way to control 24 LEDs from my arduino micro.

I decided on using a shift register – the other option would be to use a chain of NeoPixel LEDs, but I wanted to learn about shift registers and get an idea about how they worked. For an excellent introduction to shift registers check out this blog from Bildr.

Essentially a shift register is a way of converting a serial signal from the arduino into a parallel series of high and low signals to the output pins on each chip. Each shift register has 16 pins, 8 output pins, 2 earth pins, 2 positive 5 volt pins, 3 serial input pins consisting of clock, latch and time signals, and a final serial output pin which is used when daisy chaining them together.

The 74HC595 8-bit Shift Register I used was available cheaply on ebay and looks like this:

My diagram of a shift register
There are better diagrams out there but this helped me

Wired up with an arduino on breadboard it looks like this:

Teaching myself about shift registers and Larson scanners #arduino #kitt #cylon

A video posted by Pete Taylor (@kimondouk) on

Even with just 8 outputs it looks a bit messy. With 3 shift registers daisy chained together it looks even more complicated:

Now with 3 shift registers and 24leds #arduino #adventcalendar

A video posted by Pete Taylor (@kimondouk) on

But remember the diagram above – the circuit is still fairly simple, what makes it look complicated is the loops of wire which are all the same length. The challenge I found with the chip is that one of the outputs is on one side, with the remaining 7 on the other.

To tidy everything up, I soldered the chips in carriers onto a piece of full sized Adafruit perma-proto breadboard. I highly recommend using this stuff – it costs a bit more than the generic soldering boards you can buy on ebay, but it’s strong and laid out sensibly using the same layout as standard prototyping boards. In my layout I spaced the shift registers 1 hole apart and moved the offside output around the corner of the chip, so that all 8 outputs were on the same side. To connect my LEDs I was able to add 8 socket female headers as I found soldering the LED wires directly into the board was difficult as the stranded copper wire would snap easily. Plus using headers gives me the option to swap out the LEDs for something else in the future. For LEDs I found pre-soldered 5 volt LEDs available on ebay that included the resistor.

My board includes 4 shift registers giving me a total of 32 outputs – this would enable me to re-purpose the board in future, as I’m thinking after advent it would make a nice monthly calendar.

Here’s the board without any of the LEDs attached:

Shift register without the LEDs
Shift register without the LEDs

For the time circuit I used a DS 1307 RTC – the one I used shares the same chipset as the Adafruit one detailed here (link) (normally I’d buy the adafruit one to support their website, but I couldn’t find it available online).

The code:

/*
Shift register calendar
*/

// Date and time functions using a DS1307 RTC connected via I2C and Wire lib
#include <Wire.h>
#include "RTClib.h"

#if defined(ARDUINO_ARCH_SAMD)  // for Zero, output on USB Serial console, remove line below if using programming port to program the Zero!
   #define Serial SerialUSB
#endif

RTC_DS1307 rtc;

// shift register setup

//**************************************************************//
//  Name    : shiftOutCode, Dual One By One                           //
//  Author  : Carlyn Maw, Tom Igoe                               //
//  Date    : 25 Oct, 2006                                       //
//  Version : 1.0                                                //
//  Notes   : Code for using a 74HC595 Shift Register            //
//          : to count from 0 to 255                             //
//**************************************************************//


int SER_Pin = 4;   //pin 14 on the 75HC595
int RCLK_Pin = 5;  //pin 12 on the 75HC595
int SRCLK_Pin = 6; //pin 11 on the 75HC595

int caldate = 0;

//How many of the shift registers - change this
#define number_of_74hc595s 4

//do not touch
#define numOfRegisterPins number_of_74hc595s * 8

boolean registers[numOfRegisterPins];

void setup() 
{
  pinMode(SER_Pin, OUTPUT);
  pinMode(RCLK_Pin, OUTPUT);
  pinMode(SRCLK_Pin, OUTPUT);


  //reset all register pins
  clearRegisters();
  writeRegisters();

#ifndef ESP8266
  while (!Serial); // for Leonardo/Micro/Zero
#endif

Serial.begin(57600);
  if (! rtc.begin()) {
    Serial.println("Couldn't find RTC");
    while (1);
  }

  if (! rtc.isrunning()) {
    Serial.println("RTC is NOT running!");
    // following line sets the RTC to the date & time this sketch was compiled
   rtc.adjust(DateTime(F(__DATE__), F(__TIME__)));
    // This line sets the RTC with an explicit date & time, for example to set
    // January 6, 2014 at 3am you would call:
    //   rtc.adjust(DateTime(2014, 1, 6, 3, 0, 0));
  }
}

//set all register pins to LOW
void clearRegisters(){
  for(int i = numOfRegisterPins - 1; i >=  0; i--){
     registers[i] = LOW;
  }
  writeRegisters();
} 


//Set and display registers
//Only call AFTER all values are set how you would like (slow otherwise)

void writeRegisters(){

  digitalWrite(RCLK_Pin, LOW);

  for(int i = numOfRegisterPins - 1; i >=  0; i--){
    digitalWrite(SRCLK_Pin, LOW);

    int val = registers[i];

    digitalWrite(SER_Pin, val);
    digitalWrite(SRCLK_Pin, HIGH);

  }
  digitalWrite(RCLK_Pin, HIGH);

}

//set an individual pin HIGH or LOW
void setRegisterPin(int index, int value){
  registers[index] = value;
}


void loop() 
{
  DateTime now = rtc.now();
  caldate = now.day();
  Serial.print(caldate);
   Serial.print(now.day(), DEC);
 
  delay(1500);
  clearRegisters();
  delay(500);

  for (int i = 0; i < caldate; i++)
  {
   setRegisterPin(i, HIGH);
   writeRegisters();
  delay(100);
  }
}

Note – the RTC was the trickiest part of the circuit, and after reading lots of posts from people who’ve had issues with the DS1307 I’d recommend using one of the integrated chip varieties.

The code for the calendar is fairly simple – it checks the date from the RTC and then lights up the appropriate number of lights. I’ve made it loop to give a bit more visual interest, but it’s easy enough to modify the code to make it just light up once when you plug it in.

Assembly

I printed out the calendar image and pasted it onto a bit of board with holes behind each ‘light’. Using a frame from a previous project (the Concern general election Swingometer) to bring it all together. To mount the LEDs I used bottle tops – this involved drinking a lot of diet coke, and when I ran out of that, wine.

Back of the advent calendar
Back of the advent calendar

Here’s the final version, in action as if it’s Christmas Eve showing all the lights as I removed the RTC.

The #arduino shift register powered #adventcalendar is now finished! Happy #1stdecember

A video posted by Pete Taylor (@kimondouk) on

If you liked this project, please buy a gift from Concern’s shop – my personal favourite is the solar lights as they are a neat technological solution to the tricky problem of lighting.

Official Raspberry Pi touch display review

Official Raspberry Pi display
It’s bright

This week saw the launch of the official Raspberry Pi display, so I thought I would write up a quick review to share some of my initial thoughts about the device.

Ever since the first version of the Pi there’s been a DSI connector on the board – and although there have been lots of devices that use either USB or the GPIO pins to provide simple touch screens, this is the first to use this official display connector.

I ordered the Pimoroni version of the display which came with a stand for £58 – consisting of 3 layers of laser cut plastic and a couple of feet to stand the screen on. Although this is much handier than just having the display on it’s own I anticipate a lot of Pi-suppliers out there are working on more more robust tablet style enclosures, as this version still leaves the fragile ribbon connectors exposed, along with the Pi itself. The Pimoroni stand is perfect for using the Pi with it’s display on a desk but I wouldn’t chuck it in a bag and take it outside quite yet.

In usual Pimoroni fashion it’s super easy to slot together the stand. Assembling the display itself is straightforward but perhaps a little trickier. The display has a driver board with 2 ribbon cables, and a further ribbon cable which attaches to the DSI port on the Raspberry Pi. I attached the thicker orange cable first, followed by the smaller one, then screwed the board to the back of the display and finally attached the DSI cable between the board and the Pi. I found it easier when I used a couple of plastic screws from my PiBow case to gently nudge the cable covers back into place after I’d slotted each ribbon in place.

You can opt to power the display via the GPIO (jumper cables are provided) or via a USB – it is a slightly tight fit where the Pimoroni stand supports jut out of the back of the display so you’ll need a USB cable with short plugs.

Note the ribbon cable - writing on the inside
Note the ribbon cable – writing on the inside

First impressions

The display itself has a robust metal backing and is solidly constructed from glass. It has a really high quality feel to it. There’s 10 point multi-touch which is capacitive (and I imagine will have lots of interesting programming type uses). The touch was responsive and quick running the Raspbian desktop. As the display doesn’t use the HDMI or video out ports you can add another HD or video display, and it shares the power supply with the Pi. Using the USB power option leaves the GPIO ports free to add Hats to.

Here’s how the desktop looks on the display:

Raspberry Pi desktop on official display
What a brilliant website!

The display worked fine out of the box but there is an update available for Raspbian which you’ll need to enable touch, and you’ll need a USB keyboard unless you’re booting directly into the desktop. You can install an onscreen keyboard with

sudo apt-get install matchbox-keyboard

and start it with

sudo matchbox-keyboard
Raspberry Pi onscreen keyboard
It’s a diddy onscreen keyboard

To be honest I found this a bit small to practically use. An official Raspbian onscreen keyboard will be coming soon no-doubt but i’ll be sticking with my USB keyboard.

Drawbacks?

The resolution of the display is 800 x 480 (the screenshots above are native) which for some might be a little bit lacking, but given that you can add a full HD display at the same time I don’t regard this as a massive drawback. The Pi foundation had to find a compromise between cost and a full HD display would have been more expensive. Plus I think 4k displays on tiny devices are silly, and if you really want something like that you can pick up an Android tablet for not much more. Generally everything displays fine, although there are a few dialogue boxes where the buttons are off screen:

Dialogue box on Raspberry Pi display
Oops. I’ll hit enter now and hope for the best.

The viewing angle left to right is fine, but up/down was a bit sensitive. Generally though colours and contrast looks good out of the box.

I did notice the low power indicator (the rainbow coloured box) appear when I was using a USB Wifi module – and I’ve been running the Pi off the official power supply.

I was worried that the screen itself is also potentially scratchable (the Pimoroni instructions came with lots of warnings) – as it came with a plastic cover I’ve just left that on for now,  as the capacitive touch works fine with it in place. One drawback of the ribbon arrangement is that the DSI cable loops over where the micro SD card sits, so removing it is a bit fiddly.

TouchPi

This is version 1, and when more robust cases come on the market I think a lot of the initial issues like the positioning of cables and power will be solved, as will the software. Looking at how they’ve arranged the hardware I think it would be easy to design a touch pad case for the Pi (i’m really looking forward to see what rainbow inspired case Pimoroni come up with).

I think the exciting thing about the official display is how it changes the nature of the Pi – it feels like a neat self contained all in one computer. I don’t have to worry about SSH or networking, I can plug in a keyboard and start typing away with a GPIO board sitting in front of it.

Given the Pi’s purpose as an educational computer (rather than a mid-30s-bloke-who-likes-to-tinker machine) the official touch display gives the Pi a commonality with tablets and iPads that I think will appeal to young people – finally here’s an all in one machine that will play minecraft out of the box and hopefully inspire tinkering on a level impossible with any other tablet out there.

Update: I built a stand out of Lego, which handily fits quite neatly and includes space below for a Pimoroni black hack3r hat. Pimoroni has also pointed out the the display is actually upside down – the recent Raspbian update flips it over to improve the viewing angle.

#lego #raspberrypi (with official display) all in one computer stand

A photo posted by Pete Taylor (@kimondouk) on

Ryanteck Raspberry Pi Serial Debug Clip review

When building projects on the Raspberry Pi that run ‘headless’ I’ve often found it necessary to connect to the Pi to see what’s going on, work out why it’s not working as I expected or to simply shut it down neatly without yanking out the power cable.

There are a few ways to do this – you could carry around a keyboard and monitor, hook them up to the Pi and see what’s what. The extremely useful and sadly getting rarer and more expensive Motorola Lapdock which I reviewed a while back works very well as a portable monitor / keyboard combination.

Or you could connect to the Pi using SSH if you’re both connected to the same network.

The third option is to connect to the Pi using a USB to Serial port converter. These are usually available as USB to TTL Serial Cable with a USB plug on one end and a series of female jumper wires on the other. Adafruit have a good guide on how to use one of these. Ryanteck have recently released a Raspberry Pi USB debug chip which works in the same way as the USB serial cables, but which is easier to connect to the Pi and includes friendly green and red LEDs to indicate data being sent back and forth. I recently backed this on Kickstarter so was able to get one to play with.

For this option you do need to carry round a computer, but as I discovered it works well with my tiny Toshiba Encore windows 8 tablet – and even with an Android mobile phone!

Raspberry Pi USB Serial debug chip
Lego spaceman has removed the important little jumper on the bottom left of the clip

Assembling the chip is very straightforward with the instructions on the Ryanteck website – although it’s worth mentioning that the version of the PCB supplied varies slightly from the images in the guide. The final version of the PCB includes a little jumper clip – this is quite important – with the jumper in place the Debug Clip will power the Raspberry Pi. It’s vital that the Pi is powered from either the clip or it’s micro USB port – the serial link will not work if the Pi is powered from both.

The RPi debug clip lacks any headers or sockets – it’s designed to sit on the Raspberry Pi GPIO pins underneath a hat or add-on board. In practice I found it a tight fit on the Raspberry Pi pins and a loose fit on a spare extension header I had lying around so I’ve used a 40 pin extra tall header – with this it’s possible to use the Rpi Clip with the Pimoroni Coupé style cases and have room to fit additional hats on top:

Debug clip sat on a 40 pin tall header, sat on a Pimoroni Coupé case
Debug clip sat on a 40 pin tall header, sat on a Pimoroni Coupé case

Despite having just one micro usb port it’s possible to use the debug clip on the Toshiba with a Micro USB Host OTG Cable – as there are a lot of very cheap Windows based tablets now available I imagine they all work in the same way.

To get the RPi clip working with the Toshiba Encore I installed the driver from the Microchip website, and then looked up the COM port the USB Serial port was using with the Computer Management window (right click on the Windows 8 start icon). In my case it was COM3. I opened up the Windows Telnet App PuTTY, chose a serial connection on COM3 at 115200 baud, hit enter and voila! – the Raspberry Pi login prompt appeared.

RPi debug clip
I do normally use this with a little keyboard, but it’s still very little.

It’s also possible to use the same cable with an Android mobile phone. I tested it with my bog standard Nexus 5 (which hasn’t been rooted) and a free app called DroidTerm – to connect hook up the Pi with the OTG to USB cable, make sure the header on the RPi debug clip is removed and use the following settings:

Droidterm screenshot
Basic connection options

When you first connect the screen will be blank – just enter the username you normally log in on your pi with (I think everyone uses ‘Pi’) and it will prompt you for your password. It’s a basic app – there’s no cut and paste, but for checking on things it’s fine.

Droid term /cat/proc/cpuinfo
Here’s some Pi info on a mobile!

The Ryanteck Raspberry Pi debug clip is available here for about 7 quid.

 

£15 DIY usb microscope from StoneTurners

At the Elephant and Castle Mini Maker Faire this weekend I picked up a £15 microscope kit from the guys at StoneTurners (hello!).

This is a hack kit based on a USB webcam where you remove the lens and reverse it to create a cheap microscope. In the box you get a set of parts including the camera itself, a plastic screw pot, some neoprene material and a few laser cut parts.

Photo of the microscope kit
*small robot not included

Instructions can be found over at StoneTurners along with some inspiring images taken with the scope. It’s an easy build – I did however skip over using the neoprene strips instead opting to hot-glue the webcam module inside the plastic screw-pot, and I had to bend the LEDs slightly to fit them inside the hole at the top. What you end up with is 2 ways to adjust the microscope – you can focus the reversed lens attached to the CCD module, and you can raise and lower the microscope ‘stage’ –  being the outer part of the screw pot.

Here’s how mine ended up:

finished USB microscope
I was a little heavy with the glue gun

You can use the microscope with Camspinner on the Mac – this worked fine with no problems on my Yosemite iMac.

For the ultimate in budget scientific computing, you can use guvcview and plug the USB microscope directly into a Raspberry Pi. I used a model B+ and it worked fine just plugged directly into the USB port, although the low power warning icon did flash up a few times.

To install guvcview just open the terminal and type:

 sudo apt-get install guvcview

then head over to the desktop with startx – the webcam software will be found under Sound and Video in the main start menu.

I did try installing Cheese, but that was a little bit too much for the Pi.

USB microscope running on Raspberry Pi B+
The pretty pattern is my Imac screen

Finally, here are a few pictures I took just trying out the USB microscope:

an LCD screen:

An LCD screen (not OLED or retina, I can’t afford a new mac just yet)

and the tip of a ballpoint pen:

Ballpoint pen with a USB microscope
A ball-point pen

I haven’t tried anything living yet, but when it’s not dark and raining outside I’ll pop down to the thames and see if I can get a water sample. One interesting project might be to look at determining water quality based on what pond-life appears.

In conclusion it’s a fun kit for £15 and I look forward to seeing what they come up with next. You can buy the kit here.

Digital Holga part 3 – taking photos with the inputs

This is my follow up to my previous posts about building a digital camera out of a Raspberry Pi Model A and a medium format Holga 120 film camera.

My aim being to build a hackable portable digital camera which hopefully would be able to capture images not possible with a normal digital camera, and to recapture the unpredictable spirit of film cameras (without the expense of the chemicals).

In my first post I fitted a Raspberry Pi model A and camera board into a hollowed out Holga 120. The Holga’s plastic construction makes it easy to work with and it’s roomy enough to accommodate a Pi without having to remove components from the board.

Pi camera case with Pi fitted
Here it’s sitting in it’s case. Snug.

In my second post I added the final inputs to the Holga case – a rotary selector switch with 3 positions, a push button switch on the side (with a trigger input on the bottom) and a power switch. I added a filter adapter to the front lens and I also took a few pictures by remotely triggering commands on the Pi.

Holga 120d Raspberry Pi Camera Case
Here’s the 3/4 view with the big clunky switch. It now switches the mode of the camera.

I’ve now connected up the switches and added 2 LEDs to the Raspberry Pi, making the Holga 120d a practical portable digital camera.

The rotary switch combined with the trigger switches effectively gives the Holga 120d 3 input buttons. The 2 LEDs (blue and orange) indicate the ‘mode’ the camera is in when I push the shutter button.

Each of the 3 ‘modes’ is programmable – at the moment I have 2 set up – one takes a photo which is saved to the Pi’s SD card, and the other performs a safe shutdown. It’s possible to add any command to the python script – and I’m working on an additional artistic mode which I’ll detail in a later blog.

I soldered all the inputs & the 2 LEDs to a Slice of Pi Breakout Board – these are available for around £5 and fit neatly over the Raspberry Pi without taking up too much space.

Raspberry Pi Holga 120d internals
Bit of a cram, but it all fits.
Holga 120d LED viewfinder
These light up to tell you the mode the camera is in.

From the board leading to the case, the green wires are to the push switch and trigger input, the 3 red wires & black to the right lead to the rotary switch and the red and black pairs lead to the LEDs.

The yellow wires just out of shot are to the flash hot-shoe. I did consider connecting this using an opto-isolator LED and there this space to do this at a later date.

There is also (just) about enough space to add a real time clock module – I used the Adafruit DS1307 Real Time Clock which connects to the 5v, GND, SDA and SQL pins on the slice of pi board. I followed Adafruit’s instructions (leave the resistors off the board!) and it works well.

The LEDs themselves slot into the viewfinder and light up according to the position of the switch. So in mode 1 the blue LED lights up, 2 both LEDs light and in 3 just the orange LED. This gives a bit of useful feedback to show that everything is working properly and the Pi is taking pictures when you click the shutter button.

For an easier to understand diagram – here’s the circuit laid out in Fritzing.

GPIO 23,24 & 25 are the inputs, with GPIO 17 and 18 driving the 2 LEDs. The switch at S2 is the rotary selector switch.

I used 330 ohm resistors for the LEDs and 10K resistors for the GPIO inputs.

Holga 120d wiring schema
Try on a breadboard first

 

The code I used is really simple.

Make sure you’ve run sudo apt-get update and have installed the Camera py modules first.

#!/usr/bin/env python

import time
import picamera

from time import sleep
import os
import RPi.GPIO as GPIO


GPIO.setmode(GPIO.BCM)
GPIO.setup(23, GPIO.IN)
GPIO.setup(24, GPIO.IN)
GPIO.setup(25, GPIO.IN)
GPIO.setup(17, GPIO.OUT)
GPIO.setup(18, GPIO.OUT)

while True:
        if ( GPIO.input(23) == False ):
                print('Orange: Taking photo')
                GPIO.output(17, True);
                date_string = time.strftime("%Y-%m-%d-%H:%M:%S")
                with picamera.PiCamera() as camera:
                        camera.capture('image' + date_string + '.jpg');
                sleep(2);
                GPIO.output(17, False);
        if ( GPIO.input(24) == False ):
                print('Blue')
                GPIO.output(18, True);
                os.system("sudo shutdown -h now")
        if (GPIO.input(25) == False):
                print('Both')
                GPIO.output(17, True);
                GPIO.output(18, True);
                sleep(2);
                GPIO.output(17, False);
                GPIO.output(18, False);
        sleep(0.1);

In the code above, one of the settings takes a photo which is saved with a time / date stamp, the other safely shuts the Pi down, and the other is yet to be used.

The easiest way to get your photos off the Pi is to use Filezilla and to connect to your Pi using sFTP – this uses your SSH login and enables you to easily to download and delete photos.

For connecting to your Pi remotely see my previous post about finding your Pi on your network.

I’ve had lots of interesting feedback about the Holga 120d – with the Pi model A (and potentially a smaller model A+ in the works) there are lots of opportunities for adding a digital camera to an existing film camera.

Now i’ve got my Holga 120d up and running I’m going to do some experimenting – my aim being to capture images that you can’t recreate with Instagram. If you’ve got any creative ideas to share please leave them in the comments below!

Cheap Raspberry Pi outdoor case

Here’s  a very cheap outdoor weatherproof case for the Raspberry Pi.

I’ve been experimenting with the AirPi weather sensor kit (available on Tindie). This is a lovely kit which comes bundled with an air-pressure, humidity, light, temperature, NO2 and CO sensors. The AirPi is fairly easy to solder together and comes complete with some nice software that automatically uploads your recordings to Xively. As it’s written in Python it’s also quite easy to see what’s going on – and the whole project is available on GitHub.

I did find that the software needed a bit of work (don’t expect it to be perfect out of the box), but it’s a good starting point – part of the Raspberry Pi adventure is about trying to come up with your own ideas and improving on the work done by others. It’s also particularly impressive that the AirPi was put together by an 18 year old in his spare time.

If the AirPi kit is a bit steep you can also hook up a DHT22 temperature and humidity sensor – there are tutorials available on how to setup logging on your Pi, and for about £10 you can put together a simple weather station that can take readings over time.

Since it’s more fun to take readings outside, I’ve been looking at weatherproof case options for the Raspberry Pi.

The white louvred boxes you sometimes see on street corners, outside science labs or in the middle of school fields are called Stephenson screens. These allow for the weather sensors to have air circulate around them and are carefully designed to minimise the effects of sampling error – by providing a standard way of mounting and housing scientific instruments.

As Stephenson screens are no doubt quite expensive (and my AirPi hasn’t been calibrated anyway) I’ve opted for a cheaper option, which also manages to include a few of the features of it’s more expensive counterpart. The key things I’m aiming for are:  standard (and repeatable), allows air to circulate around the sensors, and white and reflective.

Build guide

For a fiver from Wilkinsons (in the UK) you can buy a bird box which makes a cheap and effective weatherproof housing. You’ll also need a dremel (or similar small drill), some sandpaper, waterproof outdoor gloss paint, wood glue and insect netting.

Raspberry pi weatherproof case
From cheap birdbox to advanced weatherproof housing

This is a box made from softwood, so it’s very easy to work with – you can use a dremel or a junior hacksaw to make holes. The plate with the birdbox hole is removable, and the pi sits on top of a piece of cardboard which wedges inside. The spare bits of wood from the hole were used to make rests for the Pi mounting board.

I modified my AirPi kit slightly – first I adjusted the height of the header pins so that the board would fit on top of a modmypi plastic case – second I didn’t solder the light sensor directly to the board. Instead I soldered a couple of header pins to the board, and then a couple of leads to the sensor – allowing it to be fitted in a different place. In the image below you can see the light sensor mounted in a hole in the front plate – it sits behind a clear lego stud which serves as a little window.

The Raspberry Pi sits inside the box on a piece of board – I cut up the back of an old picture frame.

Depending on how you’re planning to communicate with your Pi (in this case a model A with a Wifi dongle) you might need to make a hole in the back of the birdbox for the USB to stick out. In my case the WiFi module fits snugly in the hole in the back of the bird box, which was then covered with a bit of board and painted. For power I used a low profile USB – micro cable which is hooked up to a USB terminal block inside the case (scavenged from an old digibox). The Pi is orientated inside the case so that the green and red LEDs are visible through the wide hole in the font. You don’t need to add all these bits, just bare in mind that the Airpi uses a lot of power and long USB cables might have a negative effect on your Pi’s power supply.

The measurements I used were as follows:

The board on the right fits inside the case
The board on the right fits inside the case

You might need to experiment with the materials – but the softwood is very easy to work with. You can buy wood filler if you make any mistakes.

Once you’re happy with the fit of the Pi inside the box, paint the whole thing with white glossy outdoor paint. To stop insects or anything else nesting in the box, wrap the front plate in insect netting.

How the Raspberry Pi + AirPi sits inside
How the Raspberry Pi + AirPi sits inside

Finally – test! – i’d recommend leaving the box in the rain (without your Pi) with some tissue paper inside just to check if there are any issues with water getting in. Obviously this can’t be 100% waterproof, but it’s good enough to leave your Pi on a windowsill or sheltered garden.

Raspberry Pi LED scrolling sign

I’ve been playing around with LED scrolling signs for a while now and have been looking for an affordable sign to use for a project. Some LED signs are really expensive but I’ve recently come across this one from Embedded Adventures:

It’s a 80×8 display with three colours – Red Green, and Red/Green mixed to produce Orange. It measures about 35x4cm in size so is ideal for something eye catching.

Best part is that it’s available for just £20 from the Embeded Adventures website. It’s ready assembled so you don’t have to get out your soldering iron.

To connect to your Pi’s GPIO follow the instructions on this page – which includes a handy python script by Pete Goss. For the wiring guide note that the numbers refer to the number of the pins as you count across, not the GPIO number. This is also for the Rev 2 board model A or B (if you have mounting holes, your Pi is fine).

Raspberry Pi pin number (GPIO pin label) LDP-8008 pin number (label)
3 (GPIO 2) 2 (A row address)
5 (GPIO 3) 4 (B row address)
6 (GND) 5 (GND)
7 (GPIO 4) 6 (C row address)
8 (GPIO 14) 7 (EN enable display)
10  (GPIO 15) 8 (D row address)
11 (GPIO 17) 9 (red LED)
12 (GPIO 18) 10 (green LED)
13 (GPIO 27) 14 (latch)
15 (GPIO 22) 16 (shift)

There’s a slight errata on the page as you have to type:

sudo python scroll “Raspberry Pi” 1

to get it to work.

I found that it will work powered just from the GPIO of the Pi, but if you need a brighter display you can just hook up a 5 volt power supply (e.g. a spare USB charger) to the central pins – this doesn’t need to be connected to anything else. The lower pin (with the printed text on the back the right way up) is ground – I used the cable off a novelty LED light from Poundland.

For the cable you can use jumpers or for something more permanent I found this Maplin GPIO breakout board available for £3.49 to be ideal. The LDP8008 comes supplied with a ribbon cable you can use.

Here’s a closeup of my cable – by cutting the grey cable different lengths you can make it quite neat. I also added a plastic cover cut from a spare toolbox divider.

underside of the maplin breakout board
underside of the maplin breakout board

and the cable attached to the GPIO on the Raspberry Pi (make sure you get pin 0 on the right side!)

I was surprised at how neat this turned out...
I was surprised at how neat this turned out…

Note that in my case, the labels on the Maplin GPIO breakout board were incorrect – make sure you double check everything before plugging it into your PI so you don’t break it!I also found the display a little sluggish if anything else is running.

For extra neatness I mounted the whole setup in a box frame – the one I used came from Wilkinson’s and was £6.

endless office fun...
endless office fun…

Raspberry Pi retro text browser

If you visited the Raspberry Pi foundation’s website yesterday (April 1st), you will have spotted their spoof website redesign featuring a text interface and binary numbering on the menus:

This was what the web used to be like...
This was what the web used to be like…

They even had some lovely ASCII art. If you missed it, you can recreate the effect for any site on the web using the Lynx browser.

The Lynx browser is currently the oldest web browser still in use – it dates from 1992 and runs completely in the terminal. Despite it’s old age, it’s still regularly updated and actually works quite well. For sites with lots of text and forms Lynx is all you really need, and if you have limited access to the web where you work you can SSH into your Pi and browse the web remotely, all from the terminal.

Usage:

sudo apt-get install lynx

then just type:

lynx http://raspberrypi.org

to visit the site of your choice! – the newly launched redesign of the Raspberry Pi website looks like this:

No school like the old school
No school like the old school

enjoy!

Add a Raspberry Pi temperature gauge to your blog

At the moment I have a Raspberry Pi sat in the kitchen at home, running a Ghost blog – you can usually find it a ghostpi.org (BT broadband connection permitting).

As I don’t usually leave computers running 24 hours a day, 7 days a week I was curious as to how warm the Raspberry Pi gets with use, so I’ve found a handy way of keeping track of the temperature of the CPU. Admittedly the blog isn’t driving massive amounts of traffic – it was mentioned on Reddit once which generated a spike of activity, but the plucky little Pi held up very well. There are heat sink kits available for the Pi that add a block of metal – either aluminium or copper to dissipate heat. At the more extreme end of the spectrum someone’s even created a water cooled Pi.

The snowman still isn't getting in the least bit warm
The snowman still isn’t getting in the least bit warm

Realistically, although they look nice, heat sinks are a bit like go faster stripes or fluffy dice – in use the biggest impact on my Raspberry Pi was what time of day it was, and if the sun was shining on the kitchen shelf. Famous last words, perhaps this will get slashdotted and I’ll come home to find a smouldering pile of molten plastic.

If you’re interested in hosting a Ghost blog I’ve posted some instructions here – it is a beta blogging platform based on node.js which launched last year – it generally works well on the Pi, although for slightly complicated reasons logging in takes about 3 minutes (enough time for a cup of tea).

I’ve been using RRDTool to track the temperature of my Pi’s CPU – every 5 minutes this updates a nice little graph of the last 24 hours as a PNG which is then copied to the images directory on my GhostPi.org blog:

This might get cached so click on the image for the latest version

This can then be added to a page on the Ghost blog giving some stats on how hard the Pi is working.

In putting this together I used the information on this blog with a few alterations to get it to work for me.

First install the RRD  (Round Robin Database) tool:

sudo apt-get install rrdtool

 

Then run this script to set up the database. I created a folder in my home/pi directory called ‘scripts’ and then used nano to edit the script.

#!/bin/bash
#
# update .rrd database with CPU temperature
#
# $Id: update_cputemp 275 2013-05-16 05:20:56Z lenik $
cd /home/pi/scripts
# create database if not exists
[ -f cputemp.rrd ] || {
/usr/bin/rrdtool create cputemp.rrd --step 300 \
DS:cputemp:GAUGE:1200:U:U \
RRA:AVERAGE:0.5:1:3200 \
RRA:AVERAGE:0.5:6:3200 \
RRA:AVERAGE:0.5:36:3200 \
RRA:AVERAGE:0.5:144:3200 \
RRA:AVERAGE:0.5:1008:3200 \
RRA:AVERAGE:0.5:4320:3200 \
RRA:AVERAGE:0.5:52560:3200 \
RRA:AVERAGE:0.5:525600:3200
}

 

Run the script with the bash ‘name of your script’ command.

Now create a script which will update the graph: – you might want to edit the line cd /home/pi/scripts to point in the right location. The last line starting cp copies the png file to the content folder on the ghost server. Again you might want to edit that.

#!/bin/bash
#
# update .rrd database with CPU temperature
#
# $Id: update_cputemp 275 2013-05-16 05:20:56Z lenik $
cd /home/pi/scripts
# read the temperature and convert .59234. into .59.234. (degrees celsius)
TEMPERATURE=`cat /sys/class/thermal/thermal_zone0/temp`
TEMPERATURE=`echo -n ${TEMPERATURE:0:2}; echo -n .; echo -n ${TEMPERATURE:2}`
/usr/bin/rrdtool update cputemp.rrd N:$TEMPERATURE
/usr/bin/rrdtool graph cputemp.png DEF:temp=cputemp.rrd:cputemp:AVERAGE LINE2:temp#00FF00
cp /home/pi/scripts/cputemp.png /home/pi/ghost/content/images/

Test this script with bash ‘name of your update script’ – run it a few times and you should see the green line start to grow on the png graph.

Finally because you don’t want to keep having to run the script manually you need to add it to crontab:

crontab -e

 

and then add the line:

*/5 * * * *   ./scripts/CPU_temp.sh

 

the */5 bit means run every 5 minutes, and again you might need to edit the location and name of the script.

RRDtool is quite simple – there are projects out there that use external sensors to track temperatures outside the Pi. Part of me is wondering if running RRDtool a lot and reloading the PNG file will then start increasing the temperature of the CPU in a sort of observer effect feedback loop…