Pages

Raspberry Pi Weather Station

A little diversion from props today. This is a project I did in some spare time with a Raspberry Pi micro pc that I had laying around. The display is a Pi shield with an old Nokia phone display. I made a small python script that grabs the weather off of an internet service and outputs the data into a file. A C script then reads in the file and sends the character data to a display library.

Link to pi shield on Amazon





weather.py

import urllib2
import json
import time

while(True):
f = urllib2.urlopen('http://api.wunderground.com/api/Your code here/geolookup/hourly/conditions/forecast/q/Your State/Your City.json')
json_string = f.read()
parsed_json = json.loads(json_string)
location = parsed_json['location']['city']
temp_f = parsed_json['current_observation']['temp_f']
ofile = open('weather.txt', 'w')
ofile.write("Current: %s\n" % (temp_f))

forecast = parsed_json['forecast']['simpleforecast']['forecastday']
today = forecast[0]
ofile.write("Tdy: h " + today['high']['fahrenheit'] + " l " + \
today['low']['fahrenheit'] + "\n")
ofile.write(today['conditions'] + "\n")
tomorrow = forecast[1]
ofile.write("Tom: h " + tomorrow['high']['fahrenheit'] + " l " + \
tomorrow['low']['fahrenheit'] + "\n")
ofile.write(tomorrow['conditions'] + "\n")

#print parsed_json['hourly_forecast'][0]['condition']
f.close()
ofile.close()

# Sleep for 10 minutes
time.sleep(600)


Modifications to cpushow pcd8544_rpi.c

#include
#include
#include
#include
#include
#include
#include "PCD8544.h"

// pin setup
int _din = 1;
int _sclk = 0;
int _dc = 2;
int _rst = 4;
int _cs = 3;

// lcd contrast
//may be need modify to fit your screen! normal: 30- 90 ,default is:45 !!!maybe modify this value!
int contrast = 60;

int main (void)
{
// print infos
printf("Raspberry Pi PCD8544 sysinfo display\n");
printf("========================================\n");

// check wiringPi setup
if (wiringPiSetup() == -1)
{
printf("wiringPi-Error\n");
exit(1);
}

// init and clear lcd
LCDInit(_sclk, _din, _dc, _cs, _rst, contrast);
LCDclear();

for (;;)
{
LCDclear();
FILE *fp;
char buf[16];
int y = 0;
fp = fopen("/home/pi/weather/weather.txt", "r");
while ( fgets(buf, sizeof buf, fp) != NULL ) {
LCDdrawstring(0, y, buf);
y += 8;
}
// build screen
//LCDdrawstring(0, 0, "Raspberry Pi:");
//LCDdrawline(0, 10, 83, 10, BLACK);
//LCDdrawstring(0, 8, uptimeInfo);
LCDdisplay();

delay(300000);
}

return 0;
}