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.
Your firmware may use any name it likes at module level: the driver's own parameters
are ordinary words (mask, bit, start_low_ms), and a global that collides with
one of them no longer reaches inside. That took a compiler fix, so the suite measures
it rather than assuming it — see tests/test_timing.py.
See docs/ for the wire protocol, wiring diagrams, accuracy limits, sensor comparison,
and a porting guide for a new architecture.
License
MIT.
Metadata
Release files for pymcu-lib-dht 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| pymcu_lib_dht-0.1.1.tar.gz | 34.5 kB | With provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pymcu_lib_dht-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 48.5 kB
Release files / pymcu_lib_dht-0.1.1.tar.gz
| Download URL | pymcu_lib_dht-0.1.1.tar.gz |
|---|---|
| Size | 34.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4d557eabfca98b8e439608a1e76e0428619132818bfd6bbdcfc2f143f88c2308
|
|
BLAKE2b-256 checksum How to use checksums |
92c9f44858ac2181dab86ca7654f8ab9506132ffcd06d77ebf9819eec7822f3c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 18, 2026.
Transparency logRelease files / pymcu_lib_dht-0.1.1-py3-none-any.whl
| Download URL | pymcu_lib_dht-0.1.1-py3-none-any.whl |
|---|---|
| Size | 14.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
00e0244f3e6fef50aecd58ef725d0c6a7082ff1b60461739c753bf8a27ed5e1f
|
|
BLAKE2b-256 checksum How to use checksums |
e62a8d518e5fb1a52ab9182ac93d5f4c668a33d338acb4b7d1028b471f863976
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 18, 2026.
Transparency logSecurity for pymcu-lib-dht 0.1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
Full provenance
All 2 files in this release have been uploaded with provenance metadata.
Attestation for pymcu_lib_dht-0.1.1.tar.gz
PyPI Publish Attestation
PyPI verified that this artifact, at this checksum, originated from the publisher listed below.
Signed by GitHub Actions, verified by PyPI on Aug 18, 2026.
Transparency logA note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.