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…

This entry was posted in Arduino, computers, hardware, MacOS X and tagged , , . Bookmark the permalink.

Leave a Reply