pymcu-lib-dht
DHT-family temperature & humidity sensor driver for PyMCU — DHT11, DHT22/AM2302, and DHT21/AM2301 — compiled to native machine code, with no interpreter on the chip.
pymcu install dht
Two module names, three APIs, one driver
Which module name and shape you get depends on the stdlib layer your project
declares. Native and MicroPython both import from dht — that is real MicroPython's
own module name; CircuitPython imports from adafruit_dht, matching that ecosystem's
real name instead.
Native (stdlib unset):
from dht import DHT11, DHT22 # DHT21 is also available: an alias of DHT22
sensor = DHT22("PD2")
sensor.measure()
humidity = sensor.humidity() # uint16, tenths of %RH: 653 = 65.3
temperature = sensor.temperature() # int16, tenths of C: -55 = -5.5
MicroPython (stdlib = ["micropython"]) — a MicroPython script, unchanged:
from machine import Pin
from dht import DHT11
sensor = DHT11(Pin(2))
sensor.measure()
print(sensor.humidity(), sensor.temperature())
CircuitPython (stdlib = ["circuitpython"]) — an adafruit_dht script, unchanged:
import board
from adafruit_dht import DHT22
sensor = DHT22(board.D2)
print(sensor.temperature, sensor.humidity) # float, matching upstream
None of those files contains a single match __CHIP__.arch: the layer adapters are
plain Python written against each API as it is documented upstream. Everything that has
to know about a chip lives in one private module, _dht.core, and the compiler folds
it away; everything that has to know what a byte means for a given sensor model lives
in _dht.decode, which needs no chip dispatch of its own.
DHT11 vs. DHT22 vs. DHT21
- DHT11 — integer %RH and C, no fractional resolution, no negative temperatures. Cheapest, and the smallest to compile against (see below).
- DHT22/AM2302 — one decimal digit, negative temperatures, wider and more accurate range.
- DHT21/AM2301 — the same protocol and byte layout as the DHT22. This library
exposes it as
DHT21 = DHT22, a plain alias, not a second implementation.
See docs/sensors.md for the full comparison and docs/protocol.md for the byte-level
differences.
Cost
The whole driver is @inline: no object is allocated on the device, and a read
compiles down to the bit-banging routine at the call site (or a single shared
subroutine where the compiler's outliner judges that cheaper). Nothing is held in
SRAM between reads.
dht.py and compat/micropython/dht.py report tenths as a plain int16/uint16
rather than a float, on both DHT11 and DHT22: two isolated probes measured on the
emulator put a float-returning driver at 4.9x the flash of an int16-tenths one
(680 vs. 140 bytes) for the same logic. See docs/accuracy.md for the measurement.
adafruit_dht.py is the one exception — it matches adafruit_dht's real float
signature on purpose, since fidelity to that upstream API is the point of the module.
Measured figures per chip are published in the library index.
Supported hardware
The whole DHT family on AVR (ATmega328P and friends), data line on PD2-PD7.
Timing is measured on the AVR emulator rather than assumed — see
tests/test_timing.py for the start-signal and bit-decode-threshold checks.
Other architectures raise a compile-time error rather than returning something that
looks like it worked. Ports are welcome: _dht/avr.py is the whole contract, and
_dht/decode.py (the per-model byte decoding) needs no changes for a new port.
See docs/ for the wire protocol, wiring diagrams, accuracy limits, sensor comparison,
and a porting guide for a new architecture.
License
MIT.
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pymcu_lib_dht-0.1.0.tar.gz.
File metadata
- Download URL: pymcu_lib_dht-0.1.0.tar.gz
- Upload date:
- Size: 29.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c68a39cb52b6adfa4b750805380d234fd4a6e66ecc6c810a27b24a43ad7ef9f9
|
|
| MD5 |
1f1ea29340e0c60e06e51e39f02dd71b
|
|
| BLAKE2b-256 |
6ca09d3f135d1b857b334384917e98eaf7f319fb855e282c6d82f43a8b6c3d45
|
Provenance
The following attestation bundles were made for pymcu_lib_dht-0.1.0.tar.gz:
Publisher:
publish.yml on PyMCU/pymcu-lib-dht
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pymcu_lib_dht-0.1.0.tar.gz -
Subject digest:
c68a39cb52b6adfa4b750805380d234fd4a6e66ecc6c810a27b24a43ad7ef9f9 - Sigstore transparency entry: 2496517974
- Sigstore integration time:
-
Permalink:
PyMCU/pymcu-lib-dht@fd3fa8a432508f34717ade51a060fd68f69ff350 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/PyMCU
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@fd3fa8a432508f34717ade51a060fd68f69ff350 -
Trigger Event:
release
-
Statement type:
File details
Details for the file pymcu_lib_dht-0.1.0-py3-none-any.whl.
File metadata
- Download URL: pymcu_lib_dht-0.1.0-py3-none-any.whl
- Upload date:
- Size: 13.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via:
twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
265917d3a126a813dd6bea9b7048e7917002753c45a035cd7a42d5347e07c1d1
|
|
| MD5 |
ce48d09ae6ff9b5946f043279435f190
|
|
| BLAKE2b-256 |
802f06811c0fb2bb54b29791d6d070a1407e8ee6de72c1408a2720cdac415657
|
Provenance
The following attestation bundles were made for pymcu_lib_dht-0.1.0-py3-none-any.whl:
Publisher:
publish.yml on PyMCU/pymcu-lib-dht
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pymcu_lib_dht-0.1.0-py3-none-any.whl -
Subject digest:
265917d3a126a813dd6bea9b7048e7917002753c45a035cd7a42d5347e07c1d1 - Sigstore transparency entry: 2496517993
- Sigstore integration time:
-
Permalink:
PyMCU/pymcu-lib-dht@fd3fa8a432508f34717ade51a060fd68f69ff350 -
Branch / Tag:
refs/tags/v0.1.0 - Owner: https://github.com/PyMCU
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@fd3fa8a432508f34717ade51a060fd68f69ff350 -
Trigger Event:
release
-
Statement type: