Categories
Arduino Creative Family Gadgets Geekery Raspberry Pi

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)
Categories
Gadgets Geekery Raspberry Pi

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

Categories
Gadgets Geekery Raspberry Pi

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.

 

Categories
Activism Raspberry Pi Work stuff

Raspberry Pi powered General Election Swingometer

In the UK it’s election time again and the BBC are preparing to wheel out the latest version of their Swingometer. The BBC Swingometer dates back to 1959, and was a visual device for displaying the balance in seats won by the two main political parties. The Swingometer coined a whole load of phrases along the lines of a ‘swing away’ or ‘swing towards’ a particular party or candidate, and was well suited towards the simple days of two party politics.

Here’s version 1.0 back in 1959:

There's a chap with a pipe behind controlling the arrow
There’s a chap with a pipe behind moving the arrow (photo BBC)

The BBC have more or less stuck to the same device for every election since, although sadly in the same way that CGI ruined the Star Wars films, Swingometers have recently become more and more complicated. This is perhaps also a consequence of the UK moving to multi-party politics where working out who exactly in power after polling day is getting a bit complicated.

Here’s version 14.0 from 2010:

There's just a big green room
There’s just a big green room (photo BBC)

In a tribute to the original, the charity I work for – Concern Worldwide have been using a Development Swingometer, which pays homage to the original 1959 version and tracks the number of candidates who have signed up to support Concern’s 5 pledges on fighting global poverty and protecting international aid (you can tweet them on that page with some code I mashed up using TheyWorkForYou.com and YourNextMP.com).

https://twitter.com/ConcernUK/status/593761711020183552

Building a Raspberry Pi powered Swingometer

As our low-budget version is a bit simple, for a bit of fun I thought I’d build a slightly more technical version that updates itself automatically. My updated Swingometer uses a servo to move the arrow, and a Raspberry Pi to fetch the ‘swing value’ from a web page when you push the big friendly button. The code I’ve used can be edited to fetch more or less any numerical value from a web page and turn it into a ‘swing’ so It should be possible to repurpose this into a political swingometer, or something that displays anything with a value of 1-180 (the angle of swing possible with a servo).

Push the button for results
Just push the button for the latest results

The back of the frame (£5 from Wilko) shows the Raspberry Pi model A and a little slice of Pi board I soldered up. There are two buttons – the big friendly update button for the front and a safe shutdown button on the back, so I can run this without a screen and keyboard.

Here's the back with an arcade machine button and the wiring to the servo
Here’s the back with an arcade machine button (white wires) and the wiring to the servo (brown – red – yellow wires)

The method I’ve used to control the servo is similar to RaspiTV’s Raspberry Pi flag waving post – although I opted for the version detailed in the Raspberry Pi cookbook over Adafruit’s single servo control. For my power supply I used a D-link powered USB hub to supply both the Pi and the Servo via separate USB cables. This results in a slightly wobbly update of the Swingometer arrow, which suits me fine. For more precise control you can use a dedicated servo control hat which can control up to 16 separate servos.

https://twitter.com/kimondo/status/595957624614563841

For the code I modified the Raspberry Pi cookbook tutorial code to fetch a value from a web page using Beautiful Soup. You can install this on the pi using:

sudo apt-get install python-beautifulsoup

Note that this installs version 3 – but you’re still able to do lots of clever things to grab content from web pages. If you want to build a political swingometer I’d suggest grabbing values from the election forecast page. There’s a lot more information about using Beautiful Soup on the web page here.

Here’s the code I’ve used to update the swingometer:

import RPi.GPIO as GPIO
import time
from BeautifulSoup import BeautifulSoup
import urllib2

#change this bit
url="http://www.kimondo.co.uk/swingometer-control/"
page=urllib2.urlopen(url)
soup = BeautifulSoup(page.read())

value = soup.find('span',{'style':'color: #99cc00;'})
value = value.next
value = float(value)

print value

GPIO.cleanup()
GPIO.setmode(GPIO.BCM)
GPIO.setup(18, GPIO.OUT)
pwm = GPIO.PWM(18, 100)
pwm.start(5)
t_end = time.time() + 1

while time.time() < t_end:
        print value
  angle = value/100.0 * 180
  print angle
        duty = float(angle) / 10.0 + 2.5
        pwm.ChangeDutyCycle(duty)

exit()

An alternative I considered was using the Sentiment 140 twitter sentiment tracker API – this tracks positive and negative sentiment towards keyword searches on twitter – although it seems to get fooled by ironic tweets.

If you’ve been inspired to build a Swingometer please share it in the comments! One day I’d quite like to build something like the Weasley clock.

You can ask your election candidates to support Concern’s 5 pledges to fight global poverty and support development here and my fantastic blog about the Development Swingometer on Concern’s website.

Categories
Creative Family Geekery Raspberry Pi

5 geeky DIY Christmas gift ideas

With Christmas rapidly approaching, one of my aims this year is to at least attempt a bit of DIY Christmas gifting. So if you know me, there are potential spoilers ahead and stop reading this right now. So here are five ideas I may or may not be considering as part of my Christmas gift ideas. These really are quite geeky, but then so are most of my friends and family.

1. 3d printed jewellery

We don’t all own 3d printers (yet) particularly ones that can print in precious or semi-precious metals. But head over to Shapeways – a website with a name that sounds like it’s straight from an episode of the Hitch-hikers Guide to the Galaxy and you can print more or less anything you can practically design provided it’s in a format they support. You can also order a printed version of your idea in cheaper plastic before committing to a more expensive material.

For a less daunting project you can contact some of the designers to create customised versions of their work. Lots of designs are available on Thingiverse for you to download and edit (including the ring shape below).

http://www.thingiverse.com/thing:7354
Thingiverse Ring, it’s a thing.

2. Make your own lego brick shaped bath bombs

So slightly less technical but fun nevertheless is to make your own bath bombs or fizzies. These are compacted cubes of Sodium Bicarbonate and Citric Acid that bubble Carbon Dioxide when you chuck them in the bath:

C5H7O5COOH + NaHCO3 → C5H7O5COONa+ + H2O + CO2

Here’s a nice recipe from Busy City Mum’s blog for Bath Fizzies which goes into detail about what quantities and ingredients you need. You can now buy silicon moulds in lots of shapes including Lego brick (lookalikes, not official) and the Death Star (not a moon).

In Japan it’s tradition to include a figure inside the bath bomb, so a Lego minifigure would seem appropriate!

3. A custom Raspberry Pi

A very neat little computer

 

I had to include a Raspberry Pi based project – there are lots to choose from including Media players and retro computer emulators – but for this I wanted to find something that would be suitably difficult to purchase. One possibility is the Raspberry Pi magic mirror which is detailed on it’s creator’s blog – this is something you simply can’t buy, and looks amazing – although you’ll need a monitor and a mirror for the full effect.

My simpler project is to build a Raspberry Pi audio streamer. Audio streamers are generally very expensive and although the Pi’s default audio output is fairly basic it’s possible to add a DAC to provide really high quality sound output. Thanks to Carla at busycitymum.com for sending me a Wolfson Pi I was able to build a fairly decent Pi Music Box with Airport support.

The recipe for this is as follows – I’ve confirmed this to work with the original Wolfson Pi Audio Card and a Raspberry Pi model A – there is a new version of the Wolfson card available for the newer Raspberry Pi models.

  • Download the custom version of Raspbian from www.element14.com/PiAudioCard – on the Mac the custom version of Raspbian unpacks best if you use Stuffit Expander and then Apple Pi Baker to copy the iso file to an SD card.
  • Install Shairport using these instructions from Drew Lustro
  • For a final bit of polish (particularly if your running a Raspberry Pi as a headless server) you can include a web based shutdown control panel – follow the instructions on the forum here. You can edit the web page to include a nice message to your gift recipient as well!
IMG_2679
Raspberry Pi Airport speaker

DIY projects that work with Apple products go down quite well.

4. Bake!

Baking is a much appreciated gift – and given the diversity of cookie cutting shapes available it’s possible to give a nerdy spin on even the most traditional recipes.

Firebox do a nice line in Tetris Cookie cutters – combined with a Gingerbread recipe these make for a pleasing tessellating gift.

I’ve tried a few different gingerbread recipes and Delia’s is by far the best. Thanks to the additional spoon of black treacle the gingerbread is sufficiently biscuity – and you can vary the cooking time if you want a more chewy gingerbread. Other recipes don’t work as well since they opt for either golden syrup or black treacle. Cowards.

Combine with an original Gameboy (search for DMG1) for added wow factor. Works particularly well on millennials.

Gingerbread Tetris
Gingerbread Tetris

5. Give a DIY gift

So technically cheating, but you can also give the gift of DIY. I recently reviewed the StoneTurners DIY microscope

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

which can take awesome pictures of things, and works with the Raspberry Pi.

If you want to spend a bit more the DIY projects from Technology will save us are worth a look.  Although they’re more expensive than shopping around and buying the parts, the packaging is lovely and they make quite complicated projects accessible. Plus angry birds on the Arduino is very addictive…

Categories
Gadgets Geekery Raspberry Pi

£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.

Categories
Arts Code Gadgets Geekery Raspberry Pi

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.

Categories
Gadgets Random Raspberry Pi

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!

Categories
Code Raspberry Pi

How to find a Raspberry Pi on your network

Here’s a quick tip to finding a Raspberry Pi (and anything else) on your network using the nmap network scanning security tool.

Quite often you might want to run a ‘headless’ Raspberry Pi without a screen or keyboard, using SSH to connect. SSH can be enabled in the config menu when you first boot the Pi. You can then find the IP address of your Pi when you’re initially setting it up using the ifconfig command in the terminal. Normally this works like this – on the Pi you want to connect to, type into the terminal:

ifconfig

Note the value next to “inet addr” – which usually looks like 192.168.1.(a number) – Then from another machine you can SSH to your Pi to allow for remote control

ssh pi@[the ip address of your pi]

This is fine, but most home networks use something called DHCP – ‘dynamic host configuration protocol’ – local IP addresses are temporarily assigned to the computers by your router (the DHCP server). Although these addresses often don’t change, they can. You can assign a static IP address which is something i’ve used in the past, or install a service like no-ip that tracks your Pi’s IP address (and makes it available over the internet as well). You also need to be able to connect a screen to the computer you’re attempting to connect to!

A simpler method is to use a tool called nmap (network map)- there are versions available for windows and mac, and it works from a Raspberry Pi. It’s also free.

For instance, you might have a Raspberry Pi setup on your network with a monitor and keyboard, and you’ve plugged a second Pi in that’s running SSH.

Install nmap with:

sudo apt-get install nmap

and then use the following command:

sudo nmap -sP 192.168.1.*

Returns a list of ips and hostnames – just look for the one called Raspberry Pi – This takes about 30 seconds.

Just like the matrix
Just like the matrix

Nmap does a lot of other things as well – and it’s the program of choice whenever movies attempt to depict computer hacking, or if you want to hack into Matt Damon’s brain.

If you’re looking for a more portable version there’s a (paid for) tool called Scany which is available for the iPhone and iPad or Fing which is free.

 

 

Categories
Raspberry Pi

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.