Since I’ve upgraded my hosting, one thing I’ve been wanting to do was to find a proper home for my Tweet Your MP script.
This is a php based script that looks up a UK parliamentary constituency given a postcode, and then returns the details of the MP using it’s own database. It’s been a handy resource for a few work projects, and since being published on GitHub as an open source project has been downloaded and used by a few other organisations as well.
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):
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.
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.
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.
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!
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:
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.
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.
A while ago as part of my Kickstarter habit I excitedly backed a space program. For the princely sum of $10 I get to control a satellite that’s about the size of a coffee machine for 100 seconds.
Sadly Fortunately in this instance the satellite’s functions are limited to sending tweets from space and taking a couple of photos with it’s on-board camera, although the music from Diamonds are Forever will be playing in my head as I imagine wielding control of a thing flying through space – even if it is just for a moment and lacks a laser death ray.
Still it’s rather nice to see a very ambitious Kickstarter funded project come to fruition – given that many more earthly bound campaigns fail after the funding hurdle has been reached.
Here’s the cube blasting off on board supply ship onboard a rocket (launched magnificently from a swamp):
And here it is docking with the International Space Station:
At some point in the future it will be thrown out of an airlock in a graceful launch sequence. Suggestions of things I’m going to make it tweet (along with the 3000 or so other backers) are most welcome – I get 10 historic messages to broadcast from space and the option of 2 photos from the on-board camera.
A while ago I backed a kickstarter for an aluminium Raspberry Pi case. Although I’ve already amassed a collection of Pi cases (everything from Lego to a hollowed out Holga medium format camera) this one caught my eye as being a rather beautiful piece of industrial design. They even went as far as quoting me on the kickstarter page.
Plus it was being made by a bloke and his Dad, which I like.
Well the case has arrived today, and I’m glad to say it’s not a disappointment. I opted for the bare metal version, and it feels really well made. The finish is more matt than it appears in the photos which is a plus point, and it comes with two lids – a perforated version and a version with slots if you want to make use of the camera and GPIO.
This is a very pretty case – perhaps most suited for a desktop Pi. The perforated design is a little bit reminiscent of the powermac G5 and the construction is spot on. I did need to bend the cover very slightly to get it to lock into place, but once it’s there it sits very securely.
The case is also stackable, which would make a very attractive Pi cluster.
Downsides? well it’s not cheap – Adafruit are selling it for $49.95 although it’s cheaper than the other Aluminium cases I’ve seen. If you’re quick you can still buy it direct for $34.99, which still makes it about as much as a Pi, but then it does look very nice on my desk next to the iMac. The video out and stereo jacks are recessed, so angled plugs might struggle but the HDMI socket is almost flush with the side of the case – and this is the output I would use 99% of the time anyway.
Overall? I stand by my statement that this is the best Aluminium case available for the Raspberry Pi – there are others out there but they start to push the ludicrously expensive barrier, and the UniPi case has the feel of much more expensive fruit branded products.
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 my post for this year’s Blog Action Day which is my geeky take on the subject of Human Rights.
Privacy is one of those human rights that we take for granted. It’s listed by the United Nations as article 12 of the Universal Declaration of Human Rights:
No one shall be subjected to arbitrary interference with his privacy, family, home or correspondence, nor to attacks upon his honour and reputation. Everyone has the right to the protection of the law against such interference or attacks.
along with the freedom of expression, listed as article 19:
Everyone has the right to freedom of opinion and expression; this right includes freedom to hold opinions without interference and to seek, receive and impart information and ideas through any media and regardless of frontiers.
Since the early days of the world wide web, privacy and the freedom of expression are central, as no single person or entity controlled the chaotic sprawl of servers that spewed out opinions, information and videos of cats.
This freedom cuts both ways – the web isn’t just freedom fighters and unsigned artists, it’s also terrorists, music pirates and pornographers, but the individual was the filter, not governments or corporations.
For years in the west, we’ve looked down at China’s great firewall that filters the internet, and the behaviour of giants like google who meekly provide pictures of pretty gardens rather than tanks when you search for ‘Tianamen Square’
Yet here in the UK, the government are proposing a catch all, opted-in internet filter with the noble intention of ridding the web of porn. Sadly good intentions can have unintended consequences – what makes the block list is vague at best, and could include things like ‘web forums’, ‘esoteric material’ (whatever that is) and ‘anti-blocking software’. Very little is said about who would decide what is acceptable and what isn’t, and how this would be policed. What would stop a future government blocking the websites of political parties, environmental campaigners or minority groups? how would the right to appeal a block work? would a company abuse it’s control over the block to silence criticism? could a less moderate government use this to stifle debate and eliminate opposition?
Governments do have a duty to protect their citizens – whether its from terrorism or internet nasties, but there is an issue of accountability, and trust. We need to be able to trust that government agencies are keeping an eye on the activity of people who are a genuine threat, and that this eye is accountable and itself scrutinised. It’s no longer enough to rely on the over used argument that people with nothing to hide have nothing to fear.
Recently Chris Huhne, who was in the cabinet for two years until 2012, said ministers were in “utter ignorance” of the two biggest covert operations, Prism and (the deep fried in batter sounding) Tempora. Worrying indeed; who are these covert operations reportable to? what would stop this power being abused?
And there is the case of undercover police officer Mark Kennedy who unlawfully spied on environmentalists – an example of an agent abusing his power in what should be a moderate country governed by a moderate government.
In any democracy, checks and balances are needed to ensure that the rapid rise in surveillance isn’t abused, or could be abused in the future by less moderate governments –
Tony Benn put it quite well:
“What power have you got? Where did you get it from? In whose interests do you exercise it? To whom are you accountable? And how can we get rid of you?” If you cannot get rid of the people who govern you, you do not live in a democratic system.”
When checks and balances fail, as always, the web itself has found ways around the issue of censorship and to secure privacy:
I recently acquired a FLIRC USB Dongle to use with my Raspberry Pi, and thought I’d post a few impressions of this handy media gadget.
FLIRC is a USB programmable adapter that can learn from any IR remote controller. You program the FLIRC using an app running on a Mac, PC or Intel based Ubuntu install, and once setup the FLIRC just appears as a standard USB keyboard.
The FLIRC itself is the size of a small USB stick – I’ve been using it with an old SKY box remote which has lots of handy buttons to use for various options. These remotes are a nice size, take AA batteries, and there are plenty available from amazon if you don’t have one to hand.
Each of the keys is set by running the FLIRC app – this can be set up as a simple apple TV remote:
for a more complicated XBMC remote, compatible with the Raspberry Pi’s RaspBMC:
Or for the full kitchen sink option, as a complete USB keyboard:
The latter is particularly useful as it offers keys like left and right command – which are missed off some keyboards, like the one on the Motorola Lapdock and using a small remote as a keypad is also quite a handy feature. Programmable keypads are usually much more expensive than the £22.99 that the FLIRC retails for.
All in all the FLIRC is a handy tool for the Raspberry Pi – it’s only downside is that it can’t be programmed directly from the Pi itself, as you need an intel based Mac or PC to program it. There is an API promised in the near future that should hopefully address some of these issues.
Recently I’ve been sent a PiFace board from the lovely people at Farnell UK – I’m currently working on a slightly silly but hopefully quite fun project with this, but in the meantime I wanted to post up a quick review of the board.
The Pi-Face comes fully assembled and features 4 inputs (complete with push switches for testing) and 8 outputs – 2 of which are relays, making it suitable to drive high current motors. All the outputs feature surface mount LED indicators so you can easily see what’s happening. As there’s a load of screw terminals attached to the board, absolutely no soldering is required to hook it up to LEDs or motors, or any type of power application. Although the big chunky relays are rated up to high voltages I think the practical limit is about 20v.
Fitting the board – in this case to a Raspberry Pi model A is a push fit job – there are cut outs for the video out and ethernet ports, along with a rubber foot that rests on the HDMI port. My only slight niggle was that in order for the board to fit completely flush against the Pi I had to trim 5 of the pins from the inputs for it to fit where it sits on the blue audio output port. This is a minor issue though as the board would work fine without this.
For installation – ignore the url printed on the board as this includes a mistake in the setup instructions. I used the following to install the software for the board:
sudo nano /etc/modprobe.d/raspi-blacklist.conf
and edit the file to add a # at the beginning of the line which reads blacklist spi-bcm2708, so it reads # blacklist spi-bcm2708.
to install the software – reboot your Pi and then you can use the rather neat graphical interface to test out the board –
to startup the graphical user interface, then open a terminal and type:
The emulator lets you see inputs from the buttons, and switch the outputs on and off:
The instructions and resources from the Start Pi website seem to be the most accurate – there’s a lot of work in progress, but hopefully the support for the Pi-Face will improve with time.
In conclusion it’s a cheap, nicely put together board with very handy relays and terminal inputs – I’m planning on putting mine to use with a lego project (watch this space) – although it lacks the flexibility of some of the bigger boards it has enough for most of the projects you’re likely to do – particularly if like me you interested in the whole idea of social media controlled gadgets. The documentation could be a lot better, and with the screw terminals rather than soldering requirement this board is aimed at the beginner, so hopefully that should improve over time.