https://github.com/hectorta1989/rtos-esp32-temperature-humidity-dht22
This is an ESP32 (esp-idf) library for the DHT22 low cost temperature/humidity sensors.
https://github.com/hectorta1989/rtos-esp32-temperature-humidity-dht22
Last synced: 8 months ago
JSON representation
This is an ESP32 (esp-idf) library for the DHT22 low cost temperature/humidity sensors.
- Host: GitHub
- URL: https://github.com/hectorta1989/rtos-esp32-temperature-humidity-dht22
- Owner: HectorTa1989
- License: mit
- Created: 2021-06-07T23:51:18.000Z (over 4 years ago)
- Default Branch: master
- Last Pushed: 2021-10-27T01:49:04.000Z (almost 4 years ago)
- Last Synced: 2025-01-07T06:47:51.757Z (9 months ago)
- Language: C
- Size: 506 KB
- Stars: 0
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# DHT22 / AM2302 library for ESP32 (ESP-IDF)
This is an ESP32 (esp-idf) library for the DHT22 low cost temperature/humidity sensors.
Code based on Adafruit Industries. Please help to improve this code.
PLEASE KEEP THIS CODE IN LESS THAN 0xFF LINES. EACH LINE MAY CONTAIN ONE BUG !!!
*Running DHT22*
Create folder called DTH22. In this folder run:
```
$ git clone https://github.com/HectorTa1989/RTOS-ESP32-Temperature-Humidity-DHT22$ make menuconfig and make sure to set Component config->LWIP->recv_bufsize
$ make
$ make flash monitor
```**USE**
See DHT_main.c
```C
void DHT_task(void *pvParameter)
{
setDHTgpio( 4 );
printf( "Starting DHT Task\n\n");while(1) {
printf("=== Reading DHT ===\n" );
int ret = readDHT();
errorHandler(ret);printf( "Hum %.1f\n", getHumidity() );
printf( "Tmp %.1f\n", getTemperature() );
// -- wait at least 2 sec before reading again ------------
// The interval of whole process must be beyond 2 seconds !!
vTaskDelay( 3000 / portTICK_RATE_MS );
}
}void app_main()
{
nvs_flash_init();
vTaskDelay( 1000 / portTICK_RATE_MS );
xTaskCreate( &DHT_task, "DHT_task", 2048, NULL, 5, NULL );
}
```**Copy/paste from AM2302/DHT22 Docu:**
DATA: Hum = 16 bits, Temp = 16 Bits, check-sum = 8 Bits
Example: MCU has received 40 bits data from AM2302 as
0000 0010 1000 1100 0000 0001 0101 1111 1110 1110
16 bits RH data + 16 bits T data + check sum1) convert 16 bits RH data from binary system to decimal system, 0000 0010 1000 1100 → 652
Binary system Decimal system: RH=652/10=65.2%RH2) convert 16 bits T data from binary system to decimal system, 0000 0001 0101 1111 → 351
Binary system Decimal system: T=351/10=35.1°CWhen highest bit of temperature is 1, it means the temperature is below 0 degree Celsius.
Example: 1000 0000 0110 0101, T= minus 10.1°C: 16 bits T data3) Check Sum=0000 0010+1000 1100+0000 0001+0101 1111=1110 1110 Check-sum=the last 8 bits of Sum=11101110
Signal & Timings:
The interval of whole process must be beyond 2 seconds.
To request data from DHT:
1) Sent low pulse for > 1~10 ms (MILI SEC)
2) Sent high pulse for > 20~40 us (Micros).
3) When DHT detects the start signal, it will pull low the bus 80us as response signal,
then the DHT pulls up 80us for preparation to send data.
4) When DHT is sending data to MCU, every bit's transmission begin with low-voltage-level that last 50us,
the following high-voltage-level signal's length decide the bit is "1" or "0".
0: 26~28 us
1: 70 us