From the AdaFruit web site https://learn.adafruit.com/dht-humidity-sensing-on-raspberry-pi-with-gdocs-logging/software-install-updated
pi@raspberrypi ~ $
cd
pi@raspberrypi ~ $ ls
Adafruit_Python_DHT Desktop python
python_games startvnc
pi@raspberrypi ~ $
cd Adafruit_Python_DHT/
pi@raspberrypi ~/Adafruit_Python_DHT $ ls
Adafruit_DHT
examples
README.md
source
Adafruit_DHT.egg-info ez_setup.py setup.py
build
ez_setup.pyc setuptools-4.0.1-py2.7.egg
dist
LICENSE setuptools-4.0.1.zip
pi@raspberrypi
~/Adafruit_Python_DHT $ cd examples/
pi@raspberrypi ~/Adafruit_Python_DHT/examples $ ls
AdafruitDHT.py
google_spreadsheet.py simpletest.py
pi@raspberrypi ~/Adafruit_Python_DHT/examples $ cat
simpletest.py
#!/usr/bin/python
# Copyright (c) 2014 Adafruit Industries
# Author: Tony DiCola
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
import Adafruit_DHT
# Sensor should be set to Adafruit_DHT.DHT11,
# Adafruit_DHT.DHT22, or Adafruit_DHT.AM2302.
sensor = Adafruit_DHT.DHT22 # 22 is what I have.
# Example using a Beaglebone Black with DHT sensor
# connected to pin P8_11.
pin = 'P8_11' # Comment this for Pi
# Example using a Raspberry Pi with DHT sensor
# connected to GPIO23.
#pin = 23 # Uncomment this for Pi and change the pin number to the pin you used when you wired it.
# Try to grab a sensor reading. Use the read_retry method which will retry up
# to 15 times to get a sensor reading (waiting 2 seconds between each retry).
humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
# Note that sometimes you won't get a reading and
# the results will be null (because Linux can't
# guarantee the timing of calls to read the sensor).
# If this happens try again!
if humidity is not None and temperature is not None:
print('Temp={0:0.1f}*C Humidity={1:0.1f}%'.format(temperature, humidity))
else:
print('Failed to get reading. Try again!')
pi@raspberrypi ~/Adafruit_Python_DHT/examples $
#! /usr/bin/python import RPi.GPIO as GPIO import time import signal, os import sys import Adafruit_DHT # Catch a signal and set the gpio pins to default on forced exit def handler(signum, frame): # GPIO.output(ledPin, 0) GPIO.cleanup() os._exit(0) # In this case ^C signal.signal(signal.SIGINT, handler) # Set up parameters cycleTime = 300 # minutes ledTimeSleep = 1 sensor = 22 # sensor type pin = 23 # sensor data pin ledPin = 12 # heartbeat led # Loop forever while 1: #get the humidity and temperature. # print "get humidity\n" humidity, temperature = Adafruit_DHT.read_retry(sensor, pin) #Send the info off to fibble execArg = "ssh -i /home/pi/.ssh/forhome deid@fibble.ca pi/testPi.py " + str(temperature) + "," + str(humidity) # Execute the ssh transfer os.system(execArg) # Flash the led every second # Reset the board and change to Broadcom numbering schema GPIO.cleanup() GPIO.setmode(GPIO.BCM) # set up pin to use GPIO.setup(ledPin, GPIO.OUT) #Loop switching on and off until time to get another temperature num = cycleTime / ledTimeSleep / 2 while num > 0: GPIO.output(ledPin, 1) time.sleep(ledTimeSleep) GPIO.output(ledPin, 0) time.sleep(ledTimeSleep) num = num - 1
# Set the gpio pins to default: GPIO.cleanup()
....