From 931a40fb4135d43a2a97e3c0fad175872d40d83f Mon Sep 17 00:00:00 2001 From: niesteszeck Date: Fri, 22 Mar 2013 10:37:32 -0300 Subject: [PATCH 01/15] First commit library created --- idDHT11.cpp | 173 ++++++++++++++++++++++++++++++++++++++++++++++++++++ idDHT11.h | 73 ++++++++++++++++++++++ 2 files changed, 246 insertions(+) create mode 100644 idDHT11.cpp create mode 100644 idDHT11.h diff --git a/idDHT11.cpp b/idDHT11.cpp new file mode 100644 index 0000000..8a33cbb --- /dev/null +++ b/idDHT11.cpp @@ -0,0 +1,173 @@ +/* + FILE: idDHT11.cpp + VERSION: 0.1 + PURPOSE: Interrupt driven Lib for DHT11 with Arduino. + LICENCE: GPL v3 (http://www.gnu.org/licenses/gpl.html) + DATASHEET: http://www.micro4you.com/files/sensor/DHT11.pdf + + Based on DHT11 library: http://playground.arduino.cc/Main/DHT11Lib +*/ + +#include "idDHT11.h" +#define DEBUG_IDDHT11 + +idDHT11::idDHT11(int pin, int intNumber,void (*callback_wrapper)()) { + init(pin, intNumber,callback_wrapper); +} + +void idDHT11::init(int pin, int intNumber, void (*callback_wrapper) ()) { + this->intNumber = intNumber; + this->pin = pin; + this->isrCallback_wrapper = callback_wrapper; + hum = 0; + temp = 0; + pinMode(pin, OUTPUT); + digitalWrite(pin, HIGH); + state = STOPED; + status = IDDHTLIB_ERROR_NOTSTARTED; +} + +int idDHT11::acquire() { + if (state == STOPED || state == ACQUIRED) { + + //set the state machine for interruptions analisis of the signal + state = RESPONSE; + + // EMPTY BUFFER and vars + for (int i=0; i< 5; i++) bits[i] = 0; + cnt = 7; + idx = 0; + hum = 0; + temp = 0; + + // REQUEST SAMPLE + pinMode(pin, OUTPUT); + digitalWrite(pin, LOW); + delay(18); + digitalWrite(pin, HIGH); + delayMicroseconds(40); + pinMode(pin, INPUT); + + // Analize the data in an interrupt + us = micros(); + attachInterrupt(intNumber,isrCallback_wrapper,FALLING); + + return IDDHTLIB_ACQUIRING; + } else + return IDDHTLIB_ERROR_ACQUIRING; +} +void idDHT11::isrCallback() { + int newUs = micros(); + int delta = (newUs-us); + us = newUs; + if (delta>6000) { + status = IDDHTLIB_ERROR_TIMEOUT; + state = STOPED; + detachInterrupt(intNumber); + return; + } + switch(state) { + case RESPONSE: + if(delta<25) + return; //do nothing, it started the response signal + if(12590) //is a one + bits[idx] |= (1 << cnt); + if (cnt == 0) { // whe have fullfilled the byte, go to next + cnt = 7; // restart at MSB + if(idx++ == 4) { // go to next byte, if whe have got 5 bytes stop. + detachInterrupt(intNumber); + // WRITE TO RIGHT VARS + // as bits[1] and bits[3] are allways zero they are omitted in formulas. + hum = bits[0]; + temp = bits[2]; + uint8_t sum = bits[0] + bits[2]; + if (bits[4] != sum) { + status = IDDHTLIB_ERROR_CHECKSUM; + state = STOPED; + } else { + status = IDDHTLIB_OK; + state = ACQUIRED; + } + break; + } + } else cnt--; + } else { + detachInterrupt(intNumber); + status = IDDHTLIB_ERROR_TIMEOUT; + state = STOPED; + } + break; + default: + break; + } +} +bool idDHT11::acquiring() { + if (state != ACQUIRED && state != STOPED) + return true; + return false; +} +int idDHT11::getStatus() { + return status; +} +float idDHT11::getCelsius() { + IDDHT11_CHECK_STATE; + return temp; +} + +float idDHT11::getHumidity() { + IDDHT11_CHECK_STATE; + return hum; +} + +float idDHT11::getFahrenheit() { + IDDHT11_CHECK_STATE; + return temp * 1.8 + 32; +} + +float idDHT11::getKelvin() { + IDDHT11_CHECK_STATE; + return temp + 273.15; +} + +// delta max = 0.6544 wrt dewPoint() +// 5x faster than dewPoint() +// reference: http://en.wikipedia.org/wiki/Dew_point +double idDHT11::getDewPoint() { + IDDHT11_CHECK_STATE; + double a = 17.271; + double b = 237.7; + double temp_ = (a * (double) temp) / (b + (double) temp) + log( (double) hum/100); + double Td = (b * temp_) / (a - temp_); + return Td; + +} +// dewPoint function NOAA +// reference: http://wahiduddin.net/calc/density_algorithms.htm +double idDHT11::getDewPointSlow() { + IDDHT11_CHECK_STATE; + double A0= 373.15/(273.15 + (double) temp); + double SUM = -7.90298 * (A0-1); + SUM += 5.02808 * log10(A0); + SUM += -1.3816e-7 * (pow(10, (11.344*(1-1/A0)))-1) ; + SUM += 8.1328e-3 * (pow(10,(-3.49149*(A0-1)))-1) ; + SUM += log10(1013.246); + double VP = pow(10, SUM-3) * (double) hum; + double T = log(VP/0.61078); // temp var + return (241.88 * T) / (17.558-T); +} +// EOF \ No newline at end of file diff --git a/idDHT11.h b/idDHT11.h new file mode 100644 index 0000000..4045656 --- /dev/null +++ b/idDHT11.h @@ -0,0 +1,73 @@ +/* + FILE: idDHT11.h + VERSION: 0.1 + PURPOSE: Interrupt driven Lib for DHT11 with Arduino. + LICENCE: GPL v3 (http://www.gnu.org/licenses/gpl.html) + DATASHEET: http://www.micro4you.com/files/sensor/DHT11.pdf + + Based on DHT11 library: http://playground.arduino.cc/Main/DHT11Lib +*/ + + +#ifndef idDHT11_H__ +#define idDHT11_H__ + +#if defined(ARDUINO) && (ARDUINO >= 100) +#include +#else +#include +#endif + +#define IDDHT11LIB_VERSION "0.1" + +// state codes +#define IDDHTLIB_OK 0 +#define IDDHTLIB_ACQUIRING 1 +#define IDDHTLIB_ACQUIRED 2 +#define IDDHTLIB_RESPONSE_OK 3 + +// error codes +#define IDDHTLIB_ERROR_CHECKSUM -1 +#define IDDHTLIB_ERROR_TIMEOUT -2 +#define IDDHTLIB_ERROR_ACQUIRING -3 +#define IDDHTLIB_ERROR_DELTA -4 +#define IDDHTLIB_ERROR_NOTSTARTED -5 + +#define IDDHT11_CHECK_STATE if(state == STOPED) \ + return status; \ + else if(state != ACQUIRED) \ + return IDDHTLIB_ERROR_ACQUIRING; + +class idDHT11 +{ +public: + idDHT11(int pin, int intNumber,void (*isrCallback_wrapper)()); + void init(int pin, int intNumber,void (*isrCallback_wrapper)()); + void isrCallback(); + int acquire(); + float getCelsius(); + float getFahrenheit(); + float getKelvin(); + double getDewPoint(); + double getDewPointSlow(); + float getHumidity(); + bool acquiring(); + int getStatus(); + +private: + + void (*isrCallback_wrapper)(void); + + enum states{RESPONSE=0,DATA=1,ACQUIRED=2,STOPED=3,ACQUIRING=4}; + volatile states state; + volatile int status; + volatile byte bits[5]; + volatile byte cnt; + volatile byte idx; + volatile int us; + int intNumber; + int pin; + volatile float hum; + volatile float temp; +}; +#endif // idDHT11_H__ \ No newline at end of file From 4980566e18797028590c6ae730d7fff9b565f164 Mon Sep 17 00:00:00 2001 From: niesteszeck Date: Fri, 22 Mar 2013 11:21:48 -0300 Subject: [PATCH 02/15] Added an example sketch --- .../idDHT11_Lib_example.ino | 84 +++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 examples/idDHT11_Lib_example/idDHT11_Lib_example.ino diff --git a/examples/idDHT11_Lib_example/idDHT11_Lib_example.ino b/examples/idDHT11_Lib_example/idDHT11_Lib_example.ino new file mode 100644 index 0000000..8d7ceca --- /dev/null +++ b/examples/idDHT11_Lib_example/idDHT11_Lib_example.ino @@ -0,0 +1,84 @@ +/* + Board int.0 int.1 int.2 int.3 int.4 int.5 + Uno, Ethernet 2 3 + Mega2560 2 3 21 20 19 18 + Leonardo 3 2 0 1 + Due (any pin, more info http://arduino.cc/en/Reference/AttachInterrupt) + */ + +#include + +int idDHT11pin = 2; //Digital pin for comunications +int idDHT11intNumber = 0; //interrupt number (must be the one that use the previus defined pin (see table above) + +//declaration +void dht11_wrapper(); + +// Lib instantiate +idDHT11 DHT11(idDHT11pin,idDHT11intNumber,dht11_wrapper); + +void setup() +{ + Serial.begin(9600); + Serial.println("idDHT11 Example program"); + Serial.print("LIB version: "); + Serial.println(IDDHT11LIB_VERSION); + Serial.println("---------------"); +} +void dht11_wrapper() { + DHT11.isrCallback(); +} +void loop() +{ + Serial.print("\nRetrieving information from sensor: "); + Serial.print("Read sensor: "); + //delay(100); + DHT11.acquire(); + while (DHT11.acquiring()) + ; + int result = DHT11.getStatus(); + switch (result) + { + case IDDHTLIB_OK: + Serial.println("OK"); + break; + case IDDHTLIB_ERROR_CHECKSUM: + Serial.println("Error\n\r\tChecksum error"); + break; + case IDDHTLIB_ERROR_TIMEOUT: + Serial.println("Error\n\r\tTime out error"); + break; + case IDDHTLIB_ERROR_ACQUIRING: + Serial.println("Error\n\r\tAcquiring"); + break; + case IDDHTLIB_ERROR_DELTA: + Serial.println("Error\n\r\tDelta time to small"); + break; + case IDDHTLIB_ERROR_NOTSTARTED: + Serial.println("Error\n\r\tNot started"); + break; + default: + Serial.println("Unknown error"); + break; + } + Serial.print("Humidity (%): "); + Serial.println(DHT11.getHumidity(), 2); + + Serial.print("Temperature (oC): "); + Serial.println(DHT11.getCelsius(), 2); + + Serial.print("Temperature (oF): "); + Serial.println(DHT11.getFahrenheit(), 2); + + Serial.print("Temperature (K): "); + Serial.println(DHT11.getKelvin(), 2); + + Serial.print("Dew Point (oC): "); + Serial.println(DHT11.getDewPoint()); + + Serial.print("Dew Point Slow (oC): "); + Serial.println(DHT11.getDewPointSlow()); + + delay(2000); +} + From 5eb6886bf730e431ae828580e52c3d21787e2bbf Mon Sep 17 00:00:00 2001 From: niesteszeck Date: Fri, 22 Mar 2013 06:31:41 -0700 Subject: [PATCH 03/15] Merge branch 'master' of https://github.com/niesteszeck/idDHT11 --- README.md | 4 ++++ 1 file changed, 4 insertions(+) create mode 100644 README.md diff --git a/README.md b/README.md new file mode 100644 index 0000000..4f1e120 --- /dev/null +++ b/README.md @@ -0,0 +1,4 @@ +idDHT11 +======= + +Interrupt driven DHT11 library \ No newline at end of file From c312448f6d746b0adc6a3aea3c69b716ec95a93d Mon Sep 17 00:00:00 2001 From: niesteszeck Date: Fri, 22 Mar 2013 11:24:50 -0300 Subject: [PATCH 04/15] Update README.md --- README.md | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 4f1e120..884dc2d 100644 --- a/README.md +++ b/README.md @@ -1,4 +1,11 @@ idDHT11 ======= -Interrupt driven DHT11 library \ No newline at end of file +Interrupt driven DHT11 library + +VERSION: 0.1 +PURPOSE: Interrupt driven Lib for DHT11 with Arduino. +LICENCE: GPL v3 (http://www.gnu.org/licenses/gpl.html) +DATASHEET: http://www.micro4you.com/files/sensor/DHT11.pdf + +Based on DHT11 library: http://playground.arduino.cc/Main/DHT11Lib From 695744c24ac8308665adf540fd5e2f5e625cf555 Mon Sep 17 00:00:00 2001 From: niesteszeck Date: Fri, 22 Mar 2013 11:25:12 -0300 Subject: [PATCH 05/15] Update README.md --- README.md | 2 ++ 1 file changed, 2 insertions(+) diff --git a/README.md b/README.md index 884dc2d..10e831c 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,9 @@ Interrupt driven DHT11 library VERSION: 0.1 PURPOSE: Interrupt driven Lib for DHT11 with Arduino. + LICENCE: GPL v3 (http://www.gnu.org/licenses/gpl.html) + DATASHEET: http://www.micro4you.com/files/sensor/DHT11.pdf Based on DHT11 library: http://playground.arduino.cc/Main/DHT11Lib From ea4925fcd604b802c9178d507adc8070414132bf Mon Sep 17 00:00:00 2001 From: niesteszeck Date: Fri, 22 Mar 2013 17:06:42 -0300 Subject: [PATCH 06/15] Corrected STOPED -> STOPPED --- idDHT11.cpp | 16 ++++++++-------- idDHT11.h | 4 ++-- 2 files changed, 10 insertions(+), 10 deletions(-) diff --git a/idDHT11.cpp b/idDHT11.cpp index 8a33cbb..be7c476 100644 --- a/idDHT11.cpp +++ b/idDHT11.cpp @@ -23,12 +23,12 @@ void idDHT11::init(int pin, int intNumber, void (*callback_wrapper) ()) { temp = 0; pinMode(pin, OUTPUT); digitalWrite(pin, HIGH); - state = STOPED; + state = STOPPED; status = IDDHTLIB_ERROR_NOTSTARTED; } int idDHT11::acquire() { - if (state == STOPED || state == ACQUIRED) { + if (state == STOPPED || state == ACQUIRED) { //set the state machine for interruptions analisis of the signal state = RESPONSE; @@ -62,7 +62,7 @@ void idDHT11::isrCallback() { us = newUs; if (delta>6000) { status = IDDHTLIB_ERROR_TIMEOUT; - state = STOPED; + state = STOPPED; detachInterrupt(intNumber); return; } @@ -75,14 +75,14 @@ void idDHT11::isrCallback() { } else { detachInterrupt(intNumber); status = IDDHTLIB_ERROR_TIMEOUT; - state = STOPED; + state = STOPPED; } break; case DATA: if(delta<10) { detachInterrupt(intNumber); status = IDDHTLIB_ERROR_DELTA; - state = STOPED; + state = STOPPED; // return; } else if(6090) //is a one @@ -98,7 +98,7 @@ void idDHT11::isrCallback() { uint8_t sum = bits[0] + bits[2]; if (bits[4] != sum) { status = IDDHTLIB_ERROR_CHECKSUM; - state = STOPED; + state = STOPPED; } else { status = IDDHTLIB_OK; state = ACQUIRED; @@ -109,7 +109,7 @@ void idDHT11::isrCallback() { } else { detachInterrupt(intNumber); status = IDDHTLIB_ERROR_TIMEOUT; - state = STOPED; + state = STOPPED; } break; default: @@ -117,7 +117,7 @@ void idDHT11::isrCallback() { } } bool idDHT11::acquiring() { - if (state != ACQUIRED && state != STOPED) + if (state != ACQUIRED && state != STOPPED) return true; return false; } diff --git a/idDHT11.h b/idDHT11.h index 4045656..4bc2c08 100644 --- a/idDHT11.h +++ b/idDHT11.h @@ -33,7 +33,7 @@ #define IDDHTLIB_ERROR_DELTA -4 #define IDDHTLIB_ERROR_NOTSTARTED -5 -#define IDDHT11_CHECK_STATE if(state == STOPED) \ +#define IDDHT11_CHECK_STATE if(state == STOPPED) \ return status; \ else if(state != ACQUIRED) \ return IDDHTLIB_ERROR_ACQUIRING; @@ -58,7 +58,7 @@ private: void (*isrCallback_wrapper)(void); - enum states{RESPONSE=0,DATA=1,ACQUIRED=2,STOPED=3,ACQUIRING=4}; + enum states{RESPONSE=0,DATA=1,ACQUIRED=2,STOPPED=3,ACQUIRING=4}; volatile states state; volatile int status; volatile byte bits[5]; From ac5c661b2d8a288e8ac038319005fda34d93209b Mon Sep 17 00:00:00 2001 From: niesteszeck Date: Fri, 22 Mar 2013 17:20:18 -0300 Subject: [PATCH 07/15] added keywords.txt to highlight --- keywords.txt | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 keywords.txt diff --git a/keywords.txt b/keywords.txt new file mode 100644 index 0000000..8c3d0e9 --- /dev/null +++ b/keywords.txt @@ -0,0 +1,39 @@ +####################################### +# Syntax Coloring Map For Messenger +####################################### + +####################################### +# Datatypes (KEYWORD1) +####################################### + + +####################################### +# Methods and Functions (KEYWORD2) +####################################### + +init KEYWORD2 +acquire KEYWORD2 +getCelsius KEYWORD2 +getFahrenheit KEYWORD2 +getKelvin KEYWORD2 +getDewPoint KEYWORD2 +getDewPointSlow KEYWORD2 +getHumidity KEYWORD2 +acquiring KEYWORD2 +getStatus KEYWORD2 +####################################### +# Instances (KEYWORD2) +####################################### +idDHT11 KEYWORD2 +####################################### +# Constants (LITERAL1) +####################################### +IDDHTLIB_OK LITERAL1 +IDDHTLIB_ACQUIRING LITERAL1 +IDDHTLIB_ACQUIRED LITERAL1 +IDDHTLIB_RESPONSE_OK LITERAL1 +IDDHTLIB_ERROR_CHECKSUM LITERAL1 +IDDHTLIB_ERROR_TIMEOUT LITERAL1 +IDDHTLIB_ERROR_ACQUIRING LITERAL1 +IDDHTLIB_ERROR_DELTA LITERAL1 +IDDHTLIB_ERROR_NOTSTARTED LITERAL1 From c13b5732b8d0677682a9dd5ecca12ca878ebc245 Mon Sep 17 00:00:00 2001 From: niesteszeck Date: Fri, 22 Mar 2013 18:14:13 -0300 Subject: [PATCH 08/15] mod to the response timing --- idDHT11.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/idDHT11.cpp b/idDHT11.cpp index be7c476..7fc0a19 100644 --- a/idDHT11.cpp +++ b/idDHT11.cpp @@ -68,9 +68,10 @@ void idDHT11::isrCallback() { } switch(state) { case RESPONSE: - if(delta<25) - return; //do nothing, it started the response signal - if(12590) //is a one bits[idx] |= (1 << cnt); From 2358dd9746d8a11a5be0f0135488ddc243c20678 Mon Sep 17 00:00:00 2001 From: niesteszeck Date: Mon, 25 Mar 2013 17:37:25 -0300 Subject: [PATCH 09/15] added a new method acquireAndWait to make easy to use the lib and a example that use it --- .../idDHT11_Lib_example_Simple.ino | 84 +++++++++++++++++++ idDHT11.cpp | 6 ++ idDHT11.h | 1 + 3 files changed, 91 insertions(+) create mode 100644 examples/idDHT11_Lib_example_Simple/idDHT11_Lib_example_Simple.ino diff --git a/examples/idDHT11_Lib_example_Simple/idDHT11_Lib_example_Simple.ino b/examples/idDHT11_Lib_example_Simple/idDHT11_Lib_example_Simple.ino new file mode 100644 index 0000000..fe3b65b --- /dev/null +++ b/examples/idDHT11_Lib_example_Simple/idDHT11_Lib_example_Simple.ino @@ -0,0 +1,84 @@ +/* + Board int.0 int.1 int.2 int.3 int.4 int.5 + Uno, Ethernet 2 3 + Mega2560 2 3 21 20 19 18 + Leonardo 3 2 0 1 + Due (any pin, more info http://arduino.cc/en/Reference/AttachInterrupt) + + This example, as difference to the other, make use of the new method acquireAndWait() + */ + +#include + +int idDHT11pin = 2; //Digital pin for comunications +int idDHT11intNumber = 0; //interrupt number (must be the one that use the previus defined pin (see table above) + +//declaration +void dht11_wrapper(); + +// Lib instantiate +idDHT11 DHT11(idDHT11pin,idDHT11intNumber,dht11_wrapper); + +void setup() +{ + Serial.begin(9600); + Serial.println("idDHT11 Example program"); + Serial.print("LIB version: "); + Serial.println(IDDHT11LIB_VERSION); + Serial.println("---------------"); +} +void dht11_wrapper() { + DHT11.isrCallback(); +} +void loop() +{ + Serial.print("\nRetrieving information from sensor: "); + Serial.print("Read sensor: "); + //delay(100); + + int result = DHT11.acquireAndWait(); + switch (result) + { + case IDDHTLIB_OK: + Serial.println("OK"); + break; + case IDDHTLIB_ERROR_CHECKSUM: + Serial.println("Error\n\r\tChecksum error"); + break; + case IDDHTLIB_ERROR_TIMEOUT: + Serial.println("Error\n\r\tTime out error"); + break; + case IDDHTLIB_ERROR_ACQUIRING: + Serial.println("Error\n\r\tAcquiring"); + break; + case IDDHTLIB_ERROR_DELTA: + Serial.println("Error\n\r\tDelta time to small"); + break; + case IDDHTLIB_ERROR_NOTSTARTED: + Serial.println("Error\n\r\tNot started"); + break; + default: + Serial.println("Unknown error"); + break; + } + Serial.print("Humidity (%): "); + Serial.println(DHT11.getHumidity(), 2); + + Serial.print("Temperature (oC): "); + Serial.println(DHT11.getCelsius(), 2); + + Serial.print("Temperature (oF): "); + Serial.println(DHT11.getFahrenheit(), 2); + + Serial.print("Temperature (K): "); + Serial.println(DHT11.getKelvin(), 2); + + Serial.print("Dew Point (oC): "); + Serial.println(DHT11.getDewPoint()); + + Serial.print("Dew Point Slow (oC): "); + Serial.println(DHT11.getDewPointSlow()); + + delay(2000); +} + diff --git a/idDHT11.cpp b/idDHT11.cpp index 7fc0a19..b67ed01 100644 --- a/idDHT11.cpp +++ b/idDHT11.cpp @@ -56,6 +56,12 @@ int idDHT11::acquire() { } else return IDDHTLIB_ERROR_ACQUIRING; } +int idDHT11::acquireAndWait() { + acquire(); + while(acquiring()) + ; + return getStatus(); +} void idDHT11::isrCallback() { int newUs = micros(); int delta = (newUs-us); diff --git a/idDHT11.h b/idDHT11.h index 4bc2c08..384cc44 100644 --- a/idDHT11.h +++ b/idDHT11.h @@ -45,6 +45,7 @@ public: void init(int pin, int intNumber,void (*isrCallback_wrapper)()); void isrCallback(); int acquire(); + int acquireAndWait(); float getCelsius(); float getFahrenheit(); float getKelvin(); From 56cfe7e0bd4b3fe3dc82cae8158ddd2138cdf992 Mon Sep 17 00:00:00 2001 From: niesteszeck Date: Thu, 4 Jul 2013 09:59:22 -0400 Subject: [PATCH 10/15] example comments improvements --- examples/idDHT11_Lib_example/idDHT11_Lib_example.ino | 4 +++- .../idDHT11_Lib_example_Simple/idDHT11_Lib_example_Simple.ino | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/examples/idDHT11_Lib_example/idDHT11_Lib_example.ino b/examples/idDHT11_Lib_example/idDHT11_Lib_example.ino index 8d7ceca..b043514 100644 --- a/examples/idDHT11_Lib_example/idDHT11_Lib_example.ino +++ b/examples/idDHT11_Lib_example/idDHT11_Lib_example.ino @@ -12,7 +12,7 @@ int idDHT11pin = 2; //Digital pin for comunications int idDHT11intNumber = 0; //interrupt number (must be the one that use the previus defined pin (see table above) //declaration -void dht11_wrapper(); +void dht11_wrapper(); // must be declared before the lib initialization // Lib instantiate idDHT11 DHT11(idDHT11pin,idDHT11intNumber,dht11_wrapper); @@ -25,6 +25,8 @@ void setup() Serial.println(IDDHT11LIB_VERSION); Serial.println("---------------"); } +// This wrapper is in charge of calling +// mus be defined like this for the lib work void dht11_wrapper() { DHT11.isrCallback(); } diff --git a/examples/idDHT11_Lib_example_Simple/idDHT11_Lib_example_Simple.ino b/examples/idDHT11_Lib_example_Simple/idDHT11_Lib_example_Simple.ino index fe3b65b..b43182a 100644 --- a/examples/idDHT11_Lib_example_Simple/idDHT11_Lib_example_Simple.ino +++ b/examples/idDHT11_Lib_example_Simple/idDHT11_Lib_example_Simple.ino @@ -14,7 +14,7 @@ int idDHT11pin = 2; //Digital pin for comunications int idDHT11intNumber = 0; //interrupt number (must be the one that use the previus defined pin (see table above) //declaration -void dht11_wrapper(); +void dht11_wrapper(); // must be declared before the lib initialization // Lib instantiate idDHT11 DHT11(idDHT11pin,idDHT11intNumber,dht11_wrapper); @@ -27,6 +27,8 @@ void setup() Serial.println(IDDHT11LIB_VERSION); Serial.println("---------------"); } +// This wrapper is in charge of calling +// mus be defined like this for the lib work void dht11_wrapper() { DHT11.isrCallback(); } From e2769e3a7e279440134188fdfe19052ccdb7383e Mon Sep 17 00:00:00 2001 From: Alex Gutowski Date: Mon, 28 Oct 2013 00:54:06 -0500 Subject: [PATCH 11/15] Updates idDHT11.cpp to differentiate between timeouts Creates three different error codes instead of a single code for three timeout possibilities. --- idDHT11.cpp | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/idDHT11.cpp b/idDHT11.cpp index b67ed01..4f03667 100644 --- a/idDHT11.cpp +++ b/idDHT11.cpp @@ -67,7 +67,7 @@ void idDHT11::isrCallback() { int delta = (newUs-us); us = newUs; if (delta>6000) { - status = IDDHTLIB_ERROR_TIMEOUT; + status = IDDHTLIB_ERROR_ISR_TIMEOUT; state = STOPPED; detachInterrupt(intNumber); return; @@ -81,7 +81,7 @@ void idDHT11::isrCallback() { state = DATA; } else { detachInterrupt(intNumber); - status = IDDHTLIB_ERROR_TIMEOUT; + status = IDDHTLIB_ERROR_RESPONSE_TIMEOUT; state = STOPPED; } break; @@ -114,7 +114,7 @@ void idDHT11::isrCallback() { } else cnt--; } else { detachInterrupt(intNumber); - status = IDDHTLIB_ERROR_TIMEOUT; + status = IDDHTLIB_ERROR_DATA_TIMEOUT; state = STOPPED; } break; @@ -176,4 +176,4 @@ double idDHT11::getDewPointSlow() { double T = log(VP/0.61078); // temp var return (241.88 * T) / (17.558-T); } -// EOF \ No newline at end of file +// EOF From e73b4fb665c229415dc690597fc2cef870a070d7 Mon Sep 17 00:00:00 2001 From: Alex Gutowski Date: Mon, 28 Oct 2013 00:56:17 -0500 Subject: [PATCH 12/15] Updates idDHT11.h to differentiate between timeouts Creates three different error codes instead of a single code for three timeout possibilities. --- idDHT11.h | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/idDHT11.h b/idDHT11.h index 384cc44..ea39613 100644 --- a/idDHT11.h +++ b/idDHT11.h @@ -21,17 +21,19 @@ #define IDDHT11LIB_VERSION "0.1" // state codes -#define IDDHTLIB_OK 0 +#define IDDHTLIB_OK 0 #define IDDHTLIB_ACQUIRING 1 #define IDDHTLIB_ACQUIRED 2 -#define IDDHTLIB_RESPONSE_OK 3 +#define IDDHTLIB_RESPONSE_OK 3 // error codes #define IDDHTLIB_ERROR_CHECKSUM -1 -#define IDDHTLIB_ERROR_TIMEOUT -2 -#define IDDHTLIB_ERROR_ACQUIRING -3 -#define IDDHTLIB_ERROR_DELTA -4 -#define IDDHTLIB_ERROR_NOTSTARTED -5 +#define IDDHTLIB_ERROR_ISR_TIMEOUT -2 +#define IDDHTLIB_ERROR_RESPONSE_TIMEOUT -3 +#define IDDHTLIB_ERROR_DATA_TIMEOUT -4 +#define IDDHTLIB_ERROR_ACQUIRING -5 +#define IDDHTLIB_ERROR_DELTA -6 +#define IDDHTLIB_ERROR_NOTSTARTED -7 #define IDDHT11_CHECK_STATE if(state == STOPPED) \ return status; \ @@ -71,4 +73,4 @@ private: volatile float hum; volatile float temp; }; -#endif // idDHT11_H__ \ No newline at end of file +#endif // idDHT11_H__ From e15e40b20d4b0a5715af58f14901b91e7ec53bc9 Mon Sep 17 00:00:00 2001 From: Alex Gutowski Date: Mon, 28 Oct 2013 00:58:24 -0500 Subject: [PATCH 13/15] Adds timeout error messages for each new error code --- examples/idDHT11_Lib_example/idDHT11_Lib_example.ino | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/examples/idDHT11_Lib_example/idDHT11_Lib_example.ino b/examples/idDHT11_Lib_example/idDHT11_Lib_example.ino index b043514..05006b6 100644 --- a/examples/idDHT11_Lib_example/idDHT11_Lib_example.ino +++ b/examples/idDHT11_Lib_example/idDHT11_Lib_example.ino @@ -47,8 +47,14 @@ void loop() case IDDHTLIB_ERROR_CHECKSUM: Serial.println("Error\n\r\tChecksum error"); break; - case IDDHTLIB_ERROR_TIMEOUT: - Serial.println("Error\n\r\tTime out error"); + case IDDHTLIB_ERROR_ISR_TIMEOUT: + Serial.println("Error\n\r\tISR Time out error"); + break; + case IDDHTLIB_ERROR_RESPONSE_TIMEOUT: + Serial.println("Error\n\r\tResponse time out error"); + break; + case IDDHTLIB_ERROR_DATA_TIMEOUT: + Serial.println("Error\n\r\tData time out error"); break; case IDDHTLIB_ERROR_ACQUIRING: Serial.println("Error\n\r\tAcquiring"); From d5ec9e018558116a2be81d5362e00e581eed9b7d Mon Sep 17 00:00:00 2001 From: Alex Gutowski Date: Mon, 28 Oct 2013 00:59:37 -0500 Subject: [PATCH 14/15] Adds timeout error messages for each new error code --- .../idDHT11_Lib_example_Simple.ino | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/examples/idDHT11_Lib_example_Simple/idDHT11_Lib_example_Simple.ino b/examples/idDHT11_Lib_example_Simple/idDHT11_Lib_example_Simple.ino index b43182a..28c3ef6 100644 --- a/examples/idDHT11_Lib_example_Simple/idDHT11_Lib_example_Simple.ino +++ b/examples/idDHT11_Lib_example_Simple/idDHT11_Lib_example_Simple.ino @@ -47,8 +47,14 @@ void loop() case IDDHTLIB_ERROR_CHECKSUM: Serial.println("Error\n\r\tChecksum error"); break; - case IDDHTLIB_ERROR_TIMEOUT: - Serial.println("Error\n\r\tTime out error"); + case IDDHTLIB_ERROR_ISR_TIMEOUT: + Serial.println("Error\n\r\tISR time out error"); + break; + case IDDHTLIB_ERROR_RESPONSE_TIMEOUT: + Serial.println("Error\n\r\tResponse time out error"); + break; + case IDDHTLIB_ERROR_DATA_TIMEOUT: + Serial.println("Error\n\r\tData time out error"); break; case IDDHTLIB_ERROR_ACQUIRING: Serial.println("Error\n\r\tAcquiring"); From 6bc02837033f31cfb43808b211c49609a01dea54 Mon Sep 17 00:00:00 2001 From: Alex Gutowski Date: Mon, 28 Oct 2013 01:06:55 -0500 Subject: [PATCH 15/15] Adds more time to acquire data Example code consistently times out while grabbing data. Increasing the delta range for data acquisition fixes this. --- idDHT11.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/idDHT11.cpp b/idDHT11.cpp index 4f03667..c24bee7 100644 --- a/idDHT11.cpp +++ b/idDHT11.cpp @@ -90,7 +90,7 @@ void idDHT11::isrCallback() { detachInterrupt(intNumber); status = IDDHTLIB_ERROR_DELTA; state = STOPPED; - } else if(6090) //is a one bits[idx] |= (1 << cnt); if (cnt == 0) { // whe have fullfilled the byte, go to next