Category Archives: Gadgets

Indiana Jones Idol Swap party game

My sister in law does epic children’s parties (a couple of years back I had a lot of fun playing Snape and being mean to all the kids who weren’t in Slytherin) and this year I was given a request to build a game for an upcoming Indiana-Jones themed party.

Remember that bit at the very beginning of Raiders of the Lost Ark where Indy has to balance the idol with a bag of sand to avoid the traps going off?

“Can you build a game that does that?”

So I started thinking along the lines of using an Arduino coupled with a weight sensor which triggers an attached Raspberry Pi to play a tune when the idol is balanced, all packaged up inside a suitably rock looking biscuit tin:

I've got a bad feeling about this
I’ve got a bad feeling about this

The idea would be the idol would be swapped, the Arduino would detect the swap, determine if the weight was different and then set off an alarm and rumble motor if it was. If it was the same weight it would play the Indiana Jones music.

The Arduino has lots of analogue pins that can read changes in voltage, and the Pi can take care of the music and sound effects – it would also be possible to  hook it up to a TV to play the appropriate bit of the film, as chasing down seven year olds with a giant boulder / dart traps / snake pits might not go down well with their parents.

Initially I looked at using a load cell sensor similar to what’s found in electronic scales, however I discovered that the resistance generated by these sensors to be really tiny, and it’s not just a simple matter of hooking them up to an Arduino. Note – since I built my initial version Sparkfun have actually brought out a handy load-cell amplifier kit that should make this possible for version 2!

So instead I opted for a much simpler force sensor – these are widely available and their resistance can be easily measured, but they’re also a bit inaccurate. For the purposes of the game and to add a bit of random variability I decided to go with this simpler route.

My arduino circuit is as follows – it includes an LED to indicate if the pressure sensor is detecting the idol properly. The Arduino communicates with the Pi over serial to then trigger the appropriate sound file. I ran out of time to include the rumble motor but it would be quite easy to add one.

Adafruit have a tutorial along with some suitable code which can be used to send the force sensor output to the Raspberry Pi  via serial:

/* FSR testing sketch. 
 
Connect one end of FSR to 5V, the other end to Analog 0.
Then connect one end of a 10K resistor from Analog 0 to ground
Connect LED from pin 11 through a resistor to ground 
 
For more information see www.ladyada.net/learn/sensors/fsr.html */
 
int fsrAnalogPin = 0; // FSR is connected to analog 0
int LEDpin = 11;      // connect Red LED to pin 11 (PWM pin)
int fsrReading;      // the analog reading from the FSR resistor divider
int LEDbrightness;
 
void setup(void) {
  Serial.begin(9600);   // We'll send debugging information via the Serial monitor
  pinMode(LEDpin, OUTPUT);
}
 
void loop(void) {
  fsrReading = analogRead(fsrAnalogPin);
  Serial.print("Analog reading = ");
  Serial.println(fsrReading);
 
  // we'll need to change the range from the analog reading (0-1023) down to the range
  // used by analogWrite (0-255) with map!
  LEDbrightness = map(fsrReading, 0, 1023, 0, 255);
  // LED gets brighter the harder you press
  analogWrite(LEDpin, LEDbrightness);
 
  delay(100);
}

This also lights up an LED to give useful visual feedback – the Pi then just listens on the serial input and triggers the according sound effect.

Assembled the sensor looks like this (the force sensor is under the lid of the coffee tin):

Indiana Jones style trap game
Indy was out so Han stepped in

Inside my ‘Idol’ (which was a papercraft model printed on shiny paper), was a counterweight made from a stack of pennies – this is reasonably heavy and I was able to adjust the sensitivity of the circuit to detect the presence (and absence) of the Idol.

To build the pedestal I used an octagonal quality street plastic box, covered in paper mache and spray-painted with stone effect spray paint. The arduino and pressure sensor were contained inside a metal coffee tin.

On detecting the Idol being removed, the Pi plays the sound sample “It belongs in a museum” from Raiders of the Lost Ark, if the sensor is successfully fooled it plays the Indiana Jones theme!

After a bit of play testing we found that balancing the idol was very hit and miss – although a handy rock nearby seemed to do the job most of the time. Ideally this would use the much more accurate load cell to measure the weight of the idol and compare it to the bag of sand after a button press. I still have all the parts, so I’m just waiting for the next time someone in my family holds an Indiana Jones themed birthday party.

Indiana Jones Idol Swap game
Here it is (running off a USB battery)

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.

ASCII camera with the Holga 120d

So now I’ve finished my digital Holga project, one of the things I wanted to do was to get a bit creative with it – so here’s my first attempt at an ASCII art generating camera.

Holga 120d ASCII text image
High contrast images work best.

This uses the ASCII art script written by Steven Kay, please visit his blog to find out more – I’ve modified the original script to use the python picamera library – this helps speed up the image resize. There’s also a timestamp added to the text file which uses the same script I wrote about in my previous Holga post.

If you just want to run Steven Kay’s script you’ll need the python imaging tools – install with

sudo apt-get install python-imaging

Here’s my modified script:

'''
ASCII Art maker
Creates an ascii art image from an arbitrary image
Created on 7 Sep 2009

@author: Steven Kay
'''

import time
import picamera
from PIL import Image
import random
from bisect import bisect

# greyscale.. the following strings represent
# 7 tonal ranges, from lighter to darker.
# for a given pixel tonal level, choose a character
# at random from that range.

greyscale = [
            " ",
            " ",
            ".,-",
            "_ivc=!/|\\~",
            "gjez2]/(YL)t[+T7Vf",
            "mdK4ZGbNDXY5P*Q",
            "W8KMA",
            "#%$"
            ]

# using the bisect class to put luminosity values
# in various ranges.
# these are the luminosity cut-off points for each
# of the 7 tonal levels. At the moment, these are 7 bands
# of even width, but they could be changed to boost
# contrast or change gamma, for example.

zonebounds=[36,72,108,144,180,216,252]


#take photo

with picamera.PiCamera() as camera:
                        camera.capture('image.jpg');

# open image and resize
# experiment with aspect ratios according to font


im=Image.open(r"image.jpg")
im=im.resize((160, 75),Image.BILINEAR)
im=im.convert("L") # convert to mono

# now, work our way over the pixels
# build up str

str=""
for y in range(0,im.size[1]):
    for x in range(0,im.size[0]):
        lum=255-im.getpixel((x,y))
        row=bisect(zonebounds,lum)
        possibles=greyscale[row]
        str=str+possibles[random.randint(0,len(possibles)-1)]
    str=str+"\n"

print str

date_string = time.strftime("%Y-%m-%d-%H:%M:%S")

text_file = open('image' + date_string + '.txt', "w")
text_file.write(str)
text_file.close()

There are lots of settings to tweak – the image above was generated by the script – and bear in mind this is designed to be viewed with black text on a white background. Perhaps I’ll see if I can dig out an old dot matrix printer from somewhere.

For a blog of ‘photos’ updated whenever I take them and am in range of WiFi check out:

http://holga120d.blogspot.co.uk/

This emails the ASCII art in HTML format to blogger whenever I take a photo (and the Pi Holga is in range of the internet).

For more about the Digital Holga check out my previous blog posts on the hardware and building the case.

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!

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…

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…

 

Kano the Raspberry Pi go mainstream?

Since its launch the Raspberry Pi has been phenomenally  successful – with over 2 million units of the little computer sold around the world, it’s arguably kick-started a revolution in cheap, educational computing.

The only slight worry about this is how many Raspberry Pi computers have landed in the hands of kids (who it was really intended for) as opposed to 30-something computer nerds who are re-living their 8-bit computing childhoods, or networking the family toaster. Arguably there’s nothing wrong with that as the enthusiasts provide a ton of support but sometimes it’s easy to lose site of the goal of the project in the first place.

Then there’s the Raspberry Pi’s biggest competitor – the tablet computer. Many kids will be given tablets as they’re ‘educational’ devices – and given the choice of an instant on, readily usable ipad that can play games as well, the Raspberry Pi has its work cut out to avoid the drawer of forgotten devices.

So enter the Kano project – a kickstarter that raised over 1 million dollars, and effectively bundles the Raspberry Pi up with some nice hardware and some trendy design. Marketed as the computer you can build, it’s taking aim at the educational market in the hope that the kids will put down their iPads and have a go.

The Beta version of the Kano OS software part of the project launched this week so here are some first impressions.

In order to prepare your SD card Kano requires a burner program to run on a PC or Mac – although this does the job, it’s not quite as elegant as the NOOBS drag and drop method which has now become the standard for most Raspberry Pi software.

It did work on the first attempt
It did work on the first attempt

On bootup you get asked a few questions in the terminal, in the style similar to a text adventure. This is actually a rather nice touch. It neatly introduces the idea of the text interface and entering commands, and makes typing startx rather exciting (there’s a countdown!). I can imagine this being fun with a classroom of kids trying out the Raspberry Pi for the first time.

Not the command line you know
Not the command line you know

This first person theme continues as you use the computer – one nice touch is the bundled wi-fi setup app asks you to test your internet connection with the ping command (thus introducing the idea for later).

Once you get past this you’re presented with the Kano desktop. It’s beautifully designed with nice flat icons for the various apps. Chromium is the default web browser and it runs at a decent speed, and there are some bundled apps for creating programs.

Even as a Beta it feels quite polished.

Overall Kano OS is much simpler and less cluttered than other Raspberry Pi distributions and everything you really need is still there.

The tabletty desktop
The tabletty desktop

Lots of things here will be already familiar to anyone who’s used a Pi before – the command line is still accessible, so despite its user friendly interface there’s still the option to type proper linux commands.

The apps that have had the most work done to them are the programming tutorials – these allow you to mess around with a game of snake or pong using the drag and drop interface of scratch, and there’s also a split screen Minecraft app that is quite clever. It doesn’t take long at all to start really using the Pi and trying out different projects.

Here's pong with garish colours!
Here’s pong with garish colours!

It’ll be interesting to see how this software progresses – there are definitely some good points, and as something I could load onto a Raspberry Pi and give to some kids to play with it perfectly fits the bill; and it does still include the vital command line for anyone that gets curious as to what’s running their computer behind the scenes – something that a tablet computer lacks.

One thing I wonder though is exactly how the Kano kit fits in with the other Raspberry Pi distributions – I’m not sure if the aim is to get this to fit alongside the other Raspberry Pi distributions (for instance including it as part of NOOBS) or to sell it separately. Raspbian’s open source nature has led it to be massively improved over the years by the community – and it would be a shame if Kano OS missed out on this.

You can try out Kano for yourself at kano.me

The kit launches sometime this year with a custom keyboard – I’ll be reviewing that as well.

The smallest USB mechanical keyboard in the world*

Sometimes it’s annoying when your favourite old school mechanical keyboard lacks some of the modern function keys that we’ve grown used to using in recent years. Or you might be re-purposing a keyboard for a use it wasn’t really designed for – I have a lovely chicklet keyboard with my Raspberry Pi Motorola Lapdock hack which lacks both left and right windows keys.

You can of course usually find a way round these limitations by hitting control and frantically hammering in the number of the function key (if you can remember it) – but sometimes that doesn’t work. For example the ArcEm emulator that runs on the Raspberry Pi RISC OS requires both left and right windows keys to be pressed simultaneously to exit.

Fortunately to the rescue is this – the smallest USB mechanical keyboard in the world (probably):

Smallest USB keyboard in the world
Now I just need a portal gun

The blue Cherry MX keys are illuminated, and for 10 seconds when you first plug it in you can remap them to almost anything (including words and short phrases). I did find a couple of programmable USB keystrips that offered similar functionality, but these were a bit expensive and lacked mechanical keys. If you shop around for the parts you can build this for less than £15.

Build guide:

First you need a few parts:

  • An Adafruit USB trinket (5v) In the UK available from Pimoroni
  • 2 x MX cherry keys (try ebay – e.g. this listing)
  • 2 x keycaps (lots on Amazon)
  • 2 x 3mm LEDs (and a 50 ohm resistor)
  • A mini (the older not micro) USB cable
  • Some wire
  • A suitable box (the one I used was a little on the small size – something 6cm x 3cm x 3cm might be better)
  • Craft knife, dremel, soldering iron, multimeter with continuity tester

This project does require a bit of soldering – I opted to solder the pins onto the the trinket, and then attach the wires using female jumper cables – for a neater build you could solder the wires directly between the cherry keys and Trinket. If you’re opting for total neatness you can also solder the USB wires directly to the underside of the Trinket as there are some surface mount tabs.

A costlier but wireless alternative to the Trinket is the Adafruit Bluefruit EZ HID keyboard controller again available from Pimoroni in the UK.

Putting it together

This is based on the Adafruit USB Trinket – a very cut down minimalist Arduino clone (it runs some simple Arduino code no problem, but needs it’s own version of the programmer tool). Adafruit have a tutorial which shows how to wire up a Trinket to act as a USB HID along with a couple of code examples.

First step is to try out the Adafruit tutorial on some breadboard – if you get stuck head over to the forums where Frank can help – to get this to work on my Mac I needed to plug the USB cable into a USB 2 port directly (not via a hub) and use the experimental library. Make sure you’re using Adafruit’s version of the Adruino IDE – all the info is on the Trinket page.

Adafruit Trinket as a USB keyboard
Trinket as a USB keyboard

Plug this in and try out uploading the sketch – when you first connect the Trinket the red LED will blink for 10 seconds – you have to hit the upload button on the Arduino IDE app in this time for it to work. Once the red LED has stopped blinking, your computer should recognise the keyboard.

We’re using exactly the same circuit, with the exception of adding 2 LEDs in series. The trinket has a 5v pin which supplies just about the right amount of power for the LEDs I used but check with an LED circuit calculator to see if you need to add a resistor. The Cherry switches have 2 small holes for the LED wires to sit in.

Next we need to prepare the keys and a box for them to sit in – here for some Dremel action!

Photo of USB keyboard before assembly
all the bits, prior to wiring

The Cherry keys are wedge shaped so cut a hole slightly too small and then widen using the Dremel – they are about 12mm square. I did find this a little messy and resorted to using a glue gun to tidy things up! for a neater build you could try a hot knife cutter, or for the über neat build 3d print a proper case. Fortunately once the keys are in place you don’t really see the holes.

Once the keys are fitted, solder on some wires. Note that the pins from the cherry keys are quite brittle (they’re designed to sit in a printed circuit board) so avoid bending them if possible.

The wiring arrangement I used was this:

Cherry keyboard wiring
Cherry keys viewed from the underside

Make sure the LEDs are wired in series (+ to – to + to -) – you can identify the positive (anode) lead on the LED as it’s the longer one. The LED and key circuit can all share the same ground connector. It doesn’t matter which way round you add the resistor.

Once you’ve got everything soldered together, plug it in and test – especially before putting the box together. I found cramming it all into the case a bit tricky but managed it just. I cut up a USB mini cable and re-soldered the wires to fit in the box. As I mentioned previously – soldering the wires directly to the Trinket would save a lot of space.

USB keyboard internal wiring
here it is, tight fit.

Finally enjoy your mechanical keyboard! – although this has only 2 keys, the action on the Cherry MX blues is so nice I’m now thinking I might need to invest in a proper full size one.

*probably – I’m not expecting a call from Guinness just yet.

Update – I’ve potentially been outdone with the single key keyboard which has been launched on Kickstarter.