Tag Archives: pygal

Temperature and humidity graph with raspberry pi

Top posted update:
Now it looks like this

  • a pinch of pygal
  • 1 raspberry pi (I used model B)
  • breadboard + accessories
  • DHT22 (or equivalent)

I just followed Adafruit’s tutorial for the wiring and the software
Then I did a slight modification to the script provided by Adafruit to write the data to a log file (temp-hum.log) instead of google drive spreadsheet.

Actual work
Updated code on Github
To generate the log file that will be parsed by pygal on github
Adafruit’s code for the sensor forked on github

A short python script to generate the graphic using Pygal:

#!/usr/bin/env python

import pygal

temp = []
hum  = []

logdata = open('temp-hum.log','r')
for line in logdata.readlines():
  line = line.split()[1:]


line_chart = pygal.Line(width=1200)
line_chart.title = 'Temperature Humidity'
line_chart.add('Temperature *C', temp)
line_chart.add('Humidity %', hum) 
breadboard and flat cable
breadboard and flat cable
DHT22 and cables
DHT22 and cables
r-pi and all
r-pi and all
DHT22 sensor
DHT22 sensor
r-pi with sensor
r-pi with sensor

And the graphic looks like:

Sources: Adafruit DHT22 tutorial

raspberry pi GPIO project

The idea is to plot temperature, light an humidity inside my house.

2013-02-24 00.51.50

source of inspiration

installing pygal on debian

apt-get install python-pip
apt-get install libxml2-dev libxslt1-dev gcc
apt-get install python2.7-dev
pip install pygal

As suggested by one of our readers, if you are using python3, you should

apt-get install python3-lxml

and so on.