OK here goes my first attempt at writing down how I did it (or anything Pi)!
First update your Pi
Code: Select all
sudo apt-get update
sudo apt-get dist-upgrade
sudo rpi-update
sudo apt-get clean
Then install Python bits (not sure you really need this but I have it for relay switching)
Code: Select all
sudo apt-get install python-dev
sudo apt-get install python-rpi.gpio
Then you need the DHT22 bits from Adafruit which is "Adafruit_Python_DHT-master"
Code: Select all
https://github.com/adafruit/Adafruit_Python_DHT/archive/master.zip
Unzip it on your Pi and then install it with
Once installed you should be able to test it with the examples, just follow the gude in one of the files. I used simpletest.py in the examples folder and editied the GPIO to the one I used.
If you do not get a result here you are doing something wrong. If it works then you can get it to display on a web page.
Next steps to get output onto say index.php in /var/www/ which I assume you already have?! If not you need to do that too.
From now on follow the instructions at the start of this thread from
rpdom
You need to be very careful editing sudoers or sudoers.d or you can damage your version of Raspbain! Try it without first just make sure your python script has execute permissions set.
You need to be very careful editing sudoers or sudoers.d or you can damage your version of Raspbain! Try it without first just make sure your python script has exicute permissions set.
Below is another version of the python script I used that displayed well on a web page even if the code is probably poorly set out!
Code: Select all
[#!/usr/bin/python
# Copyright (c) 2014 Adafruit Industries
# Author: Tony DiCola
# edit
print 'Getting the temperature for you, please wait...'
import Adafruit_DHT
sensor = Adafruit_DHT.DHT22
pin = 25
humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
if humidity is not None and temperature is not None:
print 'T {0:0.1f}*C H {1:0.1f}%'.format(temperature, humidity)
else:
print 'Failed to get a reading. Please try again!'
if temperature >= 22:
words = 'Wow its hot, a blistering'
elif temperature >= 18:
words = 'Nice and warm out there at'
elif temperature >= 15:
words = 'Its OK out there, about'
elif temperature >= 9:
words = 'Its over 10 so not to bad at'
elif temperature >= 5:
words = 'Its cold, quite cold, but not that bad! Its only'
elif temperature >= 2:
words = 'Its very cold, so very cold, but not quite freezing, it just feels like it at'
else:
words = 'Really is freezing out there right now!!! Its'
print words,"{:2.2f}".format(temperature),'*C'
Thats it.
Oh and if you or anyone else knows how to get the degree symbol to work and show in python and a web page that would be very cool! Thats the ° Degree Symbol