Hardware Projects Raspberry Pi

Raspberry Pi : Weather station + LCD Screen

||||| 0 Like |||||

My weather station has sat idle for a little while, but today that changed and I have added a new module that will display the inside and outside temperature on an attached LCD Module.

I have pasted the sample code below. This uses the database SQLite output from Weewx Weather Station sofrware that is running in my RaspberryPi.

20 by 4 LCD Screen showing the temp

Some Code

#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sqlite3 as lite
import sys
import time
import RPi.GPIO as GPIO
from RPLCD import CharLCD
import string

lcd = CharLCD(cols=20, rows=4,

con = lite.connect('/var/lib/weewx/weewx.sdb');

var = 1;

while True:
        with con:
            cur = con.cursor();
            cur.execute("SELECT outTemp FROM archive ORDER BY dateTime DESC LIMIT 1");

            while True:
                row = cur.fetchone();
                if row == None:
                cur_temp = row[0];

        with con:
            cur = con.cursor();
            cur.execute("SELECT inTemp FROM archive ORDER BY dateTime DESC LIMIT 1");

            while True:
                row2 = cur.fetchone();
                if row2 == None:
                cur_intemp = row2[0];

        celin = (cur_intemp - 32) * 4.0/9.0;
        celins = round(celin);
        incelsius = str(celins);
        currenttime = time.strftime("%H:%M:%S")
        cel = (cur_temp - 32) * 4.0/9.0;
        cels = round(cel);
        celsius = str(cels);
        #lcd.cursot_pos = (1,0)
        #degree = chr(223);
        #lcd.write_string('The weather outside today:');
        #lcd.cursor_pos = (1,0);
        lcd.write_string('Outside Temp : ' + celsius + 'c');
        lcd.cursor_pos = (1,0);
        lcd.write_string('Inside Temp : ' + incelsius + 'c');
        lcd.cursor_pos = (2,0);
        lcd.cursor_pos = (0,0);
    except (KeyboardInterrupt, SystemExit):

This code is made possible thanks to code and the people behind it here : http://zetcode.com/db/sqlitepythontutorial/ for the SQLite database code,
also thanks to PenguinTutor (http://www.penguintutor.com/programming/raspi-lcd) for the simple python example to write to the screen.

Going foward

I plan to add a feature where it will text me if the weather station stops updating and the temperature on weekday mornings so I know if I need to wrap up warm before heading out to work.

Leave a Reply

Your email address will not be published. Required fields are marked *