Skip to content

Raspberry Pi 4 + DHT11 Sensor no floating point temps #98

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
dvelaren opened this issue Apr 14, 2024 · 2 comments · Fixed by #102
Closed

Raspberry Pi 4 + DHT11 Sensor no floating point temps #98

dvelaren opened this issue Apr 14, 2024 · 2 comments · Fixed by #102

Comments

@dvelaren
Copy link

dvelaren commented Apr 14, 2024

Hello Adafruit Devs,

I would like to report a problem dealing with DHT11 sensor readings using your library. It seems that the decimals for the temperature are missing. I'm only getting temperatures without decimal precision (it is always 0).

Here is the minimal code to reproduce the issue:

import time
import board
import adafruit_dht

sensor = adafruit_dht.DHT11(board.D17)

while True:
    try:
        temperature = sensor.temperature
        humidity = sensor.humidity
        print(f"Temp: {temperature:.2f} °C, Hum: {humidity:.2f} %")
    except RuntimeError as e:
        print(f"Reading from DHT failure: {e.args[0]}")
        time.sleep(2)
        continue
    except Exception as e:
        sensor.exit()
        raise e
    time.sleep(2)

I'm getting this output always:

Temp: 28.00 °C, Hum: 64.00 %
Temp: 27.00 °C, Hum: 64.00 %
Temp: 28.00 °C, Hum: 64.00 %
@TheChilliPL
Copy link

I have the same issue

@manyhuis
Copy link

manyhuis commented Oct 24, 2024

I did a little digging and found a fix for myself. If you are able to edit the source adafruit_dht.py file...

Change Line 239 from
new_temperature = buf[2]

to
new_temperature = buf[2] + float(buf[3])/10

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants