first commit
This commit is contained in:
commit
e6a42e28e9
4355 changed files with 4626605 additions and 0 deletions
97
libraries/DHT20/examples/DHT20/DHT20.ino
Normal file
97
libraries/DHT20/examples/DHT20/DHT20.ino
Normal file
|
|
@ -0,0 +1,97 @@
|
|||
//
|
||||
// FILE: DHT20.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: Demo for DHT20 I2C humidity & temperature sensor
|
||||
// URL: https://github.com/RobTillaart/DHT20
|
||||
//
|
||||
// Always check datasheet - front view
|
||||
//
|
||||
// +--------------+
|
||||
// VDD ----| 1 |
|
||||
// SDA ----| 2 DHT20 |
|
||||
// GND ----| 3 |
|
||||
// SCL ----| 4 |
|
||||
// +--------------+
|
||||
|
||||
|
||||
#include "DHT20.h"
|
||||
|
||||
DHT20 DHT;
|
||||
|
||||
uint8_t count = 0;
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("DHT20 LIBRARY VERSION: ");
|
||||
Serial.println(DHT20_LIB_VERSION);
|
||||
Serial.println();
|
||||
|
||||
Wire.begin();
|
||||
DHT.begin(); // ESP32 default pins 21 22
|
||||
|
||||
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (millis() - DHT.lastRead() >= 1000)
|
||||
{
|
||||
// READ DATA
|
||||
uint32_t start = micros();
|
||||
int status = DHT.read();
|
||||
uint32_t stop = micros();
|
||||
|
||||
if ((count % 10) == 0)
|
||||
{
|
||||
count = 0;
|
||||
Serial.println();
|
||||
Serial.println("Type\tHumidity (%)\tTemp (°C)\tTime (µs)\tStatus");
|
||||
}
|
||||
count++;
|
||||
|
||||
Serial.print("DHT20 \t");
|
||||
// DISPLAY DATA, sensor has only one decimal.
|
||||
Serial.print(DHT.getHumidity(), 1);
|
||||
Serial.print("\t\t");
|
||||
Serial.print(DHT.getTemperature(), 1);
|
||||
Serial.print("\t\t");
|
||||
Serial.print(stop - start);
|
||||
Serial.print("\t\t");
|
||||
switch (status)
|
||||
{
|
||||
case DHT20_OK:
|
||||
Serial.print("OK");
|
||||
break;
|
||||
case DHT20_ERROR_CHECKSUM:
|
||||
Serial.print("Checksum error");
|
||||
break;
|
||||
case DHT20_ERROR_CONNECT:
|
||||
Serial.print("Connect error");
|
||||
break;
|
||||
case DHT20_MISSING_BYTES:
|
||||
Serial.print("Missing bytes");
|
||||
break;
|
||||
case DHT20_ERROR_BYTES_ALL_ZERO:
|
||||
Serial.print("All bytes read zero");
|
||||
break;
|
||||
case DHT20_ERROR_READ_TIMEOUT:
|
||||
Serial.print("Read time out");
|
||||
break;
|
||||
case DHT20_ERROR_LASTREAD:
|
||||
Serial.print("Error read too fast");
|
||||
break;
|
||||
default:
|
||||
Serial.print("Unknown error");
|
||||
break;
|
||||
}
|
||||
Serial.print("\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
17
libraries/DHT20/examples/DHT20/performance_0.1.2.txt
Normal file
17
libraries/DHT20/examples/DHT20/performance_0.1.2.txt
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
...Arduino\libraries\DHT20\examples\DHT20\DHT20.ino
|
||||
DHT20 LIBRARY VERSION: 0.1.2
|
||||
|
||||
IDE 1.8.19
|
||||
Arduino UNO
|
||||
|
||||
Type Humidity (%) Temp (°C) Time (µs) Status
|
||||
DHT20 70.8 21.4 86701 OK
|
||||
DHT20 71.7 21.4 86702 OK
|
||||
DHT20 69.2 21.4 86701 OK
|
||||
DHT20 66.4 21.4 86702 OK
|
||||
DHT20 64.4 21.4 86701 OK
|
||||
DHT20 62.8 21.4 86701 OK
|
||||
DHT20 61.7 21.4 86702 OK
|
||||
DHT20 60.7 21.4 86701 OK
|
||||
DHT20 60.1 21.4 86702 OK
|
||||
DHT20 59.6 21.4 86702 OK
|
||||
17
libraries/DHT20/examples/DHT20/performance_0.1.3.txt
Normal file
17
libraries/DHT20/examples/DHT20/performance_0.1.3.txt
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
...Arduino\libraries\DHT20\examples\DHT20\DHT20.ino
|
||||
DHT20 LIBRARY VERSION: 0.1.3
|
||||
|
||||
IDE 1.8.19
|
||||
Arduino UNO
|
||||
|
||||
Type Humidity (%) Temp (°C) Time (µs) Status
|
||||
DHT20 61.4 21.5 54684 OK
|
||||
DHT20 61.4 21.5 54692 OK
|
||||
DHT20 61.4 21.5 54692 OK
|
||||
DHT20 61.4 21.5 54688 OK
|
||||
DHT20 61.4 21.5 54704 OK
|
||||
DHT20 61.4 21.5 54692 OK
|
||||
DHT20 61.4 21.5 54692 OK
|
||||
DHT20 61.4 21.5 46496 OK
|
||||
DHT20 69.7 22.2 46492 OK
|
||||
DHT20 79.9 22.3 54688 OK
|
||||
18
libraries/DHT20/examples/DHT20/performance_0.1.4.txt
Normal file
18
libraries/DHT20/examples/DHT20/performance_0.1.4.txt
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
...Arduino\libraries\DHT20\examples\DHT20\DHT20.ino
|
||||
DHT20 LIBRARY VERSION: 0.1.4
|
||||
|
||||
IDE 1.8.19
|
||||
Arduino UNO
|
||||
|
||||
Type Humidity (%) Temp (°C) Time (µs) Status
|
||||
DHT20 56.6 21.7 44136 OK
|
||||
DHT20 56.6 21.7 44136 OK
|
||||
DHT20 56.7 21.7 44144 OK
|
||||
DHT20 57.0 21.7 44140 OK
|
||||
DHT20 57.4 21.7 44136 OK
|
||||
DHT20 57.7 21.7 44140 OK
|
||||
DHT20 58.1 21.7 44148 OK
|
||||
DHT20 58.5 21.7 44140 OK
|
||||
DHT20 58.7 21.7 44132 OK
|
||||
DHT20 59.2 21.8 44140 OK
|
||||
|
||||
18
libraries/DHT20/examples/DHT20/performance_0.2.0.txt
Normal file
18
libraries/DHT20/examples/DHT20/performance_0.2.0.txt
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
...Arduino\libraries\DHT20\examples\DHT20\DHT20.ino
|
||||
DHT20 LIBRARY VERSION: 0.2.0
|
||||
|
||||
IDE 1.8.19
|
||||
Arduino UNO
|
||||
|
||||
Type Humidity (%) Temp (°C) Time (µs) Status
|
||||
DHT20 76.2 19.2 45964 OK
|
||||
DHT20 76.1 19.2 45960 OK
|
||||
DHT20 75.8 19.2 45956 OK
|
||||
DHT20 75.6 19.2 45952 OK
|
||||
DHT20 75.4 19.2 45972 OK
|
||||
DHT20 75.2 19.2 45976 OK
|
||||
DHT20 75.1 19.2 45964 OK
|
||||
DHT20 74.9 19.2 45960 OK
|
||||
DHT20 74.8 19.2 45956 OK
|
||||
DHT20 74.6 19.2 45960 OK
|
||||
|
||||
104
libraries/DHT20/examples/DHT20_I2C_speed/DHT20_I2C_speed.ino
Normal file
104
libraries/DHT20/examples/DHT20_I2C_speed/DHT20_I2C_speed.ino
Normal file
|
|
@ -0,0 +1,104 @@
|
|||
//
|
||||
// FILE: DHT20_I2C_speed.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: Demo for DHT20 I2C humidity & temperature sensor
|
||||
// URL: https://github.com/RobTillaart/DHT20
|
||||
//
|
||||
// Always check datasheet - front view
|
||||
//
|
||||
// +--------------+
|
||||
// VDD ----| 1 |
|
||||
// SDA ----| 2 DHT20 |
|
||||
// GND ----| 3 |
|
||||
// SCL ----| 4 |
|
||||
// +--------------+
|
||||
|
||||
// NOTE datasheet states 400 KHz as maximum
|
||||
|
||||
|
||||
#include "DHT20.h"
|
||||
|
||||
DHT20 DHT;
|
||||
|
||||
uint32_t start, stop;
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("DHT20 LIBRARY VERSION: ");
|
||||
Serial.println(DHT20_LIB_VERSION);
|
||||
Serial.println();
|
||||
|
||||
Serial.println("\nNOTE: datasheet states 400 KHz as maximum.\n");
|
||||
|
||||
Wire.begin();
|
||||
DHT.begin(); // ESP32 default pins 21, 22
|
||||
delay(2000);
|
||||
|
||||
for (uint32_t speed = 50000; speed < 850000; speed += 50000)
|
||||
{
|
||||
Wire.setClock(speed);
|
||||
Serial.print(speed);
|
||||
Serial.print("\t");
|
||||
Serial.print(DHT.read()); // status
|
||||
Serial.print("\t");
|
||||
Serial.print(DHT.getHumidity(), 1);
|
||||
Serial.print("\t");
|
||||
Serial.print(DHT.getTemperature(), 1);
|
||||
Serial.println();
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
Serial.println();
|
||||
for (uint32_t speed = 50000; speed < 850000; speed += 50000)
|
||||
{
|
||||
Wire.setClock(speed);
|
||||
start = micros();
|
||||
DHT.read();
|
||||
stop = micros();
|
||||
|
||||
Serial.print(speed);
|
||||
Serial.print("\t");
|
||||
Serial.print(stop - start); // time
|
||||
Serial.print("\t");
|
||||
Serial.print(DHT.getHumidity(), 1);
|
||||
Serial.print("\t");
|
||||
Serial.print(DHT.getTemperature(), 1);
|
||||
Serial.println();
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
|
||||
Serial.println();
|
||||
for (uint32_t speed = 50000; speed < 850000; speed += 50000)
|
||||
{
|
||||
DHT.requestData();
|
||||
while (DHT.isMeasuring());
|
||||
Wire.setClock(speed);
|
||||
start = micros();
|
||||
DHT.readData();
|
||||
stop = micros();
|
||||
DHT.convert();
|
||||
Serial.print(speed);
|
||||
Serial.print("\t");
|
||||
Serial.print(stop - start); // time
|
||||
Serial.print("\t");
|
||||
Serial.print(DHT.getHumidity(), 1);
|
||||
Serial.print("\t");
|
||||
Serial.print(DHT.getTemperature(), 1);
|
||||
Serial.println();
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
Serial.println("\ndone...");
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
|
@ -0,0 +1,61 @@
|
|||
Board: UNO
|
||||
IDE: 1.8.19
|
||||
|
||||
DHT20_I2C_speed.ino
|
||||
DHT20 LIBRARY VERSION: 0.2.2
|
||||
|
||||
|
||||
NOTE: datasheet states 400 KHz as maximum.
|
||||
|
||||
50000 0 48.7 17.3
|
||||
100000 0 48.7 17.3
|
||||
150000 0 48.7 17.3
|
||||
200000 0 48.6 17.3
|
||||
250000 0 48.6 17.3
|
||||
300000 0 48.6 17.3
|
||||
350000 0 48.6 17.3
|
||||
400000 0 48.6 17.3
|
||||
450000 0 48.6 17.3
|
||||
500000 0 48.6 17.3
|
||||
550000 0 48.6 17.3
|
||||
600000 0 48.6 17.3
|
||||
650000 0 48.6 17.3
|
||||
700000 0 48.6 17.3
|
||||
750000 0 48.6 17.3
|
||||
800000 0 48.6 17.3
|
||||
|
||||
50000 46916 48.6 17.4
|
||||
100000 44600 48.6 17.4
|
||||
150000 44264 48.6 17.3
|
||||
200000 43996 48.6 17.3
|
||||
250000 44308 48.6 17.3
|
||||
300000 43624 48.6 17.3
|
||||
350000 44248 48.6 17.3
|
||||
400000 44040 48.6 17.3
|
||||
450000 43724 48.5 17.4
|
||||
500000 43612 48.6 17.3
|
||||
550000 43388 48.6 17.4
|
||||
600000 43204 48.6 17.4
|
||||
650000 44200 48.6 17.3
|
||||
700000 44108 48.6 17.4
|
||||
750000 43984 48.6 17.4
|
||||
800000 43984 48.5 17.4
|
||||
|
||||
50000 1576 48.6 17.3
|
||||
100000 836 48.6 17.4
|
||||
150000 588 48.5 17.3
|
||||
200000 472 48.6 17.4
|
||||
250000 400 48.5 17.3
|
||||
300000 336 48.6 17.4
|
||||
350000 296 48.6 17.4
|
||||
400000 284 48.6 17.3
|
||||
450000 252 48.6 17.4
|
||||
500000 244 48.6 17.3
|
||||
550000 228 48.6 17.4
|
||||
600000 216 48.6 17.3
|
||||
650000 204 48.6 17.3
|
||||
700000 200 48.5 17.4
|
||||
750000 188 48.6 17.4
|
||||
800000 188 48.6 17.4
|
||||
|
||||
done...
|
||||
69
libraries/DHT20/examples/DHT20_async/DHT20_async.ino
Normal file
69
libraries/DHT20/examples/DHT20_async/DHT20_async.ino
Normal file
|
|
@ -0,0 +1,69 @@
|
|||
//
|
||||
// FILE: DHT20_async.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: Demo for DHT20 I2C humidity & temperature sensor
|
||||
// URL: https://github.com/RobTillaart/DHT20
|
||||
//
|
||||
// Always check datasheet - front view
|
||||
//
|
||||
// +--------------+
|
||||
// VDD ----| 1 |
|
||||
// SDA ----| 2 DHT20 |
|
||||
// GND ----| 3 |
|
||||
// SCL ----| 4 |
|
||||
// +--------------+
|
||||
|
||||
|
||||
#include "DHT20.h"
|
||||
|
||||
DHT20 DHT;
|
||||
|
||||
uint32_t counter = 0;
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("DHT20 LIBRARY VERSION: ");
|
||||
Serial.println(DHT20_LIB_VERSION);
|
||||
Serial.println();
|
||||
|
||||
Wire.begin();
|
||||
Wire.setClock(400000);
|
||||
|
||||
DHT.begin(); // ESP32 default 21, 22
|
||||
|
||||
delay(2000);
|
||||
|
||||
// start with initial request
|
||||
Serial.println(DHT.requestData());
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
uint32_t now = millis();
|
||||
|
||||
if (now - DHT.lastRead() > 1000)
|
||||
{
|
||||
DHT.readData();
|
||||
DHT.convert();
|
||||
|
||||
Serial.print(DHT.getHumidity(), 1);
|
||||
Serial.print(" %RH \t");
|
||||
Serial.print(DHT.getTemperature(), 1);
|
||||
Serial.print(" °C\t");
|
||||
Serial.print(counter);
|
||||
Serial.print("\n");
|
||||
// new request
|
||||
counter = 0;
|
||||
DHT.requestData();
|
||||
}
|
||||
|
||||
// other code here
|
||||
counter++; // dummy counter to show async behaviour
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
174
libraries/DHT20/examples/DHT20_lcd/DHT20_lcd.ino
Normal file
174
libraries/DHT20/examples/DHT20_lcd/DHT20_lcd.ino
Normal file
|
|
@ -0,0 +1,174 @@
|
|||
//
|
||||
// FILE: DHT20_lcd.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: Demo for DHT20 I2C humidity & temperature sensor
|
||||
// URL: https://github.com/RobTillaart/DHT20
|
||||
//
|
||||
// Always check datasheet - front view
|
||||
//
|
||||
// +--------------+
|
||||
// VDD ----| 1 |
|
||||
// SDA ----| 2 DHT20 |
|
||||
// GND ----| 3 |
|
||||
// SCL ----| 4 |
|
||||
// +--------------+
|
||||
|
||||
|
||||
#include "DHT20.h"
|
||||
|
||||
DHT20 DHT;
|
||||
|
||||
uint8_t count = 0;
|
||||
|
||||
uint32_t stop, start;
|
||||
|
||||
|
||||
///////////////////////////////////////////////////////////////////////////
|
||||
|
||||
#include <Wire.h>
|
||||
#include <LCD.h>
|
||||
#include <LiquidCrystal_I2C.h>
|
||||
|
||||
#define BACKLIGHT_PIN 3
|
||||
#define En_pin 2
|
||||
#define Rw_pin 1
|
||||
#define Rs_pin 0
|
||||
#define D4_pin 4
|
||||
#define D5_pin 5
|
||||
#define D6_pin 6
|
||||
#define D7_pin 7
|
||||
|
||||
#define BL_OFF 0
|
||||
#define BL_ON 1
|
||||
|
||||
/*
|
||||
#define BACKLIGHT_PIN 7
|
||||
#define En_pin 4
|
||||
#define Rw_pin 5
|
||||
#define Rs_pin 6
|
||||
#define D4_pin 0
|
||||
#define D5_pin 1
|
||||
#define D6_pin 2
|
||||
#define D7_pin 3
|
||||
|
||||
#define LED_OFF 0
|
||||
#define LED_ON 1
|
||||
*/
|
||||
|
||||
int displayAddress = 0x27;
|
||||
|
||||
// LCD object is created as a placeholder as the actual address is determined in setupDisplay()
|
||||
// constructor needs an I2C address. Better solution would be a function to set the address
|
||||
// runtime in the class.
|
||||
LiquidCrystal_I2C lcd(displayAddress);
|
||||
|
||||
void setupDisplay()
|
||||
{
|
||||
lcd = LiquidCrystal_I2C(displayAddress, En_pin, Rw_pin, Rs_pin, D4_pin, D5_pin, D6_pin, D7_pin);
|
||||
lcd.begin(20, 4);
|
||||
// lcd.setBacklightPin(BACKLIGHT_PIN, NEGATIVE);
|
||||
lcd.setBacklightPin(BACKLIGHT_PIN, POSITIVE);
|
||||
lcd.setBacklight(BL_ON);
|
||||
}
|
||||
|
||||
|
||||
void display()
|
||||
{
|
||||
lcd.clear();
|
||||
lcd.setCursor(0, 0);
|
||||
lcd.print("TEMP:");
|
||||
lcd.setCursor(6, 0);
|
||||
lcd.print(DHT.getTemperature());
|
||||
|
||||
lcd.setCursor(0, 1);
|
||||
lcd.print("HUM:");
|
||||
lcd.setCursor(6, 1);
|
||||
lcd.print(DHT.getHumidity());
|
||||
|
||||
lcd.setCursor(0, 3);
|
||||
lcd.print("TIME:");
|
||||
lcd.setCursor(6, 3);
|
||||
lcd.print(stop - start);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("DHT20 LIBRARY VERSION: ");
|
||||
Serial.println(DHT20_LIB_VERSION);
|
||||
Serial.println();
|
||||
|
||||
Wire.begin();
|
||||
DHT.begin(); // ESP32 default pins 21 22
|
||||
|
||||
setupDisplay();
|
||||
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (millis() - DHT.lastRead() >= 1000)
|
||||
{
|
||||
// READ DATA
|
||||
start = micros();
|
||||
int status = DHT.read();
|
||||
stop = micros();
|
||||
|
||||
display();
|
||||
|
||||
if ((count % 10) == 0)
|
||||
{
|
||||
count = 0;
|
||||
Serial.println();
|
||||
Serial.println("Type\tHumidity (%)\tTemp (°C)\tTime (µs)\tStatus");
|
||||
}
|
||||
count++;
|
||||
|
||||
Serial.print("DHT20 \t");
|
||||
// DISPLAY DATA, sensor has only one decimal.
|
||||
Serial.print(DHT.getHumidity(), 1);
|
||||
Serial.print("\t\t");
|
||||
Serial.print(DHT.getTemperature(), 1);
|
||||
Serial.print("\t\t");
|
||||
Serial.print(stop - start);
|
||||
Serial.print("\t\t");
|
||||
switch (status)
|
||||
{
|
||||
case DHT20_OK:
|
||||
Serial.print("OK");
|
||||
break;
|
||||
case DHT20_ERROR_CHECKSUM:
|
||||
Serial.print("Checksum error");
|
||||
break;
|
||||
case DHT20_ERROR_CONNECT:
|
||||
Serial.print("Connect error");
|
||||
break;
|
||||
case DHT20_MISSING_BYTES:
|
||||
Serial.print("Missing bytes");
|
||||
break;
|
||||
case DHT20_ERROR_BYTES_ALL_ZERO:
|
||||
Serial.print("All bytes read zero");
|
||||
break;
|
||||
case DHT20_ERROR_READ_TIMEOUT:
|
||||
Serial.print("Read time out");
|
||||
break;
|
||||
case DHT20_ERROR_LASTREAD:
|
||||
Serial.print("Error read too fast");
|
||||
break;
|
||||
default:
|
||||
Serial.print("Unknown error");
|
||||
break;
|
||||
}
|
||||
Serial.print("\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
109
libraries/DHT20/examples/DHT20_offset/DHT20_offset.ino
Normal file
109
libraries/DHT20/examples/DHT20_offset/DHT20_offset.ino
Normal file
|
|
@ -0,0 +1,109 @@
|
|||
//
|
||||
// FILE: DHT20_offset.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: Demo for DHT20 I2C humidity & temperature sensor
|
||||
// URL: https://github.com/RobTillaart/DHT20
|
||||
//
|
||||
// Always check datasheet - front view
|
||||
//
|
||||
// +--------------+
|
||||
// VDD ----| 1 |
|
||||
// SDA ----| 2 DHT20 |
|
||||
// GND ----| 3 |
|
||||
// SCL ----| 4 |
|
||||
// +--------------+
|
||||
|
||||
|
||||
#include "DHT20.h"
|
||||
|
||||
DHT20 DHT;
|
||||
|
||||
uint8_t count = 0;
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("DHT20 LIBRARY VERSION: ");
|
||||
Serial.println(DHT20_LIB_VERSION);
|
||||
Serial.println();
|
||||
|
||||
Wire.begin();
|
||||
Wire.setClock(400000);
|
||||
|
||||
DHT.begin(); // ESP32 default pins 21 22
|
||||
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
// set an offset after 10 seconds.
|
||||
if (millis() > 10000)
|
||||
{
|
||||
DHT.setTempOffset(1.7);
|
||||
DHT.setHumOffset(-2.3);
|
||||
}
|
||||
|
||||
// make a measurement every 2 seconds
|
||||
if (millis() - DHT.lastRead() >= 2000)
|
||||
{
|
||||
// READ DATA
|
||||
uint32_t start = micros();
|
||||
int status = DHT.read();
|
||||
uint32_t stop = micros();
|
||||
|
||||
if ((count % 10) == 0)
|
||||
{
|
||||
count = 0;
|
||||
Serial.println();
|
||||
Serial.println("Type\tHumidity (%)\tTemp (°C)\tTime (µs)\tStatus\tOffset");
|
||||
}
|
||||
count++;
|
||||
|
||||
Serial.print("DHT20 \t");
|
||||
// DISPLAY DATA, sensor has only one decimal.
|
||||
Serial.print(DHT.getHumidity(), 1);
|
||||
Serial.print("\t\t");
|
||||
Serial.print(DHT.getTemperature(), 1);
|
||||
Serial.print("\t\t");
|
||||
Serial.print(stop - start);
|
||||
Serial.print("\t\t");
|
||||
switch (status)
|
||||
{
|
||||
case DHT20_OK:
|
||||
Serial.print("OK");
|
||||
break;
|
||||
case DHT20_ERROR_CHECKSUM:
|
||||
Serial.print("Checksum error");
|
||||
break;
|
||||
case DHT20_ERROR_CONNECT:
|
||||
Serial.print("Connect error");
|
||||
break;
|
||||
case DHT20_MISSING_BYTES:
|
||||
Serial.print("Missing bytes");
|
||||
break;
|
||||
case DHT20_ERROR_BYTES_ALL_ZERO:
|
||||
Serial.print("All bytes read zero");
|
||||
break;
|
||||
case DHT20_ERROR_READ_TIMEOUT:
|
||||
Serial.print("Read time out");
|
||||
break;
|
||||
case DHT20_ERROR_LASTREAD:
|
||||
Serial.print("Error read too fast");
|
||||
break;
|
||||
default:
|
||||
Serial.print("Unknown error");
|
||||
break;
|
||||
}
|
||||
Serial.print("\t");
|
||||
Serial.print(DHT.getHumOffset());
|
||||
Serial.print("\t");
|
||||
Serial.print(DHT.getTempOffset());
|
||||
Serial.print("\n");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
45
libraries/DHT20/examples/DHT20_plotter/DHT20_plotter.ino
Normal file
45
libraries/DHT20/examples/DHT20_plotter/DHT20_plotter.ino
Normal file
|
|
@ -0,0 +1,45 @@
|
|||
//
|
||||
// FILE: DHT20_plotter.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: Demo for DHT20 I2C humidity & temperature sensor
|
||||
// URL: https://github.com/RobTillaart/DHT20
|
||||
//
|
||||
// Always check datasheet - front view
|
||||
//
|
||||
// +--------------+
|
||||
// VDD ----| 1 |
|
||||
// SDA ----| 2 DHT20 |
|
||||
// GND ----| 3 |
|
||||
// SCL ----| 4 |
|
||||
// +--------------+
|
||||
|
||||
|
||||
#include "DHT20.h"
|
||||
|
||||
DHT20 DHT(&Wire);
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Wire.begin();
|
||||
DHT.begin(); // ESP32 default pins 21 22
|
||||
|
||||
Serial.begin(115200);
|
||||
Serial.println("Humidity, Temperature");
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
if (millis() - DHT.lastRead() >= 1000)
|
||||
{
|
||||
// note no error checking
|
||||
DHT.read();
|
||||
Serial.print(DHT.getHumidity(), 1);
|
||||
Serial.print(", ");
|
||||
Serial.println(DHT.getTemperature(), 1);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
|
@ -0,0 +1,49 @@
|
|||
//
|
||||
// FILE: DHT20_read_status.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: Demo for DHT20 I2C humidity & temperature sensor
|
||||
// URL: https://github.com/RobTillaart/DHT20
|
||||
//
|
||||
// Always check datasheet - front view
|
||||
//
|
||||
// +--------------+
|
||||
// VDD ----| 1 |
|
||||
// SDA ----| 2 DHT20 |
|
||||
// GND ----| 3 |
|
||||
// SCL ----| 4 |
|
||||
// +--------------+
|
||||
|
||||
|
||||
#include "DHT20.h"
|
||||
|
||||
DHT20 DHT;
|
||||
|
||||
uint8_t count = 0;
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("DHT20 LIBRARY VERSION: ");
|
||||
Serial.println(DHT20_LIB_VERSION);
|
||||
Serial.println();
|
||||
|
||||
Wire.begin();
|
||||
Wire.setClock(400000);
|
||||
|
||||
DHT.begin(); // ESP32 default pins 21 22
|
||||
|
||||
delay(2000);
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
int status = DHT.readStatus();
|
||||
Serial.println(status);
|
||||
delay(1000);
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
80
libraries/DHT20/examples/DHT20_test_esp/DHT20_test_esp.ino
Normal file
80
libraries/DHT20/examples/DHT20_test_esp/DHT20_test_esp.ino
Normal file
|
|
@ -0,0 +1,80 @@
|
|||
//
|
||||
// FILE: DHT20_test_esp.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: Demo for DHT20 I2C humidity & temperature sensor
|
||||
// URL: https://github.com/RobTillaart/DHT20
|
||||
//
|
||||
// Always check datasheet - front view
|
||||
//
|
||||
// +--------------+
|
||||
// VDD ----| 1 |
|
||||
// SDA ----| 2 DHT20 |
|
||||
// GND ----| 3 |
|
||||
// SCL ----| 4 |
|
||||
// +--------------+
|
||||
|
||||
|
||||
#include "DHT20.h"
|
||||
|
||||
DHT20 DHT(&Wire1); // 2nd I2C interface
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("DHT20 LIBRARY VERSION: ");
|
||||
Serial.println(DHT20_LIB_VERSION);
|
||||
Serial.println();
|
||||
|
||||
Wire1.begin(12, 13); // select your pin numbers here
|
||||
|
||||
delay(2000);
|
||||
|
||||
Serial.println("Type,\tStatus,\tHumidity (%),\tTemperature (C)");
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
// READ DATA
|
||||
Serial.print("DHT20, \t");
|
||||
int status = DHT.read();
|
||||
switch (status)
|
||||
{
|
||||
case DHT20_OK:
|
||||
Serial.print("OK,\t");
|
||||
break;
|
||||
case DHT20_ERROR_CHECKSUM:
|
||||
Serial.print("Checksum error,\t");
|
||||
break;
|
||||
case DHT20_ERROR_CONNECT:
|
||||
Serial.print("Connect error,\t");
|
||||
break;
|
||||
case DHT20_MISSING_BYTES:
|
||||
Serial.print("Missing bytes,\t");
|
||||
break;
|
||||
case DHT20_ERROR_BYTES_ALL_ZERO:
|
||||
Serial.print("All bytes read zero");
|
||||
break;
|
||||
case DHT20_ERROR_READ_TIMEOUT:
|
||||
Serial.print("Read time out");
|
||||
break;
|
||||
case DHT20_ERROR_LASTREAD:
|
||||
Serial.print("Error read too fast");
|
||||
break;
|
||||
default:
|
||||
Serial.print("Unknown error,\t");
|
||||
break;
|
||||
}
|
||||
|
||||
// DISPLAY DATA, sensor has only one decimal.
|
||||
Serial.print(DHT.getHumidity(), 1);
|
||||
Serial.print(",\t");
|
||||
Serial.println(DHT.getTemperature(), 1);
|
||||
|
||||
delay(2000);
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
|
@ -0,0 +1,82 @@
|
|||
//
|
||||
// FILE: DHT20_test_rp2040.ino
|
||||
// AUTHOR: Rob Tillaart
|
||||
// PURPOSE: Demo for DHT20 I2C humidity & temperature sensor
|
||||
// URL: https://github.com/RobTillaart/DHT20
|
||||
//
|
||||
// Always check datasheet - front view
|
||||
//
|
||||
// +--------------+
|
||||
// VDD ----| 1 |
|
||||
// SDA ----| 2 DHT20 |
|
||||
// GND ----| 3 |
|
||||
// SCL ----| 4 |
|
||||
// +--------------+
|
||||
|
||||
|
||||
#include "DHT20.h"
|
||||
|
||||
DHT20 DHT(&Wire); // or use 2nd I2C interface &Wire1
|
||||
|
||||
|
||||
void setup()
|
||||
{
|
||||
Serial.begin(115200);
|
||||
Serial.println(__FILE__);
|
||||
Serial.print("DHT20 LIBRARY VERSION: ");
|
||||
Serial.println(DHT20_LIB_VERSION);
|
||||
Serial.println();
|
||||
|
||||
Wire1.setSDA(12); // select your pin numbers here
|
||||
Wire1.setSCL(13); // select your pin numbers here
|
||||
Wire1.begin();
|
||||
|
||||
delay(2000);
|
||||
|
||||
Serial.println("Type,\tStatus,\tHumidity (%),\tTemperature (C)");
|
||||
}
|
||||
|
||||
|
||||
void loop()
|
||||
{
|
||||
// READ DATA
|
||||
Serial.print("DHT20, \t");
|
||||
int status = DHT.read();
|
||||
switch (status)
|
||||
{
|
||||
case DHT20_OK:
|
||||
Serial.print("OK,\t");
|
||||
break;
|
||||
case DHT20_ERROR_CHECKSUM:
|
||||
Serial.print("Checksum error,\t");
|
||||
break;
|
||||
case DHT20_ERROR_CONNECT:
|
||||
Serial.print("Connect error,\t");
|
||||
break;
|
||||
case DHT20_MISSING_BYTES:
|
||||
Serial.print("Missing bytes,\t");
|
||||
break;
|
||||
case DHT20_ERROR_BYTES_ALL_ZERO:
|
||||
Serial.print("All bytes read zero");
|
||||
break;
|
||||
case DHT20_ERROR_READ_TIMEOUT:
|
||||
Serial.print("Read time out");
|
||||
break;
|
||||
case DHT20_ERROR_LASTREAD:
|
||||
Serial.print("Error read too fast");
|
||||
break;
|
||||
default:
|
||||
Serial.print("Unknown error,\t");
|
||||
break;
|
||||
}
|
||||
|
||||
// DISPLAY DATA, sensor has only one decimal.
|
||||
Serial.print(DHT.getHumidity(), 1);
|
||||
Serial.print(",\t");
|
||||
Serial.println(DHT.getTemperature(), 1);
|
||||
|
||||
delay(2000);
|
||||
}
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
Loading…
Add table
Add a link
Reference in a new issue