Temperature sensor on Orange Pi with Python code

In my previous IoT project on the Orange Pi I showed how to read a DHT22 or a DHT11 temperature and humidity sensor. That project involved connecting the sensor to the GPIO pins and writing C code to read the sensor. In this example I will show you how do the same, but using Python code instead.

Have a look at the previous post to see how to connect the sensor to the GPIO pins of the Orange Pi. Now we want to use Python to read the sensor. The solution is based on Vitalik-Samets’ code for the DHT11 on the Orange Pi, which in turn uses the Allwinner H3 GPIO Python library written by duxingkei33. To make the code work with the DHT22, I changed the readings returned by the sensors from these:

After that I renamed the DHT11 variable names to DHT22. I also changed the data type of the readings from integer to float. To install the library, first clone and install the H3 GPIO Python git repository:

Comments

Hi..
I tried your code for DHT22 sensor..it working.
But did u realised that it do not know to read (show) negativ value?
For example every reading below zero it do the absolute value of number and giving positive value.
Can u fix the reading?
Thx