IP Configuration
This commit is contained in:
169
lib/DHT/dht.cpp
Normal file
169
lib/DHT/dht.cpp
Normal file
@@ -0,0 +1,169 @@
|
||||
//
|
||||
// FILE: dht.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.2.0
|
||||
// PURPOSE: DHT Temperature & Humidity Sensor library for Arduino
|
||||
// URL: https://github.com/RobTillaart/Arduino/tree/master/libraries/DHTstable
|
||||
//
|
||||
// HISTORY:
|
||||
// 0.2.1 2017-09-20 fix https://github.com/RobTillaart/Arduino/issues/80
|
||||
// 0.2.0 2017-07-24 fix https://github.com/RobTillaart/Arduino/issues/31 + 33
|
||||
// 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.0 by Rob Tillaart (01/04/2011)
|
||||
//
|
||||
// inspired by DHT11 library
|
||||
//
|
||||
// Released to the public domain
|
||||
//
|
||||
|
||||
#include "dht.h"
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
//
|
||||
// PUBLIC
|
||||
//
|
||||
|
||||
// return values:
|
||||
// DHTLIB_OK
|
||||
// DHTLIB_ERROR_CHECKSUM
|
||||
// DHTLIB_ERROR_TIMEOUT
|
||||
int dht::read11(uint8_t pin)
|
||||
{
|
||||
// READ VALUES
|
||||
int rv = _readSensor(pin, DHTLIB_DHT11_WAKEUP);
|
||||
if (rv != DHTLIB_OK)
|
||||
{
|
||||
humidity = DHTLIB_INVALID_VALUE; // invalid value, or is NaN prefered?
|
||||
temperature = DHTLIB_INVALID_VALUE; // invalid value
|
||||
return rv;
|
||||
}
|
||||
|
||||
// CONVERT AND STORE
|
||||
humidity = bits[0]; // bits[1] == 0;
|
||||
temperature = bits[2]; // bits[3] == 0;
|
||||
|
||||
// TEST CHECKSUM
|
||||
uint8_t sum = bits[0] + bits[1] + bits[2] + bits[3];
|
||||
if (bits[4] != sum)
|
||||
{
|
||||
return DHTLIB_ERROR_CHECKSUM;
|
||||
}
|
||||
return DHTLIB_OK;
|
||||
}
|
||||
|
||||
|
||||
// return values:
|
||||
// DHTLIB_OK
|
||||
// DHTLIB_ERROR_CHECKSUM
|
||||
// DHTLIB_ERROR_TIMEOUT
|
||||
int dht::read(uint8_t pin)
|
||||
{
|
||||
// READ VALUES
|
||||
int rv = _readSensor(pin, DHTLIB_DHT_WAKEUP);
|
||||
if (rv != DHTLIB_OK)
|
||||
{
|
||||
humidity = DHTLIB_INVALID_VALUE; // invalid value, or is NaN prefered?
|
||||
temperature = DHTLIB_INVALID_VALUE; // invalid value
|
||||
return rv; // propagate error value
|
||||
}
|
||||
|
||||
// CONVERT AND STORE
|
||||
humidity = word(bits[0], bits[1]) * 0.1;
|
||||
temperature = word(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 DHTLIB_OK;
|
||||
}
|
||||
|
||||
/////////////////////////////////////////////////////
|
||||
//
|
||||
// PRIVATE
|
||||
//
|
||||
|
||||
// return values:
|
||||
// DHTLIB_OK
|
||||
// DHTLIB_ERROR_TIMEOUT
|
||||
int dht::_readSensor(uint8_t pin, uint8_t wakeupDelay)
|
||||
{
|
||||
// INIT BUFFERVAR TO RECEIVE DATA
|
||||
uint8_t mask = 128;
|
||||
uint8_t idx = 0;
|
||||
|
||||
// EMPTY BUFFER
|
||||
for (uint8_t i = 0; i < 5; i++) bits[i] = 0;
|
||||
|
||||
// REQUEST SAMPLE
|
||||
pinMode(pin, OUTPUT);
|
||||
digitalWrite(pin, LOW);
|
||||
delay(wakeupDelay);
|
||||
pinMode(pin, INPUT);
|
||||
delayMicroseconds(40);
|
||||
|
||||
// GET ACKNOWLEDGE or TIMEOUT
|
||||
uint16_t loopCnt = DHTLIB_TIMEOUT;
|
||||
while(digitalRead(pin) == LOW)
|
||||
{
|
||||
if (--loopCnt == 0) return DHTLIB_ERROR_TIMEOUT;
|
||||
}
|
||||
|
||||
loopCnt = DHTLIB_TIMEOUT;
|
||||
while(digitalRead(pin) == HIGH)
|
||||
{
|
||||
if (--loopCnt == 0) return DHTLIB_ERROR_TIMEOUT;
|
||||
}
|
||||
|
||||
// READ THE OUTPUT - 40 BITS => 5 BYTES
|
||||
for (uint8_t i = 40; i != 0; i--)
|
||||
{
|
||||
loopCnt = DHTLIB_TIMEOUT;
|
||||
while(digitalRead(pin) == LOW)
|
||||
{
|
||||
if (--loopCnt == 0) return DHTLIB_ERROR_TIMEOUT;
|
||||
}
|
||||
|
||||
uint32_t t = micros();
|
||||
|
||||
loopCnt = DHTLIB_TIMEOUT;
|
||||
while(digitalRead(pin) == HIGH)
|
||||
{
|
||||
if (--loopCnt == 0) return DHTLIB_ERROR_TIMEOUT;
|
||||
}
|
||||
|
||||
if ((micros() - t) > 40)
|
||||
{
|
||||
bits[idx] |= mask;
|
||||
}
|
||||
mask >>= 1;
|
||||
if (mask == 0) // next byte?
|
||||
{
|
||||
mask = 128;
|
||||
idx++;
|
||||
}
|
||||
}
|
||||
|
||||
return DHTLIB_OK;
|
||||
}
|
||||
//
|
||||
// END OF FILE
|
||||
//
|
||||
63
lib/DHT/dht.h
Normal file
63
lib/DHT/dht.h
Normal file
@@ -0,0 +1,63 @@
|
||||
//
|
||||
// FILE: dht.h
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.2.1
|
||||
// PURPOSE: DHT Temperature & Humidity Sensor library for Arduino
|
||||
// URL: https://github.com/RobTillaart/Arduino/tree/master/libraries/DHTstable
|
||||
//
|
||||
// HISTORY:
|
||||
// see dht.cpp file
|
||||
//
|
||||
|
||||
#ifndef dht_h
|
||||
#define dht_h
|
||||
|
||||
#if ARDUINO < 100
|
||||
#include <WProgram.h>
|
||||
#else
|
||||
#include <Arduino.h>
|
||||
#endif
|
||||
|
||||
#define DHT_LIB_VERSION "0.2.1 - dhtstable"
|
||||
|
||||
#define DHTLIB_OK 0
|
||||
#define DHTLIB_ERROR_CHECKSUM -1
|
||||
#define DHTLIB_ERROR_TIMEOUT -2
|
||||
#define DHTLIB_INVALID_VALUE -999
|
||||
|
||||
#define DHTLIB_DHT11_WAKEUP 18
|
||||
#define DHTLIB_DHT_WAKEUP 1
|
||||
|
||||
// max timeout is 100usec.
|
||||
// For a 16Mhz proc that is max 1600 clock cycles
|
||||
// loops using 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
|
||||
#define DHTLIB_TIMEOUT (F_CPU/40000)
|
||||
|
||||
class dht
|
||||
{
|
||||
public:
|
||||
// return values:
|
||||
// DHTLIB_OK
|
||||
// DHTLIB_ERROR_CHECKSUM
|
||||
// DHTLIB_ERROR_TIMEOUT
|
||||
int read11(uint8_t pin);
|
||||
int read(uint8_t pin);
|
||||
|
||||
inline int read21(uint8_t pin) { return read(pin); };
|
||||
inline int read22(uint8_t pin) { return read(pin); };
|
||||
inline int read33(uint8_t pin) { return read(pin); };
|
||||
inline int read44(uint8_t pin) { return read(pin); };
|
||||
|
||||
float humidity;
|
||||
float temperature;
|
||||
|
||||
private:
|
||||
uint8_t bits[5]; // buffer to receive data
|
||||
int _readSensor(uint8_t pin, uint8_t wakeupDelay);
|
||||
};
|
||||
#endif
|
||||
//
|
||||
// END OF FILE
|
||||
//
|
||||
56
lib/DHT/examples/dht11_test/dht11_test.ino
Normal file
56
lib/DHT/examples/dht11_test/dht11_test.ino
Normal file
@@ -0,0 +1,56 @@
|
||||
//
|
||||
// FILE: dht11_test.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.01
|
||||
// PURPOSE: DHT library test sketch for DHT11 && Arduino
|
||||
// URL:
|
||||
//
|
||||
// Released to the public domain
|
||||
//
|
||||
|
||||
#include <dht.h>
|
||||
|
||||
dht DHT;
|
||||
|
||||
#define DHT11_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("DHT11, \t");
|
||||
int chk = DHT.read11(DHT11_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
|
||||
//
|
||||
105
lib/DHT/examples/dht22_test/dht22_test.ino
Normal file
105
lib/DHT/examples/dht22_test/dht22_test.ino
Normal file
@@ -0,0 +1,105 @@
|
||||
//
|
||||
// FILE: dht22_test.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// VERSION: 0.1.03
|
||||
// PURPOSE: DHT library test sketch for DHT22 && Arduino
|
||||
// URL:
|
||||
// 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
|
||||
//
|
||||
// Released to the public domain
|
||||
//
|
||||
|
||||
#include <dht.h>
|
||||
|
||||
dht DHT;
|
||||
|
||||
#define DHT22_PIN 5
|
||||
|
||||
struct
|
||||
{
|
||||
uint32_t total;
|
||||
uint32_t ok;
|
||||
uint32_t crc_error;
|
||||
uint32_t time_out;
|
||||
uint32_t connect;
|
||||
uint32_t ack_l;
|
||||
uint32_t ack_h;
|
||||
uint32_t unknown;
|
||||
} stat = { 0,0,0,0,0,0,0,0};
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println("dht22_test.ino");
|
||||
Serial.print("LIBRARY VERSION: ");
|
||||
Serial.println(DHT_LIB_VERSION);
|
||||
Serial.println();
|
||||
Serial.println("Type,\tstatus,\tHumidity (%),\tTemperature (C)\tTime (us)");
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
// READ DATA
|
||||
Serial.print("DHT22, \t");
|
||||
|
||||
uint32_t start = micros();
|
||||
int chk = DHT.read22(DHT22_PIN);
|
||||
uint32_t stop = micros();
|
||||
|
||||
stat.total++;
|
||||
switch (chk)
|
||||
{
|
||||
case DHTLIB_OK:
|
||||
stat.ok++;
|
||||
Serial.print("OK,\t");
|
||||
break;
|
||||
case DHTLIB_ERROR_CHECKSUM:
|
||||
stat.crc_error++;
|
||||
Serial.print("Checksum error,\t");
|
||||
break;
|
||||
case DHTLIB_ERROR_TIMEOUT:
|
||||
stat.time_out++;
|
||||
Serial.print("Time out error,\t");
|
||||
break;
|
||||
default:
|
||||
stat.unknown++;
|
||||
Serial.print("Unknown error,\t");
|
||||
break;
|
||||
}
|
||||
// DISPLAY DATA
|
||||
Serial.print(DHT.humidity, 1);
|
||||
Serial.print(",\t");
|
||||
Serial.print(DHT.temperature, 1);
|
||||
Serial.print(",\t");
|
||||
Serial.print(stop - start);
|
||||
Serial.println();
|
||||
|
||||
if (stat.total % 20 == 0)
|
||||
{
|
||||
Serial.println("\nTOT\tOK\tCRC\tTO\tUNK");
|
||||
Serial.print(stat.total);
|
||||
Serial.print("\t");
|
||||
Serial.print(stat.ok);
|
||||
Serial.print("\t");
|
||||
Serial.print(stat.crc_error);
|
||||
Serial.print("\t");
|
||||
Serial.print(stat.time_out);
|
||||
Serial.print("\t");
|
||||
Serial.print(stat.connect);
|
||||
Serial.print("\t");
|
||||
Serial.print(stat.ack_l);
|
||||
Serial.print("\t");
|
||||
Serial.print(stat.ack_h);
|
||||
Serial.print("\t");
|
||||
Serial.print(stat.unknown);
|
||||
Serial.println("\n");
|
||||
}
|
||||
delay(2000);
|
||||
}
|
||||
//
|
||||
// END OF FILE
|
||||
//
|
||||
2
lib/DHT/examples/readme.txt
Normal file
2
lib/DHT/examples/readme.txt
Normal file
@@ -0,0 +1,2 @@
|
||||
2015-08-20 these examples are retrofitted from version 0.1.20 which supports more errors.
|
||||
|
||||
32
lib/DHT/keywords.txt
Normal file
32
lib/DHT/keywords.txt
Normal file
@@ -0,0 +1,32 @@
|
||||
#######################################
|
||||
# Syntax Coloring Map For DHT
|
||||
#######################################
|
||||
|
||||
#######################################
|
||||
# Datatypes (KEYWORD1)
|
||||
#######################################
|
||||
|
||||
DHT KEYWORD1
|
||||
|
||||
#######################################
|
||||
# Methods and Functions (KEYWORD2)
|
||||
#######################################
|
||||
|
||||
read KEYWORD2
|
||||
read11 KEYWORD2
|
||||
read21 KEYWORD2
|
||||
read22 KEYWORD2
|
||||
read33 KEYWORD2
|
||||
read44 KEYWORD2
|
||||
humidity KEYWORD2
|
||||
temperature KEYWORD2
|
||||
|
||||
#######################################
|
||||
# Instances (KEYWORD2)
|
||||
#######################################
|
||||
|
||||
|
||||
#######################################
|
||||
# Constants (LITERAL1)
|
||||
#######################################
|
||||
|
||||
23
lib/DHT/library.json
Normal file
23
lib/DHT/library.json
Normal file
@@ -0,0 +1,23 @@
|
||||
{
|
||||
"name": "DHTStable",
|
||||
"keywords": "DHT11 DHT22 DHT33 DHT44 AM2301 AM2302 AM2303",
|
||||
"description": "Stable version of the library for DHT Temperature & Humidity Sensor.",
|
||||
"authors":
|
||||
[
|
||||
{
|
||||
"name": "Rob Tillaart",
|
||||
"email": "Rob.Tillaart@gmail.com",
|
||||
"maintainer": true
|
||||
}
|
||||
],
|
||||
"repository":
|
||||
{
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/Arduino.git"
|
||||
},
|
||||
"frameworks": "arduino",
|
||||
"platforms": "atmelavr",
|
||||
"export": {
|
||||
"include": "libraries/DHTstable"
|
||||
}
|
||||
}
|
||||
9
lib/DHT/library.properties
Normal file
9
lib/DHT/library.properties
Normal file
@@ -0,0 +1,9 @@
|
||||
name=DHTStable
|
||||
version=0.2.1
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Stable version of library for DHT Temperature & Humidity Sensor
|
||||
paragraph=
|
||||
category=Sensors
|
||||
url=https://github.com/RobTillaart/Arduino/tree/master/libraries/
|
||||
architectures=*
|
||||
13
lib/DHT/readme.md
Normal file
13
lib/DHT/readme.md
Normal file
@@ -0,0 +1,13 @@
|
||||
|
||||
This is the 0.2.1 version of the DHTlib.
|
||||
This version is stable for both ARM and AVR.
|
||||
|
||||
You can use most examples from https://github.com/RobTillaart/Arduino/tree/master/libraries/DHTlib/examples
|
||||
|
||||
update 2015-10-12:
|
||||
For multithreading environments for Arduino one could replace
|
||||
delay(wakeupDelay);
|
||||
with
|
||||
delayMicroseconds(wakeupDelay * 1000UL);
|
||||
see also - https://github.com/RobTillaart/Arduino/pull/25 -
|
||||
|
||||
13
lib/DHT/readme.txt
Normal file
13
lib/DHT/readme.txt
Normal file
@@ -0,0 +1,13 @@
|
||||
|
||||
This is the 0.1.13 version of the DHTlib.
|
||||
This version is stable for both ARM and AVR.
|
||||
|
||||
You can use most examples from https://github.com/RobTillaart/Arduino/tree/master/libraries/DHTlib/examples
|
||||
|
||||
update 2015-10-12:
|
||||
For multithreading environments for Arduino one could replace
|
||||
delay(wakeupDelay);
|
||||
with
|
||||
delayMicroseconds(wakeupDelay * 1000UL);
|
||||
see also - https://github.com/RobTillaart/Arduino/pull/25 -
|
||||
|
||||
Reference in New Issue
Block a user