Tag Archives: graph

Temperature and humidity graph with raspberry pi

Top posted update:
Now it looks like this
pre-requisites:

  • 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:]
  temp.append(float(line[0]))
  hum.append(float(line[1]))

print(temp)
print(hum)

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

And the graphic looks like:
this

Sources: Adafruit DHT22 tutorial