Skip to main content

DHT11, DHT22, and AM2302 temperature and humidity sensor reading library for Raspberry Pi

Project description

DHT_PI

=======================

Simplified & Modernized fork of Adafruit's Deprecated Python DHT Sensor Library, limited to currently supported versions of Raspberry PI (Pi 2+, but create an issue if you want a Pi 1 port). Provides a simple, safe, and typed reading of temperature and humidity from DHT11, DHT22, AND AM2302 sensors via GPIO pins.

For modern support by Adafruit, see their CircuitPython libraries.

However, this simple library following modern python packaging was created because CircuitPython is a convoluted Kitchen sink that is difficult to use. I wouldn't recommend it.

This fork is not affiliated with Adafruit in any way. All copyrights belong to them except for heavily modified or new code.

Installation

You can install from Pypi using your favorite package manager (such as pip or uv). I recommend using uv

uv add dht_pi
# pip install dht_pi

Designed for Python 3.11+. Create an issue or PR if you want support/port for earlier 3.X versions. We don't even build for them.

Usage

There is a safe class-based endpoint and a slightly less safe functional endpoint.

from dht_pi import Sensor, DHT11 # or DHT22, AM2302 or #SensorType and do SensorType.DHT11

GPIO_PIN = 12 # Or whichever GPIO PIN you used for the data link

sensor = Sensor(sensor_type=DHT11, pin=GPIO_PIN) 
reading = sensor.read_retry() 
# Better to use `sensor.read_retry` instead of `sensor.read`, which gives `None` readings much more readily.
print(reading.humidity, reading.temperature)

# Equivalent, but easy to mix up the order:
humidity, temperature = sensor.read_retry()
print(humidity, temperature)

Functional endpoint:

from dht_pi import SensorType, read_retry, read

GPIO_PIN = 12 # Or whichever GPIO PIN you used for the data link
reading = read_retry(sensor=SensorType.DHT22, pin=GPIO_PIN)

# Most dangerous:
humidity, temperature = read(sensor=SensorType.DHT22.value, pin=GPIO_PIN)

Running directly on a Raspberry Pi

Ensure that your Pi can compile and download Python extensions (such as with pip). Modern Raspbian ships with Python 3.11 and pip. I would still recommend uv (Technically, you can even install uv via pip). Then simply run:

Upcoming:

  • Shell scripts.

Note: Below is from the original repo

Original Author

Adafruit invests time and resources providing this open source code, please support Adafruit and open-source hardware by purchasing products from Adafruit!

Written by Tony DiCola for Adafruit Industries.

MIT license, all text above must be included in any redistribution (?: The license doesn't mention this, but I left this part in here as well as links to Adafruit)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

dht_pi-0.1.3.tar.gz (10.6 kB view details)

Uploaded Source

Built Distributions

If you're not sure about the file name format, learn more about wheel file names.

dht_pi-0.1.3-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.whl (21.4 kB view details)

Uploaded CPython 3.14manylinux: glibc 2.17+ ARM64

dht_pi-0.1.3-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.whl (21.4 kB view details)

Uploaded CPython 3.13manylinux: glibc 2.17+ ARM64

dht_pi-0.1.3-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.whl (21.4 kB view details)

Uploaded CPython 3.12manylinux: glibc 2.17+ ARM64

dht_pi-0.1.3-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.whl (21.3 kB view details)

Uploaded CPython 3.11manylinux: glibc 2.17+ ARM64

File details

Details for the file dht_pi-0.1.3.tar.gz.

File metadata

  • Download URL: dht_pi-0.1.3.tar.gz
  • Upload date:
  • Size: 10.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.8.22

File hashes

Hashes for dht_pi-0.1.3.tar.gz
Algorithm Hash digest
SHA256 b013d12bfbce895cfbe1169cc1d04f1c22d07dd37b6b47cd21d92f747a287abe
MD5 b805fcdb66aa2a962012d19477b202b8
BLAKE2b-256 a98e263d5e968b18625408ac6150a1ec86131e88858a981ceb2f5e3f7e8fc2fb

See more details on using hashes here.

File details

Details for the file dht_pi-0.1.3-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.whl.

File metadata

File hashes

Hashes for dht_pi-0.1.3-cp314-cp314-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 5210f216379d3eb4db9fc2bcc1acd5c0782b105e9fefe1aa112dcdd0c2b8de0b
MD5 486d6999cf66b27fa8c817847daea747
BLAKE2b-256 f0b07e31ec9b9e32a113088155aea4c1de5e1c6a6e04b07cafe8e2c613644f28

See more details on using hashes here.

File details

Details for the file dht_pi-0.1.3-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.whl.

File metadata

File hashes

Hashes for dht_pi-0.1.3-cp313-cp313-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 f541beaa08838a8a550f6304c284205bb754271d573154906775bd3c34a48559
MD5 8cfc0f347c4f13ac941e5911246b7d28
BLAKE2b-256 ad93e12562b4c2c09fc26f7e2fa5f3d629e9ec5eac3fe82e4ef39a7c96d7bd90

See more details on using hashes here.

File details

Details for the file dht_pi-0.1.3-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.whl.

File metadata

File hashes

Hashes for dht_pi-0.1.3-cp312-cp312-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 09e35c55b06ddc32099c212627576823c15fa091225eea8e3a026de5408de3a6
MD5 1be6905060f44a2ad8d6a9fe72b3fe84
BLAKE2b-256 b2c809440222324ff64d69207b95295fb4ee1365ee19ac4aaaca57d0b4c21a91

See more details on using hashes here.

File details

Details for the file dht_pi-0.1.3-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.whl.

File metadata

File hashes

Hashes for dht_pi-0.1.3-cp311-cp311-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Algorithm Hash digest
SHA256 e36ecb865203ad5651cb80bb04e141e4e498c3388f4825acd7696817c8f6d464
MD5 8d3c2586d603d26c55bec7f684e84633
BLAKE2b-256 92142436babddbf9dfeeacf8661790400ac3306726d794a07d2666dd7d638d8b

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page