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:
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.
Passing values to tweetyourmp.com in this way works with spaces, but safer to encode the message and postcode parts using http://andrewu.co.uk/tools/uriencoder/ to replace characters with %20 for a space.
hello @ChukaUmunna your twitter message via @kimondo
as the tweet.
Important note on using hashtags
I had to use a bit of a hack to make it possible to have a pre-filled tweet with a hashtag. As # is used to denote an anchor link when you stick it in a URL the rest of the URL gets ignored by the bit of the code that reads the tweet from it.
To get round this use an asterisk * in place of a hash # – the code then puts the hash back in when it sends the tweet:
hello @ChukaUmunna your twitter message #hashtag via @kimondo
The salutation is fixed as ‘Hello’ but can be changed – is important not to begin the tweet with the @handle as it reduces its visibility and ‘Hi’ is a bit American sounding hence the hello.
Next on the list is building some sort of Raspberry Pi based tweet totaliser. You can download the (very simple) code that runs Tweet your MP on GitHub – a couple of interesting options are to use the code in a thankyou email after a supporter has completed an action to give it a bit more impact, or to sort through your data and merge in constituency contacts in an email.
Note that some MPs don’t consider twitter an ‘official’ communication format so this is best combined with an email or letter to an MP.
tweetyourmp.com is made possible thanks to the theyworkforyou.com API – this is free for charitable use up to 50,000 queries.
Update: I’ve now added a page that automates this process and builds a bit.ly link with the correct address!
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.
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
from PIL import Image
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 = [
# 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.
with picamera.PiCamera() as camera:
# open image and resize
# experiment with aspect ratios according to font
im=im.convert("L") # convert to mono
# now, work our way over the pixels
# build up str
for y in range(0,im.size):
for x in range(0,im.size):
date_string = time.strftime("%Y-%m-%d-%H:%M:%S")
text_file = open('image' + date_string + '.txt', "w")
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:
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:
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
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.
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.
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.
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:
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.
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:
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…
Thanks to the lovely people at Farnell UK I have 4 Xtrinsic sensor evaluation boards to give away. These boards include a stack of sensors (altitude, pressure, magnetometer and accelerometer) attached to a Freescale Freedom Development Platform board which has a multicolour LED and a touch pad.
Out of the box the boards show up as a USB drive when attached to a PC, and it’s possible to load apps to the board – the Farnell kit comes with a script that displays the information from the various sensors via a USB/Serial interface.
At the moment the board instructions are for PC, although there is a Linux driver available.
There’s potential for lots of really interesting projects with these boards, so here’s how to win one*:
Just come up with an idea for a project using the board – can be anything you like, from the complicated to the simple – and add it as a comment below.
If you want to include a bit of information (or write a blog about your idea) link to it from your comment.
I’ll pick the 4 I like the best and send out the boards. The closing date is the 7th of December 2013 so you have a week to get your thinking caps on.
I’ll feature the ideas – and follow up on how the projects went on in a later blog post.
*droids not included. I live in the UK but will post anywhere but it might take a while to arrive. Decisions are all final. Boards supplied by Farnell UK who send me nice stuff from time to time.
The competition has now closed, thank you to everyone who entered, I’ll be sorting through the ideas and contacting you if you’re a winner.
Here’s a little project to build an LED web counter for your blog. Proudly(!) display the number of visitors on a retro LED display, using the wordpress stats API – or potentially using any web accessible stats page.
You’ll need a Raspberry Pi (could even be the computer that’s hosting your blog) and a WordPress blog – either hosted yourself and using the Jetpack Stats plugin or on WordPress.com.
For this project I’m using a Python library called beautiful soup which can grab information from a web page – so as well as using this script to display a web counter, you could use it to display any information scraped from any accessible web page.
If you’re not using WordPress you could also do this using google analytics and the Embedded Analytics service, or by using your own counter installed on your website (see ideas below).
The Python script grabs the value from the web, and then sends it to the Pi’s serial port where it is displayed on an LED matrix.
For my project I’m using the Wharfe-Education.com BelleVue kit which fits neatly inside a Ferrero Rocher box and has a nice Back to the Future look about it. For 15 quid it’s a nice easy to solder together kit which features a 6 figure 7 segment LED display.
First make sure the Pi is powered down before attaching anything to the GPIO pins.
To attach the BelleVue to the Pi, you’ll need to attach the TXD (transmit), 5v and GND (ground) pins on the Pi’s GPIO to the inputs on the BelleVue – the right is a diagram for reference: – TXD on the Pi goes to RxD on the BelleVue, 5v on the Pi goes to Vcc and GND to GND.
For reference the diagram on the right shows the top row of GPIO pins with the Pi logo and text on the board the right way up – on the BelleVue it’s the 3 pins on the left hand side as you look at the board, again with the text the correct way up.
When you power on the Pi a sequence of characters will be sent out across the serial port. It is possible to disable this using the instructions found on the Raspberry Pi Spy website here – although they are for the Pi-Lite they equally apply to the BelleVue or any arduino powered LED display.
The Raspberry Leaf provides a handy guide to get the correct pins on the GPIO – or you can use the Adafruit cobbler and some breadboard. The serial port pins are in the same location for all revisions and A and B models of the Pi.
or a Pi-Lite for a scrolling ticker board effect. The Pi-Lite just plugs into the GPIO and sits neatly on top of the Pi. I’ve found that the transparent Mod-My-Pi.com case perfectly fits over the Pi-Lite:
Alternatively if you’re up to the challenge (and want to save some cash) you could make your own – the Pi-Lite, BelleVue and LED matrix boards are all LED modules driven by Arduino based micro controllers and there’s a handy tutorial here which also includes the code you need.
First on the Raspberry Pi we need to install pyserial to make use of the Pi’s serial port:
Replacing yourAPIkey and blog_uri with your values. The final part of the URL defines what data is returned. You should see a plain text message of “views” and a number if everything is working properly. The &days=-1 returns the total number of unique visits to the site – you can replace this with &days=1 for number of views in the last day or &days=30 for number of views in the last 30 days, etcetera.
Once you’re happy with your URL, create a new python script – either on the Pi Desktop or on the command line using
Command – you should see your attached LED display list the number of visits to your site. This will loop with the same value until the script is stopped or run again.
Finally – but we don’t want to be constantly typing in the commands to run the script all the time – to get by this we’re going to use cron (short for cronometer – a regular clock that does things at regular intervals). For a bit more info about cron check out this blog from David Singleton.
We can set cron to run our webcounterticker.py program every minute:
sudo crontab -e
Opens your cron table in the nano editor – you just need to add
* * * * * sudo python /home/webcounterticker.py
and then control-O to save and control-X to exit. You might need to adjust the line above depending on where you saved your python script.
A few other ideas:
Once you’ve got your LED display running you might want to think of a few other things to do with it:
You can use Embedded analytics to generate a copy of your Google stats to use with the Beautiful Soup library
Use your own web counter – e.g. this php script (which I’m currently using on the footer of GhostPi.org)
Host a blog on the same Raspberry Pi that is running the web counter
Build an Ashes scoreboard to record England’s epic victory over Australia
Build a rack of LED counters for Web visits, Twitter followers, Emails sent or other things you want to measure (and show off)
Buy a DMC-12 on ebay and turn it into a time machine
As always, corrections and improvements are welcome!
Here’s a quick guide to running the ghost blog platform on a $25 Raspberry Pi.
Ghost is a new piece of blog software, currently under development which was recently funded by a Kickstarter campaign. Ghost is a completely new blog platform which aims to concentrate on writing and has a really nice minimal, instantly updating theme.
Ghost uses node.js (a new one on me) and can run on the Raspberry Pi computer. So I thought I’d put together a few instructions based on my trial and error. You need to be a Kickstarter backer to download the code, although this will be released fairly soon.
This assumes you’re running the latest raspbian build.
replace “host: ‘127.0.0.1’” with “host: ‘<your IP address>'” and “port: ‘2368’” to “port: ’80′”.
and then enter your Pi’s ip address onto another computer on your network – you should now see your Ghost blog!
If found it very occasionally slows down when setting up users, but once I started adding posts and images it worked really smoothly on the Pi. Having a window open with an SSH session is interesting to see the software updating as you edit and create posts on the blog.
First impressions? it’s very minimal, but the lack of distractions makes this feel like a very creative blog platform to use – it’s not going to compete with the likes of wordpress and drupal for building fully fledged CMS websites, but as an alternative to tumblr or blogger it has a lot of potential.
Ghost’s approach will be to offer the software as a free download for self hosting, or paid accounts via the website (like wordpress).
I’m looking forward to see how this evolves in time, hats off to the Ghost team.
Update: making your local blog available on the internet:
I’ve been making my ghost test blog available on the internet – this is handy if you want to be able to update your blog from anywhere – although I wouldn’t recommend it for a production website that might get a lot of traffic, as it’s entirely dependent on your home broadband.
This is assuming you have a residential broadband account (I’m using BT broadband). Most home accounts used dynamic IP addresses, assigned by your service provider that change each time you connect to the internet – we’re going to use a service called no-ip.com which uses a program on your Pi to find out it’s address, and update a domain to point to this address. We’ll also need to open a port in the home router to allow connections to the Pi.
First sign up for an account at noip.com – there is a free option available, or you can opt to pay $15 a year for a service with more features.
Add a host, and choose a hostname from the list of options.
Next choose the DNS-A host option and save. The settings I’ve been using are below.
Next, on the Pi download and install the noip software (here are the instructions from RaspberryPihelp.net – check out their page if you want no-ip to run each time you switch on your Pi)
Here’s another super simple widget, for creating links that generate tweets when you click on them.
I use these links a lot in marketing type emails for work and tend to use quick and easy online tools (because I’m lazy), but I’m always slightly nervous about sending links via another website, that might get shutdown or move.
This makes use of the bit.ly API so you can track the number of clicks on your link, and then compare that to the number of tweets sent – check it out below:
You can download the source on github – feel free to hack about with it. It’s just 3 files (including the CSS). You just need a website that supports PHP which most do, and a bit.ly account.
Edit the settings at the top of the bitlytotweet.php file to include your source (this can be anything), username and API key. As this script makes use of your own bit.ly account you might want to hide the widget page and not make it public.
Earlier this year Holga Direct created a digital version of the Holga – the 120d as an April fool joke – although my version lacks the 73 megapixel sensor and retina back display it does actually exist, can take nice pictures and is fairly easy to build yourself if you’d like to give it a try.
The aim of this is to build a neat case which fits the Raspberry Pi and camera module, and to do a bit of experimenting with the GPIO (General Purpose Input and Output) pins to use them to control various aspects of the camera. Lacking instant feedback and having no idea what you’ve captured until you take it home also fulfils some of the ideas behind retro analogue photography made popular by Lomography. It also looks a bit hipster.
This is a fully working Digital Holga 120d – it used the case from a broken Holga, unfortunately it doesn’t use the original plastic lens (although I have kept this) as the Pi Camera board has it’s own built in lens, however it is now possible to use screw on lenses and filters.
The case is now finished but I have made a few changes since my last post:
I’ve lost the external USB port as there wasn’t quite enough space inside the case to fit the USB plug – I am now using a nano wifi adapter inside the case – specifically the Edimax EW-7811UN adapter which works well with the Raspberry Pi model A and fits inside the case.
Along the way I’ve added a few extra parts:
A 49mm adapter ring on the front lens – it is now possible to add filters – this is a zomei 46-49mm adapter ring (similar to this one) which screwed in to the original Holga plastic lens after using a dremel to sand down the holga lens until it fitted.
3.5mm plug for external camera trigger – this is a stereo headphone socket with 2 wires attached. Am using a mono 3.5mm cable to use as a cable release driver as I think it’s some kind of standard.
led indicator (in the viewfinder – which glows red to indicate a picture is being taken )
Optoisolator flash circuit – this is an LED attached to an image sensor – the model I’m using is rated to control very high voltages.
A 3 position rotary switch – to select between video, still photos and program mode. This is a 12 way switch so i’m only using a few of the contacts. I used a big chunky switch I found on ebay which makes a satisfying click when you turn it – it did fit after a dremel was used to cut a larger hole. I’ve used a tap washer to fill the gap between the switch and the camera case.
I’m currently powering this using a (rather big) Anker USB battery – will likely use something smaller in due course but the Anker battery seems to last forever and powers the Pi with the Wifi adapter with no problems at all.
The next step is to build the hardware to connect the various inputs and outputs to the Raspberry Pi. I’ve been experimenting with these using breadboard and hope to solder it all neatly together – with details – for my next project post. Essentially I need to wire 3 switches (shutter, 2 rotary switch positions) and 2 LEDs (indicator, optoisolator) to the GPIO.
Then finally there’s the matter of some software to pull it all together. At the moment I’ve been testing using the rather useful BerryCam iOS app – although it seems ironic to be using a device with it’s own much better built in camera to control the camera of another computer remotely, it’s a useful app to test things with. If you use the instructions in the first bit of my post about using the Pi as an Adblock server you can also set the IP address to be the same each time.