This is London

I managed to get my FridgeGizmo prototype to display the weather in London! Ok, it’s in Fahrenheit, but it’s London weather! Lahhhhhvery!

Where I was going wrong was by not realising that of course the US zip codes were stored as numerical variables, whereas international Yahoo weather city codes contain letters. So I changed the zip code for Nashville, to UKXX0085 for London – with added quote marks.

// Weather
$zipcode = "UKXX0085";
$title = "London UK WX.";

I then added a couple of quote marks to the YQL query, either side of $zipcode, escaping them with backslash characters:

from%20weather.forecast%20where%20location%3D\"".$zipcode."\"&format=json
Posted in Arduino | Tagged , , , , , | Leave a comment

Fridge Gizmo step 2

Mostly cloud

As you may know, I have a dream of a gizmo on my fridge that tells me the weather, some tweets and what time my next train is due. I’m trying to build this using an Arduino, an LCD display shield and a Raspberry Pi.

I just got a step closer by following these instructions: http://www.midnightcheese.com/2011/10/displaying-twitter-and-weather-on-your-arduino-lcd-screen/

It’s very much a half-way house – it’s running connected to a laptop running OS X, not a Raspberry Pi. It is displaying top global Twitter trends and random public tweets, but the weather… it’s the weather in Nashville. In Fahrenheit. Ah yes, the weather… more on that later.

The instructions on Midnight Cheese site skipped some steps, and the link to download the code doesn’t work, so here’s what I had to do.

1. Tweaked the Arduino code.

I had to change the case of the include for the LCD library to read

#include <LiquidCrystal.h>

(note capital letters). I then altered the line to initialise the pins of my LCD – I took these from sample Arduino code that came with my LCD shield:

LiquidCrystal lcd(8, 9, 4, 5, 6, 7);

I then commented out the line to set the contrast of the display:

//  analogWrite(5, 100);    // Set LCD contrast level (0-255)

I did want to add a feature to dim the display, but this discussion has freaked me out a bit: http://arduino.cc/forum/index.php?topic=96747.0 – no idea yet if my shield has this fault, so I won’t mess around with the brightness for now.

2. Turned on the web server in OS X.

My netbook has OS X 10.6 (Snow Leopard) on it. To turn on the web server I went to System Preferences > Sharing and turned web sharing on. This switches on the built-in Apache web server. I also had to turn on PHP, as the script that is going to fetch the tweets and weather from the internet is written in PHP. I followed the instructions on this web site: http://georgebutler.com/blog/setting-up-local-web-server-on-os-x-snow-leopard-10-6/

3. Tweaking the PHP script

I had to modify the serial port to match my Arduino Uno – I did this by looking in my /dev/ folder with the Arduino plugged in, poking around and guessing a bit. My serial device line was this:

//Define the serial port to use
define('SERIALPORT','/dev/cu.usbmodem7d21');

I saved the PHP file in my web folder (~/Sites/) and called it tweet-weather.php. I then put the PHP serial class file in the same folder – I had to tweak the name of the file like this though (no ‘OSX’):

// Include the PHP Serial class.
include "php_serial.class.php";

4. Bash Street Kids.

To make the Bash startup file which will run everything, you need to save the text in a text editor in a file called something like tweet-weather.sh

#!/bin/bash

nohup sleep 36000 < /dev/cu.usbmodem7d21 &

php tweet-weather.php

You then need to make your bash script executable  – I used the instructions here: http://ss64.com/osx/syntax-shellscript.html

Having uploaded the Arduino code to the Arduino, plugged the shield in and connected it by USB to the laptop, I navigated to my ~/Sites/ folder in the OS X command line and typed

./tweet-weather.sh

After a little while weather (for Nashville) appeared on my LCD and random tweets and top trends started scrolling across. I have learned that, amazingly, a lot of tweets are not written in English (Spanish seems very popular), and my LCD screen doesn’t like non-Latin characters (with the possible exception of Japanese).

Getting the weather for London, however, is proving harder. This script uses a very particular YQL (Yahoo Query Language) request from Yahoo which only seems to take US Zip codes (I tried 90210 – apparently it’s warm and sunny). I’ve tried supplying it with 2 different city codes for London and neither of them work – so I may have to find another way of getting weather…

Posted in Arduino, computers, hardware, MacOS X | Tagged , , | Leave a comment

Sidebar of literary shame

There is, of course, no earthly reason why anyone would be interested in what I’ve just read, but I’ve been ignoring my personal reading record, my sidebar of literary shame, so I decided to tidy up the blog, dump this down and show that there’s more to me than tinkering with my Arduino and Raspberry Pi.

This is just a personal checklist of what I’ve read. Once in a seminar at university, Professor Hammond asked ‘who is Shakespeare addressing here?’ We all examined the ceiling, our fingernails. Eventually even I could stand the silence no longer. ‘Himself?’ I suggested. Prof Hammond laughed. ‘Well, yes, I suppose, in a way, all of us, ultimately are just… talking to ourselves…’

The Terrorists by Maj Sjöwall and Per Wahlöö. I was reading the Martin Beck books in strict order but saw this in a book sale. Classic Swedish crime fiction.
The Banned List by John Rentoul. 99p Kindle offer. Probably not worth much more, to be honest. I wish he’d done the whole thing as an alphabetical list with a brief discourse on each cliché.
Cell by Stephen King. A good read, but I wanted answers!
Where the Bodies are Buried by Chris Brookmyre. My second Brookmyre. A bit like Ian Rankin meets Kate Atkinson – in Glasgow. Enjoyed it very, very much.
The Tomorrow People in Three in Three by Roger Price and The Visitor by Roger Price & Julian R Gregory. I found 4 of the Tomorrow People books I had as a child at a book sale. I could remember The Visitor one almost word-for-word. I must have read and re-read it many times as a child.
Triangles by Andrea Newman. I joked on twitter half way through that one of these short stories about affairs would feature someone having an affair with their own husband. And it did!
When God Was a Rabbit by Sarah Winman. Reviewed here.
How to be a Woman by Caitlin Moran. It’s funny cos it’s true.
Gumble’s Yard by John Rowe Townsend.
Noah’s Castle by John Rowe Townsend. Thank god for the internet for finally allowing me to find this dystopian 70s childrens’ book which had a huge effect on me at the time. I could remember neither the title nor the author.
The Ask and the Answer by Patrick Ness. Grim, but brilliant kids’ book.
The Knife of Never Letting Go by Patrick Ness. Brilliant dystopian book for teens. The short prequel is a free Kindle download.
Seven Types of Ambiguity by Elliot Perlman. 607 pages, seven viewpoints of the same extraordinarily inter-twined events. Clever, full of good ideas but I didn’t warm to the main character and didn’t love it anywhere near as much as A Fraction of the Whole by Steve Toltz.
The Fear by Charlie Higson.
Started Early, Took My Dog by Kate Atkinson. I HATED this book – which was a surprise as I really liked the previous 3 Jackson Brodies, esp the previous one. Why? Too many characters I didn’t care about. Not enough Jackson Brodie. And I know it’s grim up North – but just too, too grim. Forced myself to finish it, but only because I bloody paid for it.
When Will There Be Good News? by Kate Atkinson. MUCH better than the TV adaptation, which I found very confusing. Very readable – some of the turns choices made by the main characters have had me going ‘whaaat’? but it’s all the more believable and enjoyable for them.
One Good Turn by Kate Atkinson. Good, but didn’t enjoy it as much as Case Histories.
Case Histories by Kate Atkinson. Bliss.
Jeff in Venice, Death in Varanasi by Geoff Dyer. Oh me. Oh my. I reviewed this here.
Solar by Ian McEwan. Good holiday read but not stunning literature.
One Day by David Nicholls. I am officially the last person-but-one in England to read this. Loved it, though. Bastard.
Moonraker by Ian Fleming. Ah, another improbably-named young woman to see you, Mr Bond. (Like I can talk).
Obstacles to Young Love by David Nobbs. This lad Nobbs will go far. Funny, touching, very occasionally annoying, but a damn fine novel.
The Terrible Privacy of Maxwell Sim by Jonathan Coe. Hated the ending. Sorry. Sure it’s been done elsewhere. My first, and probably last, Coe.
Hungry the Stars and Everything by Emma Jane Unsworth. Delicious! I reviewed this here.
The Crimson Petal and the White by Michel Faber. It’s Dickens with swear words. In a good way.
I Capture the Castle by Dodie Smith. From 1949. Perfect. It’s so good, I love it so much. Cannot believe I’ve never read this before.
Jar City by Arnaldur Indriðason – bit disappointed. Just a police procedural. Not that odd. No big DNA conspiracy.
The Good Soldier by Ford Madox Ford – I proof-read a neighbour’s uni essay on this and had to read it. Bleak it is, so bleak – especially for a man of my age and circumstance. Almost gave up but half way through I ‘got it’ and glad I finished it. But grim. Grim.
The Game by Jack London.
The Man Who Went Up In Smoke by Maj Sjöwall and Per Wahlöö. 2nd Martin Beck novel from the original masters of the modern (1960s) police procedural.
Devil May Care by Sebastian Faulks writing as Ian Fleming. I enjoyed this WAY more than Engleby. Really good, flavour of Bond captured very well indeed.
Dead Man’s Cove by Lauren St John. Great children’s book, set in St Ives, Cornwall. If the Laura Marlin Mysteries continue like this, I might have to write my own Caitlin Ros Mysteries. (Geddit?!)
Sweet Desserts by Lucy Ellman.
Live and Let Die by Ian Fleming.
Engleby by Sebastian Faulks. My first Faulks – he’s too damn popular with the ladies for my liking. I almost gave up on it on page 85. Luckily something happens on page 86. Blog post coming…
Street Kids by Chandrika Kaviraj. Excellent unpublished story for older children set in Pakistan and India during Partition.
The Sacred Art of Stealing by Christopher Brookmyre.
Casino Royale by Ian Fleming. My first Bond. It’s just as I would have hoped and expected. And me oh my does Vesper Lynd remind me of someone.
Anna Karenina by Leo Tolstoy. There’s a stunning novel in here, struggling to get out. Just spare me the state of Russian agriculture, Leo, I beg you…
Nemesis by Jo Nesbø – this is shaping up very nicely, up there with The Snowman and The Redeemer.

Posted in fiction, literature, recently read | Tagged , , | Leave a comment

Fridge gizmo

fridge gizmo takes shape
My dream of a gizmo stuck to the fridge to tell me my next train time, the weather and certain tweets got a step closer today. I ordered an Arduino shield with a 2 line LCD display and some buttons - and a tiny USB-powered wifi adaptor for the Rasperry Pi – the Edimax EW-7811UN Wireless 802.11b/g/n 150Mbps Nano USB Adaptor

I know there are cheaper (and larger) displays to be had, but I like the fact that this one is a shield that plugs straight into the Arduino, so no soldering required. And it has buttons! How cool would it be to press a button for weather, another one for tweets and another for train times?

My mad plan is to get the Raspberry Pi to do all the talking to the internet, and somehow transfer the text to the Arduino, perhaps using PHP like this: http://www.midnightcheese.com/2011/10/displaying-twitter-and-weather-on-your-arduino-lcd-screen/

As a half-way house, I’ll try and get something working on OS X first.

Posted in Arduino, computers, hardware, internet, Linux, MacOS X, Raspberry Pi | Tagged , , , | Leave a comment

Which is better: Arduino or Raspberry Pi? There’s only one way to find out…

…join them together!

Arduino connected to Rasperry Pi

But seriously, they are very different things for very different purposes, and it’s a bit sad that some hard-core Arduino fans hate the Raspberry Pi (though perhaps understandable). The Arduino is a relatively expensive (for its processing power) microcontroller, though it does have the backing of a huge open source community of software and hardware projects. I bought one while I was waiting for my Raspberry Pi to arrive, and to be honest we’ve learnt more about electronics and programming so far from the Arduino than we have from the RasPi.

The Raspberry Pi, however, is a ridiculously cheap actual computer with a graphics chip that can display HD video. Its potential is immense, but I can see a great future in joining the Arduino to the Raspberry Pi to get the best of both worlds. The Arduino is great for low-level stuff in the real world, with light bulbs, switches, sensors, motors etc, and the RasPi great at stuff like talking to the internet and storing larger amounts of data.

There is a hardware gizmo called the GertBoard which promises to make the GPIO pins on the Raspberry Pi more accessible to hacking and interfacing with electronics, but I’ve had a quick look at it, and it’s not for me. It’s £30, and comes as a bag of parts that require a great deal of soldering – and then one look at the manual had me heading for the hills. Just way too complex for me – and part of it seems to involve adding a microcontroller – practically piggy-backing an Arduino-type device on the Raspberry Pi. Well, I already have an Arduino I can plug in via USB, so why not just use that? I know directly addressing GPIO pins on the Raspberry Pi will be very useful, but at my level I’m quite happy turning lights on and off, ringing buzzers, maybe driving a 2-line LCD display – and USB should be fine for that.

And today I managed to get my Raspberry Pi talking to my Arduino – I could type text on the Pi’s keyboard, and the Arduino (connected via USB) would beep and flash the letters in Morse code using the Morse project we started a couple of days ago after visiting Porthcurno.

I worked out that an Arduino Uno presents itself to a Rasperry Pi (running Raspbian Wheezy 2012-08-16) as /dev/ttyACM0 but I could not get

echo 'sos' > /dev/ttyACM0

to do anything other than make the Arduino light blink. This is exactly the same problem I had in the OS X command line, so I wasn’t totally disheartened. I clearly had the right device name, but some kind of handshaking or protocol was awry. I remembered that I got round the problem in OS X using a command line ‘screen’ session, so I tried that – no luck on the Raspberry Pi, as ‘screen’ was not installed.

So, I connected my Raspberry Pi to the internet (another story in itself)* and at the command line typed

sudo apt-get install screen

Then typed on the RasPi command line:

screen /dev/ttyACM0 9600

The 9600 is the baud rate set in the Arduino Morse sketch I was using. Then any letter I typed into the console on the Pi was translated into Morse beeps and flashes on the Arduino, as I typed them. A very satisfying achievement. (You can exit a screen session by typing ‘ctrl-a d’ to disconnect.)

Arduino and Raspberry Pi – a perfect match for each other.

* getting the Raspberry Pi on the internet so I could install ‘screen’ was fun. TV upstairs, in constant use by kids. Internet router is downstairs in kitchen, where there’s no TV. Sounds like a job for SSH. To cut a long story short, I wasted hours trying to open a remote SSH session into the wrong IP address. It’s quite hard knowing what the IP address of a screenless Raspberry Pi is when you don’t have access to the broadband router’s admin page. In the end I used an OS X utility called IPScanner, but there are other tricks you can use. The most bizarre, but ingenious, one I found was installing something to blink the IP address on the Raspberry Pi’s onboard LEDs!

Once I’d got SSH working, I could leave the Raspberry Pi screenless, keyboardless and mouseless in the kitchen connected to the internet & the LAN via ethernet and to the Arduino via USB, and using an SSH session on my laptop upstairs send a morse code message to the kitchen asking for more tea. Yeah, a guy can dream… Well, I might possibly teach the kids some Morse code by getting one upstairs sending rude messages from the laptop to another in the kitchen with a Morse key chart and a pad of paper.

This is cleverer than it looks...

Next task – to install the Arduino IDE on the Raspberry Pi…

Posted in Arduino, computers, Debian, hardware, Linux, Raspberry Pi | Tagged , | Leave a comment