I’m quite new to RPi and was working on the tutorials of Paul McWorther.
Now I came across the DHT11 temperature sensor where I was first notified about the ‘unkown platform error’ which I understand is linked to me using the RPi 4b (instead of older versions). With many searches I managed to work around this error but now I get the message ‘int’ object not callable. If you can help me out would be appreciated.
Here is the code I’m using:
import RPi.GPIO as GPIO
import Adafruit_DHT
import digitalio
import board
import time
Initial the dht device, with data pin connected to GPIO4
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:
sensor.exit()
raise error
time.sleep(2.0)
The error “int object not callable” happens because two different DHT libraries are being mixed together in the code.
In your current script, this line:
sensor = Adafruit_DHT.DHT11(board.D4)
is the issue.
Adafruit_DHT.DHT11 is actually just an integer constant, not a function. So Python is trying to “call” an integer, which causes the error.
If you are following Paul McWhorter’s tutorial, please modify your code like this:
import Adafruit_DHT
import time
sensor = Adafruit_DHT.DHT11
pin = 4 # GPIO4
while True:
humidity, temperature = Adafruit_DHT.read(sensor, pin)
if humidity is not None and temperature is not None:
print(f"Temp: {temperature:.1f} C Humidity: {humidity}%")
else:
print("Sensor failure. Please check wiring.")
time.sleep(2)
Hello, and many thanks for your response to my question.
However, I already tried this, and tried now once more, but with this code the following error is raised:
RuntimeError(‘Unknown platform’)
As I understand this has to do with the fact that I run this code on a RPi 4b which is apparently not defined in “platform_detect.py”. If you might have an idea how to solve this issue, would be appreciated.
The error you’re seeing — RuntimeError: ‘Unknown platform’ — is not caused by your wiring or Python syntax. It happens because the Adafruit_DHT library is an older driver and it may not recognize newer Raspberry Pi OS, such as Bookwarm, Trixie, so it reports “Unknown platform”.
The best solution is to use a newer, actively maintained DHT library.