I have a Raspberry Pi 4 connected with a DHT22 sensor, and I want to read data from my sensor.
So I installed the library Adafruit_DHT
sudo pip3 install Adafruit_DHT
then, I navigate to the directory Adafruit_Python_DHT/examples/
, and then,
since I have a DHT22 sensor connected to GPIO pi n° 4,
I run
python AdafruitDHT.py 22 4
and I get
(lab_app) root@Raspberry100:/var/www/lab_app/Adafruit_Python_DHT/examples# python AdafruitDHT.py 2302 4
Traceback (most recent call last):
File "AdafruitDHT.py", line 41, in <module>
humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
File "/var/www/lab_app/lib/python3.8/site-packages/Adafruit_DHT-1.4.0-py3.8-linux-armv7l.egg/Adafruit_DHT/common.py", line 94, in read_retry
humidity, temperature = read(sensor, pin, platform)
File "/var/www/lab_app/lib/python3.8/site-packages/Adafruit_DHT-1.4.0-py3.8-linux-armv7l.egg/Adafruit_DHT/common.py", line 80, in read
platform = get_platform()
File "/var/www/lab_app/lib/python3.8/site-packages/Adafruit_DHT-1.4.0-py3.8-linux-armv7l.egg/Adafruit_DHT/common.py", line 63, in get_platform
raise RuntimeError('Unknown platform.')
RuntimeError: Unknown platform.
(lab_app) root@Raspberry100:/var/www/lab_app/Adafruit_Python_DHT/examples# python AdafruitDHT.py 22 4
Traceback (most recent call last):
File "AdafruitDHT.py", line 41, in <module>
humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
File "/var/www/lab_app/lib/python3.8/site-packages/Adafruit_DHT-1.4.0-py3.8-linux-armv7l.egg/Adafruit_DHT/common.py", line 94, in read_retry
humidity, temperature = read(sensor, pin, platform)
File "/var/www/lab_app/lib/python3.8/site-packages/Adafruit_DHT-1.4.0-py3.8-linux-armv7l.egg/Adafruit_DHT/common.py", line 80, in read
platform = get_platform()
File "/var/www/lab_app/lib/python3.8/site-packages/Adafruit_DHT-1.4.0-py3.8-linux-armv7l.egg/Adafruit_DHT/common.py", line 63, in get_platform
raise RuntimeError('Unknown platform.')
RuntimeError: Unknown platform.
(lab_app) root@Raspberry100:/var/www/lab_app/Adafruit_Python_DHT/examples#
Since the traceback indicates
'Unknown platform.'
I did a little research on the github repository of Adafruit_Python_DHT library, and I found the script Adafruit_Python_DHT/Adafruit_DHT/common.py
.
Here I see there is an If/elif structure def get_platform()
that aims to identify the device calling the library, but there is value assignment only for RPi 1, 2 and 3, while RPi 4 is missing.
So I bet this is the reason why the error unknown platform
occurs.
I navigated the library source code and I found out the directory Adafruit_Python_DHT/Adafruit_DHT/
, in which the last commit says "included Raspberry Pi 4".
Here is a module platform_detect.py
that seems to be designed to somehow "upgrade" the library in order to recognize Raspberry Pi 4.
So I tryed to "upgrade" my library by doing this:
In (lab_app) root@Raspberry100:/var/www/lab_app/Adafruit_Python_DHT/Adafruit_DHT#
,
I run
platform_detect.py
And I don't get any output from the prompt, so I guess everything has gone right.
Then I navigate to the directory Adafruit_Python_DHT/examples/
and run again
python AdafruitDHT.py 22 4
but I still get the same error.
So how can I get data from a DHT22 sensor connected to GPIO pi n° 4 by using Adafruit_Python_DHT library?