DHT22 visar inte lägre temp än 0.2 °C

Permalänk
Medlem

DHT22 visar inte lägre temp än 0.2 °C

Har en DHT22 som enligt denna spec. ska kunna mäta temperaturer mellan -40 °C till +80 °C
https://components101.com/sensors/dht22-pinout-specs-datashee...

Raspberry Pi och ett skript i python snurrar och jag kan läsa temperatur och fukt och där konstaterar jag att jag inte erhåller lägre temperatur än 0,2 °C
Grunden till mitt skarpa skript är detta jag hittat på nätet

# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT import time import board import adafruit_dht # Initial the dht device, with data pin connected to: dhtDevice = adafruit_dht.DHT22(board.D4) # you can pass DHT22 use_pulseio=False if you wouldn't like to use pulseio. # This may be necessary on a Linux single board computer like the Raspberry Pi, # but it will not work in CircuitPython. dhtDevice = adafruit_dht.DHT22(board.D4, use_pulseio=False) while True: try: # Print the values to the serial port temperature_c = dhtDevice.temperature temperature_f = temperature_c * (9 / 5) + 32 humidity = dhtDevice.humidity print( "Temp: {:.1f} C Fukt: {} % ".format( temperature_c, humidity ) ) except RuntimeError as error: # Errors happen fairly often, DHT's are hard to read, just keep going print(error.args[0]) time.sleep(2.0) continue except Exception as error: dhtDevice.exit() raise error time.sleep(10.0)

(det "grund-skriptet" visar inte heller lägre än 0,2)

Vid rumstemperatur visas rätt temperatur.
Vid ca -12 °C visas alltså 0,2 °C

Varför blir det så?

Tråden kanske inte specifikt hör till just enkortsdatorer men eftersom jag har anslutit givaren till en sån så...

Visa signatur

LMDE6 Faye @Mintbox Mini 2 Pro

Permalänk
Medlem

Körde koden genom chatGPT:
It looks like this code is intended to read temperature and humidity data from a DHT22 sensor using the Adafruit DHT library. At a high level, the code initializes the DHT22 sensor and then enters a loop where it repeatedly reads temperature and humidity values from the sensor and prints them to the console.

There are a few things that could be improved in this code:

The DHT22 device is initialized twice, with the second initialization overwriting the first. It would be better to only initialize the device once, and pass the use_pulseio argument in the first initialization.

The code catches any Exception that might be thrown in the try block, which is generally not a good practice. It would be better to only catch specific exceptions that you expect to be thrown, such as RuntimeError which is raised when there is an error reading the sensor.

The continue statement in the except block will cause the loop to skip the rest of the current iteration and continue to the next one. This means that the time.sleep(10.0) line will not be executed, which could cause the loop to run too frequently. Instead, you might want to move the time.sleep(10.0) line to the bottom of the loop, outside of the try-except block.

That being said, the code should be functional as it is, assuming the necessary libraries are installed and the DHT22 sensor is properly connected. If you are experiencing any issues with the code, please provide more information about the problem you are encountering and I will do my best to help.

It doesn't work with negative temperature

If the temperature being read by the DHT22 sensor is negative (below 0°C), it is possible that the sensor is not correctly configured or is not functioning correctly. Here are a few things you can try to troubleshoot the issue:

Make sure the DHT22 sensor is properly connected to the microcontroller. Check the wiring diagram provided by the manufacturer to ensure that the sensor is connected correctly.

Make sure you are using the correct type of DHT sensor. The DHT22 is designed to measure temperature in the range of -40°C to 80°C, so if you are expecting to measure temperatures outside of this range, you may need to use a different type of sensor.

Check the temperature and humidity values being returned by the DHT22 sensor. If the values seem unreasonable or are fluctuating wildly, there may be an issue with the sensor itself. You can try running the sensor outside of the loop and printing the values to the console to see if the values are stable.

Make sure the code is correctly reading the temperature and humidity values from the sensor. The temperature property of the DHT22 object returns the temperature in degrees Celsius, so you may need to convert the value to Fahrenheit if you are expecting the temperature to be in that unit.

If the sensor is still not working as expected, you may need to replace the sensor or check for any other hardware issues.

I hope this helps! If you have any further questions or need more assistance, please don't hesitate to ask.

Är ju inte helt dåliga tips.
Har du testat med en annan sensor om det är hårdvarufel?

Permalänk
Medlem

Om man googlar på DHT22 negative temperature så får man upp att det är känd bug, verkar ha något problem med checksum vid negativa temperaturer.

Permalänk
Medlem

Tack!
Okej, jag har själv hittat nåt om att sensorn läser heltal vid minusvärden och att det skulle kunna ställa till det.
Har även hittat att det är själva biblioteket som inte hanterar negativa tal och att ett annat bibliotek skulle kunna fixa detta men jag har inte hittat nåt annat att ladda hem.

Tillägg: Måste vänta tills det blir minusgrader igen...

minus
Visa signatur

LMDE6 Faye @Mintbox Mini 2 Pro

Permalänk
Medlem

Lägg den i frysen.

Permalänk
Medlem

Hittade ett annat skript men där blir det ett annat fel vid minusgrader, något som jag sett beskrivas i andra trådar men inte hittat någon lösning för..
Jag får värdet 6553.0 när det är strax under nollan.

import RPi.GPIO as GPIO import dht22 import time import datetime # initialize GPIO GPIO.setwarnings(True) GPIO.setmode(GPIO.BCM) # read data using pin 4 instance = dht22.DHT22(pin=4) try: while True: result = instance.read() if result.is_valid(): print("Last valid input: " + str(datetime.datetime.now())) print("Temperature: %-3.1f C" % result.temperature) print("Humidity: %-3.1f %%" % result.humidity) time.sleep(5) except KeyboardInterrupt: print("Cleanup") GPIO.cleanup()

Visa signatur

LMDE6 Faye @Mintbox Mini 2 Pro

Permalänk
Rekordmedlem

Det låter som om det är nått fel som har med tillämpningen av 2 komplementsform att göra, känner inte till nått alls om den specifika produkten så fråga mig inget om det.
https://sv.wikipedia.org/wiki/Tv%C3%A5komplementsform

Visa signatur

R5 5600G, Asus ROG STRIX X470-F Gaming, WD SN850X 2TB, Seasonic Focus+ Gold 650W, Aerocool Graphite v3, Tittar på en Acer ET430Kbmiippx 43" 4K. Lyssnar på Behringer DCX2496, Truth B3031A, Truth B2092A. Har också oscilloskop, mätmikrofon och colorimeter.

Permalänk
Medlem

Ja, jag var inne på att det "slog över" till 65536 (2^16) och att det petades in en decimalpunkt där, vid minusvärden.
Men det är inte konsekvent detta.. jag kan få 0,0, 0,2 och detta 6553.0 (ish) under samma temperaturförhållande. Jag ser att även fuktigheten får konstiga värden.
Kanske bara att gilla läget och använda tempsensorn till något annat då...
Styrningen av elpannan har jag bytt till Sonoff, annars hade det varit ett lämpligt uppdrag.

Förslag?

Visa signatur

LMDE6 Faye @Mintbox Mini 2 Pro

Permalänk
Rekordmedlem
Skrivet av Mikael63:

Ja, jag var inne på att det "slog över" till 65536 (2^16) och att det petades in en decimalpunkt där, vid minusvärden.
Men det är inte konsekvent detta.. jag kan få 0,0, 0,2 och detta 6553.0 (ish) under samma temperaturförhållande. Jag ser att även fuktigheten får konstiga värden.
Kanske bara att gilla läget och använda tempsensorn till något annat då...
Styrningen av elpannan har jag bytt till Sonoff, annars hade det varit ett lämpligt uppdrag.

Förslag?

Själva sensorn är säkert ganska linjär om du mäter dess utsignal, problemen lär vara i mjukvaran eller kretsarna efter sensorn.
DHT 22 är dock inte en ren sensor utan den innehåller andra kretsar.

Visa signatur

R5 5600G, Asus ROG STRIX X470-F Gaming, WD SN850X 2TB, Seasonic Focus+ Gold 650W, Aerocool Graphite v3, Tittar på en Acer ET430Kbmiippx 43" 4K. Lyssnar på Behringer DCX2496, Truth B3031A, Truth B2092A. Har också oscilloskop, mätmikrofon och colorimeter.

Permalänk
Medlem
Skrivet av mrqaffe:

DHT 22 är dock inte en ren sensor utan den innehåller andra kretsar.

Ja, jag skaffade den för att "leka med". När jag så hittade ett skript som fungerade tänkte jag hitta ett användningsområde.
Om jag måste mäta just temperatur har jag några andra givare att "leka med" men jag låter det vara. Kanske får bygga ett växthus och reglera klimatet i det. Nån gång..

Visa signatur

LMDE6 Faye @Mintbox Mini 2 Pro