8 Commits
1.2.1 ... 1.2.3

Author SHA1 Message Date
edcd0e06e6 Merge branch 'master' of https://github.com/adafruit/DHT-sensor-library 2015-10-12 21:30:18 -07:00
15020aa891 Fix #44 by conditionally excluding unused port and bitmask state on non-AVR platforms. 2015-10-12 21:30:01 -07:00
572347f137 Merge comment update from pull #43 2015-10-12 21:09:17 -07:00
e9daf69083 Merge README.md change from pull #43 2015-10-12 21:08:31 -07:00
56058fecc5 Bump library to 1.2.2 version. 2015-10-12 18:39:28 -07:00
d71288af17 Merge branch 'jmdana-master' 2015-10-12 18:38:58 -07:00
ce3190f65c Switch back to integer division in array indexing. 2015-10-12 18:37:54 -07:00
5bc0a5c796 Divisions turned into multiplications
As correctly stated by Mausy5043, the division is quite slow in most
microcontrollers, so I have replaced them with multiplications.
2015-10-06 23:42:19 +01:00
5 changed files with 21 additions and 12 deletions

16
DHT.cpp
View File

@ -11,8 +11,10 @@ written by Adafruit Industries
DHT::DHT(uint8_t pin, uint8_t type, uint8_t count) {
_pin = pin;
_type = type;
_bit = digitalPinToBitMask(pin);
_port = digitalPinToPort(pin);
#ifdef __AVR
_bit = digitalPinToBitMask(pin);
_port = digitalPinToPort(pin);
#endif
_maxcycles = microsecondsToClockCycles(1000); // 1 millisecond timeout for
// reading pulses from DHT sensor.
// Note that count is now ignored as the DHT reading algorithm adjusts itself
@ -46,7 +48,7 @@ float DHT::readTemperature(bool S, bool force) {
f = data[2] & 0x7F;
f *= 256;
f += data[3];
f /= 10;
f *= 0.1;
if (data[2] & 0x80) {
f *= -1;
}
@ -60,11 +62,11 @@ float DHT::readTemperature(bool S, bool force) {
}
float DHT::convertCtoF(float c) {
return c * 9 / 5 + 32;
return c * 1.8 + 32;
}
float DHT::convertFtoC(float f) {
return (f - 32) * 5 / 9;
return (f - 32) * 0.55555;
}
float DHT::readHumidity(bool force) {
@ -79,7 +81,7 @@ float DHT::readHumidity(bool force) {
f = data[0];
f *= 256;
f += data[1];
f /= 10;
f *= 0.1;
break;
}
}
@ -95,7 +97,7 @@ float DHT::computeHeatIndex(float temperature, float percentHumidity, bool isFah
if (!isFahrenheit)
temperature = convertCtoF(temperature);
hi = 0.5 * (temperature + 61.0 + ((temperature - 68.0) * 1.2) + (percentHumidity * 0.094));
hi = 0.5 * (temperature + 61.0 + ((temperature - 68.0) * 1.2) + (percentHumidity * 0.094));
if (hi > 79) {
hi = -42.379 +

7
DHT.h
View File

@ -48,7 +48,12 @@ class DHT {
private:
uint8_t data[5];
uint8_t _pin, _type, _bit, _port;
uint8_t _pin, _type;
#ifdef __AVR
// Use direct GPIO access on an 8-bit AVR so keep track of the port and bitmask
// for the digital pin connected to the DHT. Other platforms will use digitalRead.
uint8_t _bit, _port;
#endif
uint32_t _lastreadtime, _maxcycles;
bool _lastresult;

View File

@ -1,3 +1,5 @@
This is an Arduino library for the DHT series of low cost temperature/humidity sensors.
To download. click the DOWNLOADS button in the top right corner, rename the uncompressed folder DHT. Check that the DHT folder contains DHT.cpp and DHT.h. Place the DHT library folder your <arduinosketchfolder>/libraries/ folder. You may need to create the libraries subfolder if its your first library. Restart the IDE.
Tutorial: https://learn.adafruit.com/dht
To download. click the DOWNLOADS button in the top right corner, rename the uncompressed folder DHT. Check that the DHT folder contains DHT.cpp and DHT.h. Place the DHT library folder your <arduinosketchfolder>/libraries/ folder. You may need to create the libraries subfolder if its your first library. Restart the IDE.

View File

@ -3,11 +3,11 @@
#include "DHT.h"
#define DHTPIN 2 // what pin we're connected to
#define DHTPIN 2 // what digital pin we're connected to
// Uncomment whatever type you're using!
//#define DHTTYPE DHT11 // DHT 11
#define DHTTYPE DHT22 // DHT 22 (AM2302)
#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321
//#define DHTTYPE DHT21 // DHT 21 (AM2301)
// Connect pin 1 (on the left) of the sensor to +5V

View File

@ -1,5 +1,5 @@
name=DHT sensor library
version=1.2.1
version=1.2.3
author=Adafruit
maintainer=Adafruit <info@adafruit.com>
sentence=Arduino library for DHT11, DHT22, etc Temp & Humidity Sensors