Browse Source

Added support for DHT12 sensor (thanks to Altan Altay)

ech1560
Xose Pérez 6 years ago
parent
commit
d2a4330511
1 changed files with 10 additions and 2 deletions
  1. +10
    -2
      code/espurna/sensors/DHTSensor.h

+ 10
- 2
code/espurna/sensors/DHTSensor.h View File

@ -15,6 +15,7 @@
#define DHT_MIN_INTERVAL 2000
#define DHT_CHIP_DHT11 11
#define DHT_CHIP_DHT12 12
#define DHT_CHIP_DHT22 22
#define DHT_CHIP_DHT21 21
#define DHT_CHIP_AM2301 21
@ -145,7 +146,7 @@ class DHTSensor : public BaseSensor {
pinMode(_gpio, OUTPUT);
noInterrupts();
digitalWrite(_gpio, LOW);
if (_type == DHT_CHIP_DHT11) {
if ((_type == DHT_CHIP_DHT11) || (_type == DHT_CHIP_DHT12)) {
nice_delay(20);
} else {
delayMicroseconds(500);
@ -201,6 +202,9 @@ class DHTSensor : public BaseSensor {
// Get humidity from Data[0] and Data[1]
if (_type == DHT_CHIP_DHT11) {
_humidity = dhtData[0];
} else if (_type == DHT_CHIP_DHT12) {
_humidity = dhtData[0];
_humidity += dhtData[1] * 0.1;
} else {
_humidity = dhtData[0] * 256 + dhtData[1];
_humidity /= 10;
@ -209,6 +213,10 @@ class DHTSensor : public BaseSensor {
// Get temp from Data[2] and Data[3]
if (_type == DHT_CHIP_DHT11) {
_temperature = dhtData[2];
} else if (_type == DHT_CHIP_DHT12) {
_temperature = (dhtData[2] & 0x7F);
_temperature += dhtData[3] * 0.1;
if (dhtData[2] & 0x80) _temperature *= -1;
} else {
_temperature = (dhtData[2] & 0x7F) * 256 + dhtData[3];
_temperature /= 10;
@ -238,7 +246,7 @@ class DHTSensor : public BaseSensor {
unsigned char _errors = 0;
double _temperature = 0;
unsigned int _humidity = 0;
double _humidity = 0;
};


Loading…
Cancel
Save