This module enables access to the AM2302 wired digital temperature and humidity sensor from a Raspberry Pi. It's been adapted from Adafruit's C code.
It may work with both the DHT11 and DHT22 sensors as well, though this is untested.
Get it with pip install am2302_rpi
. The BCM2835 C
Library is required and the
root user must be used to access the GPIO pins.
Both methods return floats, or None if the sensor can't be read. The sensor can only be read once every few seconds.
Reads the current temperature from a sensor attached to the specified pin.
Reads the current humidity from a sensor attached to the specified pin.
This module provides a class Sensor which periodically polls the sensor to keep track of the current temperature without waiting for it.
It has the following methods available.
Create a new sensor object instance with s = am2302_rpi.Sensor(4)
.
Get the last read temperature.
Get the time of the last successful read.
Turn the timer off by cancelling it's internal ticker. Make sure you call this before exiting.
Clean up the sensor object properly.