{"id":24701611,"url":"https://github.com/fernandorpardo/dht22_esp-idf","last_synced_at":"2026-05-20T10:11:00.278Z","repository":{"id":272587922,"uuid":"917099491","full_name":"fernandorpardo/DHT22_ESP-IDF","owner":"fernandorpardo","description":"DHT22 temperature \u0026 humidity sensor driver for ESP-IDF","archived":false,"fork":false,"pushed_at":"2025-02-09T08:43:49.000Z","size":33,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-22T04:12:45.802Z","etag":null,"topics":["dht22","esp-idf","esp32","freertos"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"apache-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/fernandorpardo.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-01-15T10:59:01.000Z","updated_at":"2025-02-09T08:43:52.000Z","dependencies_parsed_at":"2025-01-17T01:15:23.637Z","dependency_job_id":null,"html_url":"https://github.com/fernandorpardo/DHT22_ESP-IDF","commit_stats":null,"previous_names":["fernandorpardo/dht22_esp-idf"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fernandorpardo%2FDHT22_ESP-IDF","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fernandorpardo%2FDHT22_ESP-IDF/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fernandorpardo%2FDHT22_ESP-IDF/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/fernandorpardo%2FDHT22_ESP-IDF/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/fernandorpardo","download_url":"https://codeload.github.com/fernandorpardo/DHT22_ESP-IDF/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":244902925,"owners_count":20529115,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["dht22","esp-idf","esp32","freertos"],"created_at":"2025-01-27T05:24:57.219Z","updated_at":"2026-05-20T10:11:00.192Z","avatar_url":"https://github.com/fernandorpardo.png","language":"C","funding_links":[],"categories":[],"sub_categories":[],"readme":"# DHT22 FreeRTOS driver for ESP-IDF\n[![Apache-2.0 license](https://img.shields.io/badge/License-Apache_2.0-green.svg?style=flat-square)](https://www.apache.org/licenses/LICENSE-2.0)\n[![ESP32](https://img.shields.io/badge/ESP-32-green.svg?style=flat-square)](https://www.espressif.com/en/products/socs/esp32)\n\nThis is a FreeRTOS DHT22 temperature \u0026 humidity sensor driver for ESP IDF.\n\nIt works with interruptions instead of active waiting and relays on \nthe [\"ESP Timer\"](https://docs.espressif.com/projects/esp-idf/en/stable/esp32/api-reference/system/esp_timer.html) API for microseconds time measurement.\n\n## Environment\nThe DHT22 device is powered with 3.3v and the DATA pin is wired to ESP32's GPIO 25 in the code delivered here.\n\nGPIO is configured as open-drain for input \u0026 output with a 1k Ohm pull-up to 3.3v.\n\nThe code has been generated using **ESP-IDF v5.4-dev-2194-gd7ca8b94c8** for Linux running on a Raspberry Pi.\n\nThe code was developed and tested on a ESP-WROOM-32.\n\n## Description\nThe driver provides 2 functions.\n\n**void DHTinit(gpio_num_t gpio_num)**\nis the initialization function that needs to be called once. It takes the GPIO number of choice as parameter and configures the GPIO as open drain for input \u0026 output (GPIO_MODE_INPUT_OUTPUT_OD), enables the pin for interruptions on falling edge (GPIO_INTR_NEGEDGE), enables the interruption handler function (ISR), and starts the ESP timer.\n\n**int DHTget(uint16_t\\* temperature, uint16_t\\* humidity)**\nis meant to be called anytime to get DHT's measurements. The function returns after approximately 20ms which is the time it takes the DHT to respond and transmit the data. The function is preemptive, that is, it is not blocking other tasks during its execution.\n\nWhen DHTget is called the ESP drives the GPIO as output to generate the start signal (it pulls the GPIO low and then up back).\n\n```\n          500us         20-40us   \n ___               _______________ - - - -\n    \\             /    \n     \\___________/                 \n```\n \nAfter the start signal the ESP32 releases the wire and it is the turn of the DHT22 to drive it to send back the response. \n\nThe DHT generates 41 down+up cycles.\n\nThe first down+up cycle means \"ready to output\" and is followed by 40 pulses meaning data 0 or 1.\n\nData 0 or 1 is discriminated by the duration of the up pulse. Up time for data 0 is 26-28us and up time for data 1 is around 70us.\n\n```\ndata 0 bit\n                         26-28us   \n                   ____________\n    \\             /    \n     \\___________/                 \n\ndata 1 bit\n                              70us   \n                   ______________________ \n    \\             /    \n     \\___________/    \n```\nThe driver takes the duration of the down+up, that is, the time between two consecutive falling edges, to decide between 0 and 1.\n\nThe interrupt routine (ISR) is limited to counting cycles and recording the time between falling edges.\n\nThe recorded down+up cycles are converted into bits. The post processing outcome is 5 bytes. The first two bytes are for the humidity and the second two is the temperature. The fifth byte is the checksum.\n\n\n\n## Build\nFollow the regular process to generate and flash the code as described in the ESP IDF instructions [\"Configure Your Projec\"](https://docs.espressif.com/projects/esp-idf/en/latest/esp32/get-started/linux-macos-setup.html#configure-your-project)\n\nRun ESP-IDF script to make the tools usable from the command line and set the necessary environment variables.\n```console\n. $HOME/esp/esp-idf/export.sh\n```\nGo to your project directory, e.g.\n```console\ncd ~/esp/DHT22\n```\nSelect your target\n```console\nidf.py set-target esp32\n```\nYou can skip the menuconfig for the are no project specific variables to set up\n```console\nidf.py menuconfig\n```\nCompile and generate the code\n```console\nidf.py build\n```\nExecute (choose the right port for your enviroment)\n```console\nidf.py -p /dev/ttyUSB1 flash monitor\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffernandorpardo%2Fdht22_esp-idf","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Ffernandorpardo%2Fdht22_esp-idf","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Ffernandorpardo%2Fdht22_esp-idf/lists"}