-
DHT22:
- 温度范围:-40-80°C
- 温度精度:±0.5°C
- 湿度范围:0-100%RH
- 湿度精度:±2-5%RH
- 分辨率:0.1°C / 0.1%RH
-
#define LOG_LOCAL_LEVEL ESP_LOG_VERBOSE #include <stdio.h> #include <freertos/FreeRTOS.h> #include <freertos/task.h> #include "esp_system.h" #include "freertos/event_groups.h" #include "esp_event.h" #include "nvs_flash.h" #include "esp_log.h" #include "driver/gpio.h" #include "DHT.h" // == global defines ============================================= static const char *TAG = "DHT"; int DHTgpio = GPIO_NUM_4; // my default DHT pin = 4 float humidity = 0.; float temperature = 0.; //串口打印的主函数(默认的波特率为115200) void DHT_task(void *pvParameter) { setDHTgpio(GPIO_NUM_4); ESP_LOGI(TAG, "Starting DHT Task\n\n"); while (1) { ESP_LOGI(TAG, "=== Reading DHT ===\n"); int ret = readDHT(); errorHandler(ret); ESP_LOGI(TAG, "Hum: %.1f Tmp: %.1f\n", getHumidity(), getTemperature()); // -- wait at least 2 sec before reading again ------------
DHT22温湿度传感器(Espressif驱动)
最新推荐文章于 2024-11-17 21:17:55 发布