Skip to content

infincia/dht_espidf

master
Switch branches/tags

Name already in use

A tag already exists with the provided branch name. Many Git commands accept both tag and branch names, so creating this branch may cause unexpected behavior. Are you sure you want to create this branch?
Code

Latest commit

 

Git stats

Files

Permalink
Failed to load latest commit information.
Type
Name
Latest commit message
Commit time
 
 
src
 
 
 
 
 
 
 
 
 
 

dht_espidf

An ESP-IDF component for the DHT11/22 humidity and temperature sensor family.

Derived from the NodeMCU firmware driver for DHT11/22 sensors.

Installation

ESP-IDF build system

Clone this repository into your components directory inside the project:

cd components
git clone https://github.com/infincia/dht_espidf.git

PlatformIO

Add this repository as a library in your platformio.ini file in the root of your project:

[env:development]
platform = espressif32
board = esp32dev
framework = espidf
lib_deps =
  https://github.com/infincia/dht_espidf.git#v0.1.0

Full example of usage

This is a bare minimum main.cpp file you can refer to when using this library.

#include <esp_err.h>
#include <esp_log.h>
static const char *TAG = "[MyProject]";

#include <dht_espidf.h>

#define DHT_IO 27


extern "C" {
void app_main();
}

int app_main() {

    struct dht_reading dht_data{};

    dht_result_t res = read_dht_sensor_data((gpio_num_t)DHT_IO, DHT11, &dht_data);

    if (res != DHT_OK) {
        ESP_LOGW(TAG, "DHT sensor reading failed");
    } else {
        double fahrenheit = (dht_data.temperature * 1.8f) + 32.0f;
        double humidity = dht_data.humidity;
        ESP_LOGI(TAG, "DHT sensor reading: %f° / %f", fahrenheit, humidity);
    }

    return 0;
}

About

An ESP IDF component for the DHT11/22 humidity and temperature sensor family.

Resources

License

Stars

Watchers

Forks

Packages

No packages published