mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-10-03 18:09:02 -04:00
0.1.35 DHTlib
This commit is contained in:
parent
a790900a79
commit
42c06fdaf5
@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2011-2021 Rob Tillaart
|
||||
Copyright (c) 2011-2022 Rob Tillaart
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -1,56 +1,80 @@
|
||||
//
|
||||
// FILE: dht.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.34
|
||||
// VERSION: 0.1.35
|
||||
// PURPOSE: DHT Temperature & Humidity Sensor library for Arduino, AVR optimized
|
||||
// URL: https://github.com/RobTillaart/DHTlib
|
||||
// http://arduino.cc/playground/Main/DHTLib
|
||||
//
|
||||
// HISTORY:
|
||||
// 0.1.34 2021-11-13 fix negative temperature DHT22 again (code from DHTNew)
|
||||
// 0.1.33 2021-02-16 fix #6 T-GO signal in handshake. (needed for long wires)
|
||||
// 0.1.32 2021-02-01 fix negative temperature DHT22 again (code from DHTNew)
|
||||
// 0.1.31 2020-12-15 fix negative temperature DHT22 (code from DHTNew)
|
||||
// 0.1.30 2020-06-30 own repo;
|
||||
// 0.1.29 2018-09-02 fix negative temperature DHT12 - issue #111
|
||||
// 0.1.28 2018-04-03 refactor
|
||||
// 0.1.27 2018-03-26 added _disableIRQ flag
|
||||
// 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
|
||||
// 0.1.22 undo delayMicroseconds() for wakeups larger than 8
|
||||
// 0.1.21 replace delay with delayMicroseconds() + small fix
|
||||
// 0.1.20 Reduce footprint by using uint8_t as error codes. (thanks to chaveiro)
|
||||
// 0.1.19 masking error for DHT11 - FIXED (thanks Richard for noticing)
|
||||
// 0.1.18 version 1.16/17 broke the DHT11 - FIXED
|
||||
// 0.1.17 replaced micros() with adaptive loopcount
|
||||
// removed DHTLIB_INVALID_VALUE
|
||||
// added DHTLIB_ERROR_CONNECT
|
||||
// added DHTLIB_ERROR_ACK_L DHTLIB_ERROR_ACK_H
|
||||
// 0.1.16 masking unused bits (less errors); refactored bits[]
|
||||
// 0.1.15 reduced # micros calls 2->1 in inner loop.
|
||||
// 0.1.14 replace digital read with faster (~3x) code => more robust low MHz machines.
|
||||
//
|
||||
// 0.1.13 fix negative temperature
|
||||
// 0.1.12 support DHT33 and DHT44 initial version
|
||||
// 0.1.11 renamed DHTLIB_TIMEOUT
|
||||
// 0.1.10 optimized faster WAKEUP + TIMEOUT
|
||||
// 0.1.09 optimize size: timeout check + use of mask
|
||||
// 0.1.08 added formula for timeout based upon clockspeed
|
||||
// 0.1.07 added support for DHT21
|
||||
// 0.1.06 minimize footprint (2012-12-27)
|
||||
// 0.1.05 fixed negative temperature bug (thanks to Roseman)
|
||||
// 0.1.04 improved readability of code using DHTLIB_OK in code
|
||||
// 0.1.03 added error values for temp and humidity when read failed
|
||||
// 0.1.02 added error codes
|
||||
// 0.1.01 added support for Arduino 1.0, fixed typos (31/12/2011)
|
||||
// 0.1.00 by Rob Tillaart (01/04/2011)
|
||||
//
|
||||
// HISTORY:
|
||||
// 0.1.35 2021-12-16 update library.json, license, #pragma once,
|
||||
// move private defines to .cpp file
|
||||
// 0.1.34 2021-11-13 fix negative temperature DHT22 again (code from DHTNew)
|
||||
// 0.1.33 2021-02-16 fix #6 T-GO signal in handshake. (needed for long wires)
|
||||
// 0.1.32 2021-02-01 fix negative temperature DHT22 again (code from DHTNew)
|
||||
// 0.1.31 2020-12-15 fix negative temperature DHT22 (code from DHTNew)
|
||||
// 0.1.30 2020-06-30 own repo;
|
||||
// 0.1.29 2018-09-02 fix negative temperature DHT12 - issue #111
|
||||
// 0.1.28 2018-04-03 refactor
|
||||
// 0.1.27 2018-03-26 added _disableIRQ flag
|
||||
// 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
|
||||
// 0.1.22 undo delayMicroseconds() for wakeups larger than 8
|
||||
// 0.1.21 replace delay with delayMicroseconds() + small fix
|
||||
// 0.1.20 Reduce footprint by using uint8_t as error codes. (thanks to chaveiro)
|
||||
// 0.1.19 masking error for DHT11 - FIXED (thanks Richard for noticing)
|
||||
// 0.1.18 version 1.16/17 broke the DHT11 - FIXED
|
||||
// 0.1.17 replaced micros() with adaptive loopcount
|
||||
// removed DHTLIB_INVALID_VALUE
|
||||
// added DHTLIB_ERROR_CONNECT
|
||||
// added DHTLIB_ERROR_ACK_L DHTLIB_ERROR_ACK_H
|
||||
// 0.1.16 masking unused bits (less errors); refactored bits[]
|
||||
// 0.1.15 reduced # micros calls 2->1 in inner loop.
|
||||
// 0.1.14 replace digital read with faster (~3x) code => more robust low MHz machines.
|
||||
//
|
||||
// 0.1.13 fix negative temperature
|
||||
// 0.1.12 support DHT33 and DHT44 initial version
|
||||
// 0.1.11 renamed DHTLIB_TIMEOUT
|
||||
// 0.1.10 optimized faster WAKEUP + TIMEOUT
|
||||
// 0.1.09 optimize size: timeout check + use of mask
|
||||
// 0.1.08 added formula for timeout based upon clockspeed
|
||||
// 0.1.07 added support for DHT21
|
||||
// 0.1.06 minimize footprint (2012-12-27)
|
||||
// 0.1.05 fixed negative temperature bug (thanks to Roseman)
|
||||
// 0.1.04 improved readability of code using DHTLIB_OK in code
|
||||
// 0.1.03 added error values for temp and humidity when read failed
|
||||
// 0.1.02 added error codes
|
||||
// 0.1.01 added support for Arduino 1.0, fixed typos (31/12/2011)
|
||||
// 0.1.00 by Rob Tillaart (01/04/2011)
|
||||
//
|
||||
// inspired by DHT11 library
|
||||
|
||||
|
||||
#include "dht.h"
|
||||
|
||||
|
||||
#define DHTLIB_DHT11_WAKEUP 18
|
||||
#define DHTLIB_DHT_WAKEUP 1
|
||||
|
||||
#define DHTLIB_DHT11_LEADING_ZEROS 1
|
||||
#define DHTLIB_DHT_LEADING_ZEROS 6
|
||||
|
||||
|
||||
// max timeout is 100 microseconds.
|
||||
// For a 16 MHz processor 100 microseconds is 1600 clock cycles
|
||||
// loops using DHTLIB_TIMEOUT use at least 4 clock cycles
|
||||
// so 100 us takes max 400 loops
|
||||
// so by dividing F_CPU by 40000 we "fail" as fast as possible
|
||||
#ifndef F_CPU
|
||||
#define DHTLIB_TIMEOUT 1000 // should be approx. clock/40000
|
||||
#else
|
||||
#define DHTLIB_TIMEOUT (F_CPU/40000)
|
||||
#endif
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
//
|
||||
// PUBLIC
|
||||
@ -80,6 +104,7 @@ int8_t dht::read11(uint8_t pin)
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
int8_t dht::read12(uint8_t pin)
|
||||
{
|
||||
// READ VALUES
|
||||
@ -104,6 +129,7 @@ int8_t dht::read12(uint8_t pin)
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
int8_t dht::read(uint8_t pin)
|
||||
{
|
||||
// READ VALUES
|
||||
@ -164,11 +190,11 @@ int8_t dht::read(uint8_t pin)
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
//
|
||||
// PRIVATE
|
||||
//
|
||||
|
||||
int8_t dht::_readSensor(uint8_t pin, uint8_t wakeupDelay, uint8_t leadingZeroBits)
|
||||
{
|
||||
// INIT BUFFERVAR TO RECEIVE DATA
|
||||
@ -273,6 +299,7 @@ int8_t dht::_readSensor(uint8_t pin, uint8_t wakeupDelay, uint8_t leadingZeroBit
|
||||
// digitalWrite(pin, HIGH);
|
||||
return DHTLIB_OK;
|
||||
}
|
||||
//
|
||||
// END OF FILE
|
||||
//
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -1,17 +1,12 @@
|
||||
#pragma once
|
||||
//
|
||||
// FILE: dht.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.34
|
||||
// VERSION: 0.1.35
|
||||
// PURPOSE: DHT Temperature & Humidity Sensor library for Arduino. AVR optimized
|
||||
// URL: https://github.com/RobTillaart/DHTlib
|
||||
// http://arduino.cc/playground/Main/DHTLib
|
||||
//
|
||||
// HISTORY:
|
||||
// see dht.cpp file
|
||||
//
|
||||
|
||||
#ifndef dht_h
|
||||
#define dht_h
|
||||
|
||||
#if ARDUINO < 100
|
||||
#include <WProgram.h>
|
||||
@ -21,7 +16,7 @@
|
||||
#endif
|
||||
|
||||
|
||||
#define DHT_LIB_VERSION (F("0.1.34"))
|
||||
#define DHT_LIB_VERSION (F("0.1.35"))
|
||||
|
||||
#define DHTLIB_OK 0
|
||||
#define DHTLIB_ERROR_CHECKSUM -1
|
||||
@ -30,24 +25,6 @@
|
||||
#define DHTLIB_ERROR_ACK_L -4
|
||||
#define DHTLIB_ERROR_ACK_H -5
|
||||
|
||||
#define DHTLIB_DHT11_WAKEUP 18
|
||||
#define DHTLIB_DHT_WAKEUP 1
|
||||
|
||||
#define DHTLIB_DHT11_LEADING_ZEROS 1
|
||||
#define DHTLIB_DHT_LEADING_ZEROS 6
|
||||
|
||||
|
||||
// max timeout is 100 usec.
|
||||
// For a 16 Mhz proc 100 usec is 1600 clock cycles
|
||||
// loops using DHTLIB_TIMEOUT use at least 4 clock cycli
|
||||
// so 100 us takes max 400 loops
|
||||
// so by dividing F_CPU by 40000 we "fail" as fast as possible
|
||||
#ifndef F_CPU
|
||||
#define DHTLIB_TIMEOUT 1000 // ahould be approx. clock/40000
|
||||
#else
|
||||
#define DHTLIB_TIMEOUT (F_CPU/40000)
|
||||
#endif
|
||||
|
||||
|
||||
class dht
|
||||
{
|
||||
@ -85,7 +62,7 @@ private:
|
||||
int8_t _readSensor(uint8_t pin, uint8_t wakeupDelay, uint8_t leadingZeroBits);
|
||||
bool _disableIRQ;
|
||||
};
|
||||
#endif
|
||||
//
|
||||
// END OF FILE
|
||||
//
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -1,17 +1,16 @@
|
||||
|
||||
//
|
||||
// FILE: dht11_test.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.01
|
||||
// PURPOSE: DHT library test sketch for DHT11 && Arduino
|
||||
// URL: https://github.com/RobTillaart/DHTlib
|
||||
//
|
||||
|
||||
|
||||
#include <dht.h>
|
||||
|
||||
dht DHT;
|
||||
|
||||
#define DHT11_PIN 5
|
||||
#define DHT11_PIN 5
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
@ -23,6 +22,7 @@ void setup()
|
||||
Serial.println("Type,\tstatus,\tHumidity (%),\tTemperature (C)");
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
// READ DATA
|
||||
@ -31,14 +31,14 @@ void loop()
|
||||
switch (chk)
|
||||
{
|
||||
case DHTLIB_OK:
|
||||
Serial.print("OK,\t");
|
||||
break;
|
||||
Serial.print("OK,\t");
|
||||
break;
|
||||
case DHTLIB_ERROR_CHECKSUM:
|
||||
Serial.print("Checksum error,\t");
|
||||
break;
|
||||
Serial.print("Checksum error,\t");
|
||||
break;
|
||||
case DHTLIB_ERROR_TIMEOUT:
|
||||
Serial.print("Time out error,\t");
|
||||
break;
|
||||
Serial.print("Time out error,\t");
|
||||
break;
|
||||
case DHTLIB_ERROR_CONNECT:
|
||||
Serial.print("Connect error,\t");
|
||||
break;
|
||||
@ -49,8 +49,8 @@ void loop()
|
||||
Serial.print("Ack High error,\t");
|
||||
break;
|
||||
default:
|
||||
Serial.print("Unknown error,\t");
|
||||
break;
|
||||
Serial.print("Unknown error,\t");
|
||||
break;
|
||||
}
|
||||
// DISPLAY DATA
|
||||
Serial.print(DHT.humidity, 1);
|
||||
@ -59,6 +59,7 @@ void loop()
|
||||
|
||||
delay(2000);
|
||||
}
|
||||
//
|
||||
// END OF FILE
|
||||
//
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -1,16 +1,16 @@
|
||||
//
|
||||
// FILE: dht12_test.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.0
|
||||
// PURPOSE: DHT library test sketch for DHT12 && Arduino
|
||||
// URL: https://github.com/RobTillaart/DHTlib
|
||||
//
|
||||
|
||||
|
||||
#include <dht.h>
|
||||
|
||||
dht DHT;
|
||||
|
||||
#define DHT12_PIN 5
|
||||
#define DHT12_PIN 5
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
@ -22,6 +22,7 @@ void setup()
|
||||
Serial.println("Type,\tstatus,\tHumidity (%),\tTemperature (C)");
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
// READ DATA
|
||||
@ -30,17 +31,17 @@ void loop()
|
||||
switch (chk)
|
||||
{
|
||||
case DHTLIB_OK:
|
||||
Serial.print("OK,\t");
|
||||
break;
|
||||
Serial.print("OK,\t");
|
||||
break;
|
||||
case DHTLIB_ERROR_CHECKSUM:
|
||||
Serial.print("Checksum error,\t");
|
||||
break;
|
||||
Serial.print("Checksum error,\t");
|
||||
break;
|
||||
case DHTLIB_ERROR_TIMEOUT:
|
||||
Serial.print("Time out error,\t");
|
||||
break;
|
||||
Serial.print("Time out error,\t");
|
||||
break;
|
||||
default:
|
||||
Serial.print("Unknown error,\t");
|
||||
break;
|
||||
Serial.print("Unknown error,\t");
|
||||
break;
|
||||
}
|
||||
// DISPLAY DATA
|
||||
Serial.print(DHT.humidity, 1);
|
||||
@ -49,6 +50,7 @@ void loop()
|
||||
|
||||
delay(2000);
|
||||
}
|
||||
//
|
||||
// END OF FILE
|
||||
//
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -1,19 +1,16 @@
|
||||
|
||||
//
|
||||
// FILE: dht21_test.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.02
|
||||
// PURPOSE: DHT library test sketch for DHT21 && Arduino
|
||||
// URL:
|
||||
//
|
||||
// Released to the public domain
|
||||
//
|
||||
|
||||
|
||||
#include <dht.h>
|
||||
|
||||
dht DHT;
|
||||
|
||||
#define DHT21_PIN 5
|
||||
#define DHT21_PIN 5
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
@ -25,6 +22,7 @@ void setup()
|
||||
Serial.println("Type,\tstatus,\tHumidity (%),\tTemperature (C)");
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
// READ DATA
|
||||
@ -61,6 +59,7 @@ void loop()
|
||||
|
||||
delay(2000);
|
||||
}
|
||||
//
|
||||
// END OF FILE
|
||||
//
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -1,17 +1,17 @@
|
||||
//
|
||||
// FILE: dht22_in_function.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.0
|
||||
// DATE: 2021-02-19
|
||||
// PURPOSE: show usage of DHT object in a function
|
||||
// based on issue #8
|
||||
// URL: https://github.com/RobTillaart/DHTlib
|
||||
|
||||
// based on issue #8
|
||||
|
||||
#include "dht.h"
|
||||
|
||||
#define DHTPIN 8
|
||||
|
||||
|
||||
void printDHT(const uint8_t pin) // uint8_t is an 8 bit unsigned integer
|
||||
{
|
||||
// This command questions a DHT22 on a specific 'pin'.
|
||||
@ -58,6 +58,7 @@ void printDHT(const uint8_t pin) // uint8_t is an 8 bit unsigned integer
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
@ -77,4 +78,6 @@ void loop()
|
||||
// add your other code here
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -1,22 +1,16 @@
|
||||
//
|
||||
// FILE: dht22_test.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.03
|
||||
// PURPOSE: DHT library test sketch for DHT22 && Arduino
|
||||
// URL: https://github.com/RobTillaart/DHTlib
|
||||
//
|
||||
// HISTORY:
|
||||
// 0.1.03 extended stats for all errors
|
||||
// 0.1.02 added counters for error-regression testing.
|
||||
// 0.1.01
|
||||
// 0.1.00 initial version
|
||||
//
|
||||
|
||||
|
||||
#include <dht.h>
|
||||
|
||||
dht DHT;
|
||||
|
||||
#define DHT22_PIN 5
|
||||
#define DHT22_PIN 5
|
||||
|
||||
|
||||
struct
|
||||
{
|
||||
@ -30,6 +24,7 @@ struct
|
||||
uint32_t unknown;
|
||||
} stat = { 0,0,0,0,0,0,0,0};
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
@ -40,6 +35,7 @@ void setup()
|
||||
Serial.println("Type,\tstatus,\tHumidity (%),\tTemperature (C)\tTime (us)");
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
// READ DATA
|
||||
@ -111,6 +107,8 @@ void loop()
|
||||
}
|
||||
delay(2000);
|
||||
}
|
||||
//
|
||||
// END OF FILE
|
||||
//
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
||||
|
@ -1,14 +1,9 @@
|
||||
//
|
||||
// FILE: dht22_test_noIRQ.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.0
|
||||
// PURPOSE: DHT library test sketch for DHT22 && Arduino
|
||||
// URL:
|
||||
// HISTORY:
|
||||
// 0.1.0 initial version
|
||||
//
|
||||
// Released to the public domain
|
||||
//
|
||||
// URL: https://github.com/RobTillaart/DHTlib
|
||||
|
||||
|
||||
#include <dht.h>
|
||||
|
||||
@ -16,6 +11,7 @@ dht DHT;
|
||||
|
||||
#define DHT22_PIN 5
|
||||
|
||||
|
||||
struct
|
||||
{
|
||||
uint32_t total;
|
||||
@ -30,6 +26,7 @@ struct
|
||||
uint32_t mintime;
|
||||
} stat = { 0,0,0,0,0,0,0,0, 0, 9999};
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
@ -37,16 +34,17 @@ void setup()
|
||||
Serial.print("LIBRARY VERSION: ");
|
||||
Serial.println(DHT_LIB_VERSION);
|
||||
Serial.println();
|
||||
|
||||
|
||||
Serial.print("IRQ:\t");
|
||||
Serial.println( DHT.getDisableIRQ() );
|
||||
DHT.setDisableIRQ(true);
|
||||
Serial.print("IRQ:\t");
|
||||
Serial.println( DHT.getDisableIRQ() );
|
||||
|
||||
|
||||
Serial.println("Type,\tstatus,\tHumidity (%),\tTemperature (C)\tTime (us)");
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
// READ DATA
|
||||
@ -125,6 +123,7 @@ void loop()
|
||||
}
|
||||
delay(500);
|
||||
}
|
||||
//
|
||||
// END OF FILE
|
||||
//
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -1,18 +1,16 @@
|
||||
//
|
||||
// FILE: dht33_test.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.01
|
||||
// PURPOSE: DHT library test sketch for DHT33 && Arduino
|
||||
// URL:
|
||||
//
|
||||
// Released to the public domain
|
||||
//
|
||||
// URL: https://github.com/RobTillaart/DHTlib
|
||||
|
||||
|
||||
#include <dht.h>
|
||||
|
||||
dht DHT;
|
||||
|
||||
#define DHT33_PIN 5
|
||||
#define DHT33_PIN 5
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
@ -24,6 +22,7 @@ void setup()
|
||||
Serial.println("Type,\tstatus,\tHumidity (%),\tTemperature (C)\tTime (us)");
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
// READ DATA
|
||||
@ -69,6 +68,7 @@ void loop()
|
||||
// ADJUST TO YOUR NEEDS
|
||||
delay(1000);
|
||||
}
|
||||
//
|
||||
// END OF FILE
|
||||
//
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -1,18 +1,16 @@
|
||||
//
|
||||
// FILE: dht44_test.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.01
|
||||
// PURPOSE: DHT library test sketch for DHT44 && Arduino
|
||||
// URL:
|
||||
//
|
||||
// Released to the public domain
|
||||
//
|
||||
// URL: https://github.com/RobTillaart/DHTlib
|
||||
|
||||
|
||||
#include <dht.h>
|
||||
|
||||
dht DHT;
|
||||
|
||||
#define DHT44_PIN 5
|
||||
#define DHT44_PIN 5
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
@ -24,6 +22,7 @@ void setup()
|
||||
Serial.println("Type,\tstatus,\tHumidity (%),\tTemperature (C)\tTime (us)");
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
// READ DATA
|
||||
@ -70,6 +69,7 @@ void loop()
|
||||
|
||||
delay(1000);
|
||||
}
|
||||
//
|
||||
// END OF FILE
|
||||
//
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -1,20 +1,19 @@
|
||||
//
|
||||
// FILE: dht_test.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.08
|
||||
// PURPOSE: DHT Temperature & Humidity Sensor library for Arduino
|
||||
// URL: https://github.com/RobTillaart/DHTlib
|
||||
// URL: http://arduino.cc/playground/Main/DHTLib
|
||||
//
|
||||
// Released to the public domain
|
||||
//
|
||||
|
||||
|
||||
#include <dht.h>
|
||||
|
||||
dht DHT;
|
||||
|
||||
#define DHT11_PIN 4
|
||||
#define DHT21_PIN 5
|
||||
#define DHT22_PIN 6
|
||||
#define DHT11_PIN 4
|
||||
#define DHT21_PIN 5
|
||||
#define DHT22_PIN 6
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
@ -26,6 +25,7 @@ void setup()
|
||||
Serial.println("Type,\tstatus,\tHumidity (%),\tTemperature (C)");
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
// READ DATA
|
||||
@ -34,14 +34,14 @@ void loop()
|
||||
switch (chk)
|
||||
{
|
||||
case DHTLIB_OK:
|
||||
Serial.print("OK,\t");
|
||||
break;
|
||||
Serial.print("OK,\t");
|
||||
break;
|
||||
case DHTLIB_ERROR_CHECKSUM:
|
||||
Serial.print("Checksum error,\t");
|
||||
break;
|
||||
Serial.print("Checksum error,\t");
|
||||
break;
|
||||
case DHTLIB_ERROR_TIMEOUT:
|
||||
Serial.print("Time out error,\t");
|
||||
break;
|
||||
Serial.print("Time out error,\t");
|
||||
break;
|
||||
case DHTLIB_ERROR_CONNECT:
|
||||
Serial.print("Connect error,\t");
|
||||
break;
|
||||
@ -52,8 +52,8 @@ void loop()
|
||||
Serial.print("Ack High error,\t");
|
||||
break;
|
||||
default:
|
||||
Serial.print("Unknown error,\t");
|
||||
break;
|
||||
Serial.print("Unknown error,\t");
|
||||
break;
|
||||
}
|
||||
// DISPLAY DATA
|
||||
Serial.print(DHT.humidity, 1);
|
||||
@ -62,21 +62,20 @@ void loop()
|
||||
|
||||
delay(1000);
|
||||
|
||||
|
||||
// READ DATA
|
||||
Serial.print("DHT21, \t");
|
||||
chk = DHT.read21(DHT21_PIN);
|
||||
switch (chk)
|
||||
{
|
||||
case DHTLIB_OK:
|
||||
Serial.print("OK,\t");
|
||||
break;
|
||||
Serial.print("OK,\t");
|
||||
break;
|
||||
case DHTLIB_ERROR_CHECKSUM:
|
||||
Serial.print("Checksum error,\t");
|
||||
break;
|
||||
Serial.print("Checksum error,\t");
|
||||
break;
|
||||
case DHTLIB_ERROR_TIMEOUT:
|
||||
Serial.print("Time out error,\t");
|
||||
break;
|
||||
Serial.print("Time out error,\t");
|
||||
break;
|
||||
case DHTLIB_ERROR_CONNECT:
|
||||
Serial.print("Connect error,\t");
|
||||
break;
|
||||
@ -87,8 +86,8 @@ void loop()
|
||||
Serial.print("Ack High error,\t");
|
||||
break;
|
||||
default:
|
||||
Serial.print("Unknown error,\t");
|
||||
break;
|
||||
Serial.print("Unknown error,\t");
|
||||
break;
|
||||
}
|
||||
// DISPLAY DATA
|
||||
Serial.print(DHT.humidity, 1);
|
||||
@ -103,14 +102,14 @@ void loop()
|
||||
switch (chk)
|
||||
{
|
||||
case DHTLIB_OK:
|
||||
Serial.print("OK,\t");
|
||||
break;
|
||||
Serial.print("OK,\t");
|
||||
break;
|
||||
case DHTLIB_ERROR_CHECKSUM:
|
||||
Serial.print("Checksum error,\t");
|
||||
break;
|
||||
Serial.print("Checksum error,\t");
|
||||
break;
|
||||
case DHTLIB_ERROR_TIMEOUT:
|
||||
Serial.print("Time out error,\t");
|
||||
break;
|
||||
Serial.print("Time out error,\t");
|
||||
break;
|
||||
case DHTLIB_ERROR_CONNECT:
|
||||
Serial.print("Connect error,\t");
|
||||
break;
|
||||
@ -121,8 +120,8 @@ void loop()
|
||||
Serial.print("Ack High error,\t");
|
||||
break;
|
||||
default:
|
||||
Serial.print("Unknown error,\t");
|
||||
break;
|
||||
Serial.print("Unknown error,\t");
|
||||
break;
|
||||
}
|
||||
// DISPLAY DATA
|
||||
Serial.print(DHT.humidity,1);
|
||||
@ -131,6 +130,6 @@ void loop()
|
||||
|
||||
delay(1000);
|
||||
}
|
||||
//
|
||||
// END OF FILE
|
||||
//
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
@ -1,18 +1,24 @@
|
||||
//
|
||||
// FILE: dht_tuning.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.00
|
||||
// PURPOSE: DHT test sketch for DHT22 && Arduino => find minimum time between reads
|
||||
// URL:
|
||||
//
|
||||
// Released to the public domain
|
||||
//
|
||||
// URL: https://github.com/RobTillaart/DHTlib
|
||||
|
||||
|
||||
#include <dht.h>
|
||||
|
||||
dht DHT;
|
||||
|
||||
#define DHT22_PIN 2
|
||||
#define DHT22_PIN 2
|
||||
|
||||
|
||||
int del = 500;
|
||||
uint32_t startRead = 0;
|
||||
uint32_t stopRead = 0;
|
||||
uint32_t startCycle = 0;
|
||||
uint32_t stopCycle = 0;
|
||||
uint32_t tempCycle = 0;
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
@ -24,12 +30,6 @@ void setup()
|
||||
Serial.println("Type,\tstatus,\t\tHumidity (%),\tTemperatur (C),\tT_Read (us)\tT_Cycle (us)\tT_Delay (us)");
|
||||
}
|
||||
|
||||
int del = 500;
|
||||
uint32_t startRead = 0;
|
||||
uint32_t stopRead = 0;
|
||||
uint32_t startCycle = 0;
|
||||
uint32_t stopCycle = 0;
|
||||
uint32_t tempCycle = 0;
|
||||
|
||||
void loop()
|
||||
{
|
||||
@ -87,7 +87,7 @@ void loop()
|
||||
}
|
||||
while(1);
|
||||
}
|
||||
//
|
||||
// END OF FILE
|
||||
//
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -1,17 +1,11 @@
|
||||
#######################################
|
||||
# Syntax Coloring Map For DHT
|
||||
#######################################
|
||||
# Syntax Colouring Map For DHT
|
||||
|
||||
#######################################
|
||||
# Datatypes (KEYWORD1)
|
||||
#######################################
|
||||
|
||||
# Data types (KEYWORD1)
|
||||
DHT KEYWORD1
|
||||
|
||||
#######################################
|
||||
# Methods and Functions (KEYWORD2)
|
||||
#######################################
|
||||
|
||||
# Methods and Functions (KEYWORD2)
|
||||
read KEYWORD2
|
||||
read11 KEYWORD2
|
||||
read12 KEYWORD2
|
||||
@ -19,20 +13,27 @@ read21 KEYWORD2
|
||||
read22 KEYWORD2
|
||||
read33 KEYWORD2
|
||||
read44 KEYWORD2
|
||||
|
||||
read2301 KEYWORD2
|
||||
read2302 KEYWORD2
|
||||
read2303 KEYWORD2
|
||||
read2320 KEYWORD2
|
||||
read2322 KEYWORD2
|
||||
|
||||
humidity KEYWORD2
|
||||
temperature KEYWORD2
|
||||
|
||||
#######################################
|
||||
|
||||
# Instances (KEYWORD2)
|
||||
#######################################
|
||||
|
||||
|
||||
#######################################
|
||||
# Constants (LITERAL1)
|
||||
#######################################
|
||||
DHT_LIB_VERSION LITERAL1
|
||||
|
||||
DHTLIB_OK LITERAL1
|
||||
DHTLIB_ERROR_CHECKSUM LITERAL1
|
||||
DHTLIB_ERROR_TIMEOUT LITERAL1
|
||||
DHTLIB_ERROR_CONNECT LITERAL1
|
||||
DHTLIB_ERROR_ACK_L LITERAL1
|
||||
DHTLIB_ERROR_ACK_H LITERAL1
|
||||
|
||||
|
@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "DHTlib",
|
||||
"keywords": "DHT11 DHT22 AM2301 AM2302 AM2303 AM2320 AM2322",
|
||||
"keywords": "DHT11,DHT22,AM2301,AM2302,AM2303,AM2320,AM2322",
|
||||
"description": "Optimized Library for DHT Temperature & Humidity Sensor on AVR only.",
|
||||
"authors":
|
||||
[
|
||||
@ -15,8 +15,9 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/DHTlib.git"
|
||||
},
|
||||
"version": "0.1.34",
|
||||
"version": "0.1.35",
|
||||
"license": "MIT",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "*"
|
||||
"platforms": "*",
|
||||
"headers": "dht.h"
|
||||
}
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=DHTlib
|
||||
version=0.1.34
|
||||
version=0.1.35
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=AVR Optimized Library for DHT Temperature & Humidity Sensor on AVR only.
|
||||
|
@ -57,12 +57,12 @@ See examples
|
||||
==> See DHTStable library for latest stable version for all platforms.
|
||||
|
||||
- version 0.1.13 is the last stable version for both AVR and ARM
|
||||
- version 0.1.14 and up are not compatible anymore with pre 1.0 Arduino.
|
||||
These have breaking changes wrt ARM based arduino's e.g DUE.
|
||||
- version 0.1.14 and up are not compatible any more with pre 1.0 Arduino.
|
||||
These have breaking changes wrt ARM based Arduino's e.g DUE.
|
||||
- version 0.1.15 is stable version for AVR only
|
||||
- version 0.1.16 and 0.1.17 have breaking changes for DHT11
|
||||
- version 0.1.18 works again for DHT11 (avr only)
|
||||
- version 0.1.19 fixed masking bug DHT11 (avr only)
|
||||
- version 0.1.18 works again for DHT11 (AVR only)
|
||||
- version 0.1.19 fixed masking bug DHT11 (AVR only)
|
||||
- version 0.1.20 Reduce footprint (34 bytes) by using int8_t as error codes. (thanks to chaveiro)
|
||||
- version 0.1.21 replace delay with delayMicroseconds() + small fix (thanks to codingforfun)
|
||||
- version 0.1.22 undo delayMicroseconds() for wakeups larger than 8
|
||||
@ -70,8 +70,24 @@ These have breaking changes wrt ARM based arduino's e.g DUE.
|
||||
- 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
|
||||
- version 0.1.27 added _disableIRQ flag
|
||||
- version 0.1.27 added \_disableIRQ flag
|
||||
- version 0.1.28 refactor
|
||||
- version 0.1.29 fix negative temperature DHT12 - issue #111
|
||||
- version 0.1.30 own repo version
|
||||
- version 0.1.31 fix negative temperature DHT22 (code from DHTNew)
|
||||
- version 0.1.32 fix negative temperature DHT22 again (code from DHTNew)
|
||||
- version 0.1.33 fix #6 T-GO signal in handshake. (needed for long wires)
|
||||
- version 0.1.34 fix negative temperature DHT22 again (code from DHTNew)
|
||||
- version 0.1.35 update license, library.json, #pragma once, minor edits
|
||||
|
||||
|
||||
## Future
|
||||
|
||||
- updates only on request basis (bugs)
|
||||
- improve documentation
|
||||
- improve unit tests
|
||||
- constants
|
||||
- move non public part of #defines to .cpp
|
||||
- separate history versions releasenotes file ?
|
||||
-
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user