0.1.26 updated DHTlib to support the DHT12 and AM23XX series

This commit is contained in:
RobTillaart 2017-12-12 20:58:58 +01:00
parent 9cd38afd16
commit d782be9946
7 changed files with 98 additions and 6 deletions

View File

@ -1,11 +1,12 @@
//
// FILE: dht.cpp
// AUTHOR: Rob Tillaart
// VERSION: 0.1.25
// VERSION: 0.1.26
// PURPOSE: DHT Temperature & Humidity Sensor library for Arduino
// URL: http://arduino.cc/playground/Main/DHTLib
//
// HISTORY:
// 0.1.26 2017-12-12 explicit support for AM23XX series and DHT12
// 0.1.25 2017-09-20 FIX https://github.com/RobTillaart/Arduino/issues/80
// 0.1.24 2017-07-27 FIX https://github.com/RobTillaart/Arduino/issues/33 double -> float
// 0.1.23 2017-07-24 FIX https://github.com/RobTillaart/Arduino/issues/31
@ -71,6 +72,28 @@ int8_t dht::read11(uint8_t pin)
return result;
}
int8_t dht::read12(uint8_t pin)
{
// READ VALUES
int8_t result = _readSensor(pin, DHTLIB_DHT11_WAKEUP, DHTLIB_DHT11_LEADING_ZEROS);
// CONVERT AND STORE
humidity = bits[0] + bits[1] * 0.1;
temperature = (bits[2] & 0x7F) + bits[3] * 0.1;
if (bits[2] & 0x80) // negative temperature
{
temperature = -temperature;
}
// TEST CHECKSUM
uint8_t sum = bits[0] + bits[1] + bits[2] + bits[3];
if (bits[4] != sum)
{
return DHTLIB_ERROR_CHECKSUM;
}
return result;
}
int8_t dht::read(uint8_t pin)
{
// READ VALUES

View File

@ -1,7 +1,7 @@
//
// FILE: dht.h
// AUTHOR: Rob Tillaart
// VERSION: 0.1.25
// VERSION: 0.1.26
// PURPOSE: DHT Temperature & Humidity Sensor library for Arduino
// URL: http://arduino.cc/playground/Main/DHTLib
//
@ -19,7 +19,7 @@
#include <Arduino.h>
#endif
#define DHT_LIB_VERSION "0.1.25"
#define DHT_LIB_VERSION "0.1.26"
#define DHTLIB_OK 0
#define DHTLIB_ERROR_CHECKSUM -1
@ -58,11 +58,17 @@ public:
// DHTLIB_ERROR_ACK_H
int8_t read11(uint8_t pin);
int8_t read(uint8_t pin);
int8_t read12(uint8_t pin);
inline int8_t read21(uint8_t pin) { return read(pin); };
inline int8_t read22(uint8_t pin) { return read(pin); };
inline int8_t read33(uint8_t pin) { return read(pin); };
inline int8_t read44(uint8_t pin) { return read(pin); };
inline int8_t read2301(uint8_t pin) { return read(pin); };
inline int8_t read2302(uint8_t pin) { return read(pin); };
inline int8_t read2303(uint8_t pin) { return read(pin); };
inline int8_t read2320(uint8_t pin) { return read(pin); };
inline int8_t read2322(uint8_t pin) { return read(pin); };
float humidity;
float temperature;

View File

@ -0,0 +1,56 @@
//
// FILE: dht12_test.ino
// AUTHOR: Rob Tillaart
// VERSION: 0.1.0
// PURPOSE: DHT library test sketch for DHT12 && Arduino
// URL:
//
// Released to the public domain
//
#include <dht.h>
dht DHT;
#define DHT12_PIN 5
void setup()
{
Serial.begin(115200);
Serial.println("DHT TEST PROGRAM ");
Serial.print("LIBRARY VERSION: ");
Serial.println(DHT_LIB_VERSION);
Serial.println();
Serial.println("Type,\tstatus,\tHumidity (%),\tTemperature (C)");
}
void loop()
{
// READ DATA
Serial.print("DHT12, \t");
int chk = DHT.read12(DHT12_PIN);
switch (chk)
{
case DHTLIB_OK:
Serial.print("OK,\t");
break;
case DHTLIB_ERROR_CHECKSUM:
Serial.print("Checksum error,\t");
break;
case DHTLIB_ERROR_TIMEOUT:
Serial.print("Time out error,\t");
break;
default:
Serial.print("Unknown error,\t");
break;
}
// DISPLAY DATA
Serial.print(DHT.humidity, 1);
Serial.print(",\t");
Serial.println(DHT.temperature, 1);
delay(2000);
}
//
// END OF FILE
//

View File

@ -14,10 +14,16 @@ DHT KEYWORD1
read KEYWORD2
read11 KEYWORD2
read12 KEYWORD2
read21 KEYWORD2
read22 KEYWORD2
read33 KEYWORD2
read44 KEYWORD2
read2301 KEYWORD2
read2302 KEYWORD2
read2303 KEYWORD2
read2320 KEYWORD2
read2322 KEYWORD2
humidity KEYWORD2
temperature KEYWORD2

View File

@ -1,6 +1,6 @@
{
"name": "DHTlib",
"keywords": "DHT11 DHT22 DHT33 DHT44 AM2301 AM2302 AM2303",
"keywords": "DHT11 DHT22 DHT33 DHT44 AM2301 AM2302 AM2303 AM2320 AM2322",
"description": "Optimized Library for DHT Temperature & Humidity Sensor on AVR only.",
"repository":
{

View File

@ -1,9 +1,9 @@
name=DHTlib
version=0.1.25
version=0.1.26
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Optimized Library for DHT Temperature & Humidity Sensor on AVR only.
paragraph=
category=Sensors
url=https://github.com/RobTillaart/Arduino/tree/master/libraries
architectures=avr
architectures=atmelavr

View File

@ -44,3 +44,4 @@ TODO pin description
* version 0.1.23 FIX https://github.com/RobTillaart/Arduino/issues/31
* version 0.1.24 FIX https://github.com/RobTillaart/Arduino/issues/33
* version 0.1.25 FIX https://github.com/RobTillaart/Arduino/issues/80
* version 0.1.26 Explicit support for AM23XX series and DHT12