-
Notifications
You must be signed in to change notification settings - Fork 59
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Updated DHT_example to remove while loop Increased version numbers
- Loading branch information
Showing
6 changed files
with
91 additions
and
70 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,14 @@ | ||
/* | ||
* FILE: DHT_example.ino | ||
* VERSION: 0.2 | ||
* VERSION: 0.3 | ||
* PURPOSE: Example that uses DHT library with two sensors | ||
* LICENSE: GPL v3 (http://www.gnu.org/licenses/gpl.html) | ||
* | ||
* Calls acquire on one sensor and monitors the results for long term | ||
* analysis. It uses DHT.acquire and DHT.acquiring | ||
* Example that start acquisition of DHT sensor and allows the | ||
* loop to continue until the acquisition has completed | ||
* It uses DHT.acquire and DHT.acquiring | ||
* | ||
* Change DHT_SAMPLE_TIME to vary the frequency of samples | ||
* | ||
* Scott Piette (Piette Technologies) [email protected] | ||
* January 2014 Original Spark Port | ||
|
@@ -15,15 +18,21 @@ | |
|
||
#include "PietteTech_DHT/PietteTech_DHT.h" | ||
|
||
#define DHTTYPE DHT22 // Sensor type DHT11/21/22/AM2301/AM2302 | ||
#define DHTPIN 3 // Digital pin for communications | ||
// system defines | ||
#define DHTTYPE DHT22 // Sensor type DHT11/21/22/AM2301/AM2302 | ||
#define DHTPIN 3 // Digital pin for communications | ||
#define DHT_SAMPLE_INTERVAL 2000 // Sample every two seconds | ||
|
||
//declaration | ||
void dht_wrapper(); // must be declared before the lib initialization | ||
|
||
// Lib instantiate | ||
PietteTech_DHT DHT(DHTPIN, DHTTYPE, dht_wrapper); | ||
int n; // counter | ||
|
||
// globals | ||
unsigned int DHTnextSampleTime; // Next time we want to start sample | ||
bool bDHTstarted; // flag to indicate we started acquisition | ||
int n; // counter | ||
|
||
void setup() | ||
{ | ||
|
@@ -36,8 +45,11 @@ void setup() | |
Serial.print("LIB version: "); | ||
Serial.println(DHTLIB_VERSION); | ||
Serial.println("---------------"); | ||
|
||
DHTnextSampleTime = 0; // Start the first sample immediately | ||
} | ||
|
||
|
||
// This wrapper is in charge of calling | ||
// mus be defined like this for the lib work | ||
void dht_wrapper() { | ||
|
@@ -46,64 +58,73 @@ void dht_wrapper() { | |
|
||
void loop() | ||
{ | ||
Serial.print("\n"); | ||
Serial.print(n); | ||
Serial.print(": Retrieving information from sensor: "); | ||
Serial.print("Read sensor: "); | ||
//delay(100); | ||
|
||
DHT.acquire(); | ||
while (DHT.acquiring()) ; | ||
|
||
int result = DHT.getStatus(); | ||
|
||
switch (result) { | ||
case DHTLIB_OK: | ||
Serial.println("OK"); | ||
break; | ||
case DHTLIB_ERROR_CHECKSUM: | ||
Serial.println("Error\n\r\tChecksum error"); | ||
break; | ||
case DHTLIB_ERROR_ISR_TIMEOUT: | ||
Serial.println("Error\n\r\tISR time out error"); | ||
break; | ||
case DHTLIB_ERROR_RESPONSE_TIMEOUT: | ||
Serial.println("Error\n\r\tResponse time out error"); | ||
break; | ||
case DHTLIB_ERROR_DATA_TIMEOUT: | ||
Serial.println("Error\n\r\tData time out error"); | ||
break; | ||
case DHTLIB_ERROR_ACQUIRING: | ||
Serial.println("Error\n\r\tAcquiring"); | ||
break; | ||
case DHTLIB_ERROR_DELTA: | ||
Serial.println("Error\n\r\tDelta time to small"); | ||
break; | ||
case DHTLIB_ERROR_NOTSTARTED: | ||
Serial.println("Error\n\r\tNot started"); | ||
break; | ||
default: | ||
Serial.println("Unknown error"); | ||
break; | ||
// Check if we need to start the next sample | ||
if (millis() > DHTnextSampleTime) { | ||
if (!bDHTstarted) { // start the sample | ||
Serial.print("\n"); | ||
Serial.print(n); | ||
Serial.print(": Retrieving information from sensor: "); | ||
DHT.acquire(); | ||
bDHTstarted = true; | ||
} | ||
|
||
if (!DHT.acquiring()) { // has sample completed? | ||
|
||
// get DHT status | ||
int result = DHT.getStatus(); | ||
|
||
Serial.print("Read sensor: "); | ||
switch (result) { | ||
case DHTLIB_OK: | ||
Serial.println("OK"); | ||
break; | ||
case DHTLIB_ERROR_CHECKSUM: | ||
Serial.println("Error\n\r\tChecksum error"); | ||
break; | ||
case DHTLIB_ERROR_ISR_TIMEOUT: | ||
Serial.println("Error\n\r\tISR time out error"); | ||
break; | ||
case DHTLIB_ERROR_RESPONSE_TIMEOUT: | ||
Serial.println("Error\n\r\tResponse time out error"); | ||
break; | ||
case DHTLIB_ERROR_DATA_TIMEOUT: | ||
Serial.println("Error\n\r\tData time out error"); | ||
break; | ||
case DHTLIB_ERROR_ACQUIRING: | ||
Serial.println("Error\n\r\tAcquiring"); | ||
break; | ||
case DHTLIB_ERROR_DELTA: | ||
Serial.println("Error\n\r\tDelta time to small"); | ||
break; | ||
case DHTLIB_ERROR_NOTSTARTED: | ||
Serial.println("Error\n\r\tNot started"); | ||
break; | ||
default: | ||
Serial.println("Unknown error"); | ||
break; | ||
} | ||
|
||
Serial.print("Humidity (%): "); | ||
Serial.println(DHT.getHumidity(), 2); | ||
|
||
Serial.print("Temperature (oC): "); | ||
Serial.println(DHT.getCelsius(), 2); | ||
|
||
Serial.print("Temperature (oF): "); | ||
Serial.println(DHT.getFahrenheit(), 2); | ||
|
||
Serial.print("Temperature (K): "); | ||
Serial.println(DHT.getKelvin(), 2); | ||
|
||
Serial.print("Dew Point (oC): "); | ||
Serial.println(DHT.getDewPoint()); | ||
|
||
Serial.print("Dew Point Slow (oC): "); | ||
Serial.println(DHT.getDewPointSlow()); | ||
|
||
n++; // increment counter | ||
bDHTstarted = false; // reset the sample flag so we can take another | ||
DHTnextSampleTime = millis() + DHT_SAMPLE_INTERVAL; // set the time for next sample | ||
} | ||
} | ||
Serial.print("Humidity (%): "); | ||
Serial.println(DHT.getHumidity(), 2); | ||
|
||
Serial.print("Temperature (oC): "); | ||
Serial.println(DHT.getCelsius(), 2); | ||
|
||
Serial.print("Temperature (oF): "); | ||
Serial.println(DHT.getFahrenheit(), 2); | ||
|
||
Serial.print("Temperature (K): "); | ||
Serial.println(DHT.getKelvin(), 2); | ||
|
||
Serial.print("Dew Point (oC): "); | ||
Serial.println(DHT.getDewPoint()); | ||
|
||
Serial.print("Dew Point Slow (oC): "); | ||
Serial.println(DHT.getDewPointSlow()); | ||
|
||
n++; | ||
delay(2500); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,6 +1,6 @@ | ||
{ | ||
"name": "PietteTech_DHT", | ||
"version": "0.0.2", | ||
"version": "0.0.3", | ||
"author": "Scott Piette [email protected]", | ||
"license": "GPL v3 (http://www.gnu.org/licenses/gpl.html)", | ||
"description": "Interrupt driven DHT11/21/22 Sensor library" | ||
|