Displaying Yahoo London weather in Celsius on Arduino LCD

London weather! In Celsius!

I’ve cracked it! I have got my proto-fridge-gizmo to display the weather for London in centigrade.

The key is to tweak the YQL query to read:

select * from weather.forecast where
location="UKXX0085" and u="c" &format=json

In PHP you’ll need to escape those spaces, equals sign and quote marks, so you’ll end up with a line of PHP that reads something like:

$yql = "http://query.yahooapis.com/v1/public
/yql?q=select%20*%20from%20weather.forecast%20where
%20location%3D\"".$zipcode."\"%20and
%20u%3D\"c\"&format=json";

$zipcode is a variable that contains the location code, in our case “UKXX0085″ for London. I’m trying to add another variable so you can choose if you want temperatures in centigrade or Fahrenheit.

Next things to do:

  • get this working driven from a Raspberry Pi, rather than a laptop running OS X. This might involve installing the Apache web server and maybe PHP as well. 
  • Make the buttons do something.
  • Source some train info – this is going to be tricky as SE Train info is not publicly syndicated. I probably could show Dublin DART times more easily…
Posted in Arduino | Tagged , , | Leave a comment

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