{"id":26524978,"url":"https://github.com/hyper-prog/dht22m","last_synced_at":"2025-09-26T15:50:51.016Z","repository":{"id":282530295,"uuid":"948883122","full_name":"hyper-prog/dht22m","owner":"hyper-prog","description":"Kernel module for reading DHT22 (AM2302) sensors on Raspberry Pi","archived":false,"fork":false,"pushed_at":"2025-03-22T21:05:39.000Z","size":226,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-22T21:35:40.233Z","etag":null,"topics":["am2302","dht22","kernel","kernel-driver","kernel-module","raspberry-pi","sensor","sensors"],"latest_commit_sha":null,"homepage":"","language":"C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-2.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/hyper-prog.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-03-15T07:02:58.000Z","updated_at":"2025-03-22T21:05:42.000Z","dependencies_parsed_at":"2025-03-15T08:34:58.343Z","dependency_job_id":null,"html_url":"https://github.com/hyper-prog/dht22m","commit_stats":null,"previous_names":["hyper-prog/dht22m"],"tags_count":0,"template":false,"template_full_name":null,"purl":"pkg:github/hyper-prog/dht22m","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyper-prog%2Fdht22m","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyper-prog%2Fdht22m/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyper-prog%2Fdht22m/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyper-prog%2Fdht22m/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/hyper-prog","download_url":"https://codeload.github.com/hyper-prog/dht22m/tar.gz/refs/heads/main","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/hyper-prog%2Fdht22m/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":277103474,"owners_count":25761397,"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","status":"online","status_checked_at":"2025-09-26T02:00:09.010Z","response_time":78,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":["am2302","dht22","kernel","kernel-driver","kernel-module","raspberry-pi","sensor","sensors"],"created_at":"2025-03-21T14:40:11.477Z","updated_at":"2025-09-26T15:50:51.011Z","avatar_url":"https://github.com/hyper-prog.png","language":"C","funding_links":["https://www.paypal.com/donate/?business=EM2E9A6BZBK64\u0026no_recurring=0\u0026currency_code=USD"],"categories":[],"sub_categories":[],"readme":"![DHT22M logo](https://raw.githubusercontent.com/hyper-prog/dht22m/master/images/dht22m_logo_s.png)\n\nKernel module for reading DHT22 / AM2302 sensors on Raspberry Pi\n================================================================\n\n_**The most reliable dht22 sensor reader!**_\n\nThis project implements a [Raspberry Pi](https://en.wikipedia.org/wiki/Raspberry_Pi)\n[kernel module](https://en.wikipedia.org/wiki/Loadable_kernel_module)\nfor the DHT22 temperature and humidity sensor.\nThe goal of the driver is to read multiple sensors so that\nthe [GPIOs](https://en.wikipedia.org/wiki/General-purpose_input/output)\ncan be dynamically set without reloading the kernel module.\nThe sensor data can easely read from `/dev/dht22mX` character devices.\nThis kernel module uses [hardware interrupts](https://en.wikipedia.org/wiki/Interrupt#Hardware_interrupts)\nto collect sensor data, which results in much more reliable results (fewer crc errors) than\nuser-mode readers that constantly monitor the status of the gpio.\n\nIntroduction \u0026 Backgrounds\n----------------------------\n\nI was created a project which handle multiple DHT22 sensors.\nMy code collected statistics on the number of successful and failed readings,\nand I found that some cases approximately 20 percent of the readings were erroneous.\nIt is very big amount of error!\n\nInitially, I attempted to improve the user-space reading code,\nbut the DHT22 sensor transmits data using so very short pulses\n(20, 50, and 70 microseconds) which makes very hard to read without loosing a bit.\nAccurately capturing these signals with conventional GPIO polling proved to be unreliable.\nDue to the operation system task switching, interrupts,\nand system load, the number of failed readings remained high.\n\nTo achieve more precise timing and improve reading accuracy,\nI turned to kernel module development. By handling GPIO signal processing at the kernel level,\nthe module ensures much finer timing control,\nsignificantly reducing read errors and enhancing overall reliability.\n\nMy moderately loaded Raspberri Pi with 4 sensor produce the following statistics:\n\nWith user mode reader\n\n![User mode stats](https://raw.githubusercontent.com/hyper-prog/dht22m/master/images/um-stats.png)\n\nWith kernel mode reader\n\n![Kernel mode stats](https://raw.githubusercontent.com/hyper-prog/dht22m/master/images/krnl-stats.png)\n\n_It can be seen that with the traditional user mode reading method the percentage of errors is 5-20%,\nwhile with the dht22m kernel module it is less than 1%. (typically less than 0.1%)_\n\nConfigure sensor GPIOs to read data\n-------------------------------------\n\nYou can send your dht22m sensor GPIOs numbers to as\n[sysfs](https://en.wikipedia.org/wiki/Sysfs) file: `/sys/class/dht22m/gpiolist`\nThe GPIO numbers are separated by spaces. After If success the `/dev/dht22mX`\ndevices will be created in same order as the GPIOs listed in the sysfs file.\n\n    echo \"2 3 22\" \u003e /sys/class/dht22m/gpiolist\n\nYou can always check the GPIOs settings of your dht22 devices\n\n    cat /sys/class/dht22m/gpiolist\n    2 3 22\n\n    ls /dev/dht22*\n    /dev/dht22m0 /dev/dht22m1 /dev/dht22m2\n\n_Note: The kernel module is written in such a way that if a configuration request\nis received matches the running configuration, recognizes the matching and does nothing.\nSo the user programs can safely send the necessary settings at startup, it will not cause kernel overhead._\n\nRead the values\n----------------\n\nYou can read temperature and humidity values by simple read from `/dev/dht22mX` device files.\n\n    cat /dev/dht22m*\n    Ok;19.7;38.2\n    Ok;20.1;42.1\n    Ok;11.7;26.0\n\nThe device files could send the following strings\n\n| Received string             | Possible events / meaning                                       |\n| --------------------------- | --------------------------------------------------------------- |\n| `Ok;TEMPERATURE;HUMIDITY`   | Successful read, with the read values.                          |\n| `ChecksumError`             | Checksum error during the read. Wait 2 sec and read again!      |\n| `ReadTooSoon`               | Read the sensor too quickly. Read later!                        |\n| `IOError`                   | GPIO/Sensor/Other error                                         |\n| `NotRead`                   | Data not read                                                   |\n\nPre-requisites to build the kernel module\n-----------------------------------------\n\nTo build the kernel module, you need to first install the following\npackages:\n\n    sudo apt install build-essential raspberrypi-kernel-headers\n\nOn some [raspbian](https://www.raspberrypi.com/software/) versions, the sources for the running kernel\nmay not be installed from a package.\nIn this case, check the https://github.com/RPi-Distro/rpi-source tool\nwhich downloads the current running raspbery pi kernel for you.\nIf you did so, run the following commands to configure soruces as your running kernel:\n\n    cd /lib/modules/$(uname -r)/build\n    zcat /proc/config.gz \u003e .config\n    make olddefconfig\n    make modules_prepare\n\nBuilding and install the kernel module\n--------------------------------------\n\nClone dht22m sources from github.\nTo compile module enter the dht22m directory and build \u0026 install it.\n\n    git clone https://github.com/hyper-prog/dht22m\n    cd dht22m\n    sudo make\n    sudo make install\n\nIf success, you can load the module:\n\n    sudo modprobe dht22m\n\nIn case you would like to make the dht22m module loads after reboot run:\n\n    sudo echo \"dht22m\" \u003e /etc/modules-load.d/dht22m.conf\n\nWiring of DHT22 \u0026 Hardware connections\n--------------------------------------\n\nThe hardware connection of the dht22 sensor is the same as the method described in user mode reading,\nwhich can be found here https://github.com/hyper-prog/DHT22-Raspberry-Pi\n\nReferences\n-----------\n\nTo learn more about Linux kernel\nmodules in general, see [The Linux Kernel Module Programming\nGuide](https://sysprog21.github.io/lkmpg/). To learn more about the DHT22 / AM2302\nsensor, see the [data sheet](https://files.seeedstudio.com/wiki/Grove-Temperature_and_Humidity_Sensor_Pro/res/AM2302-EN.pdf).\n\nAuthor\n-------\n- Written by Péter Deák (C) hyper80@gmail.com, License GPLv2\n- Thanks to the Google and Lars Engebretsen for sensor handling tips and codes!\n- The author wrote this project entirely as a hobby. Any help is welcome!\n\n------\n\n[![paypal](https://raw.githubusercontent.com/hyper-prog/dht22m/master/images/tipjar.png)](https://www.paypal.com/donate/?business=EM2E9A6BZBK64\u0026no_recurring=0\u0026currency_code=USD)\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhyper-prog%2Fdht22m","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fhyper-prog%2Fdht22m","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fhyper-prog%2Fdht22m/lists"}