RPi::PIGPIO::Device::DHT22 - Read temperature and humidity from a DHT22 sensor
Uses the pigpiod to read temperature and humidity from a local or remote DHT22 sensor
use RPi::PIGPIO; use RPi::PIGPIO::Device::DHT22; my $pi = RPi::PIGPIO->connect('192.168.1.10'); my $dht22 = RPi::PIGPIO::Device::DHT22->new($pi,4); $dht22->trigger(); #trigger a read print "Temperature : ".$dht22->temperature."\n"; print "Humidity : ".$dht22->humidity."\n";
Create a new object
Usage:
my $dht22 = RPi::PIGPIO::Device::DHT22->new($pi,$gpio);
Arguments:
$pi - an instance of RPi::PIGPIO
$gpio - GPIO number to which the sensor is connected
Return the last read temperature
Return the last read humidity
When was the last read done (unix timestamp)
Trigger a new read from the sensor.
Note: The read is not imediate, it's done asyncronyous. After calling trigger you shoud sleep for a second and than you should get the values received by calling temperature() and humidity() .
You should always chek the timestamp of the last read to make sure we were actually able to read the data after you called trigger()
DHT22 can freeze if you call trigger too often. Don't call it more than every 3 seconds and you should be fine
Callback method used to read and put together the data received from the sensor
Reset internal counters that help us put together data received from the sensor
To install RPi::PIGPIO, copy and paste the appropriate command in to your terminal.
cpanm
cpanm RPi::PIGPIO
CPAN shell
perl -MCPAN -e shell install RPi::PIGPIO
For more information on module installation, please visit the detailed CPAN module installation guide.