DHT22 and Orange Pi Zero

The DHT22 is a temperature and humidity sensor that can be connected to nano computers such as the Orange PI.


Connect the DHT22 to the + 3.3v of the orange pi zero and for example to the PA06 pin as shown in the diagram.


For the installation of the Armbian system, see the following article: https://f1atb.fr/index.php/2020/08/06/getting-started-orange-pi-zero/

First for python 3, you have to update and add the pip installer, setuptools and python3-dev.

apt-get update
apt-get upgrade
apt install python3-pip
apt-get install python3-setuptools
apt-get install python3-dev

Go to the folder you want to use to install the GPIO and DHT libraries. Add sudo to the commands if you are not root.

git clone https://github.com/nvl1109/orangepi_zero_gpio.git
cd orangepi_zero_gpio
python3 setup.py install

Return to your installation folder and clone the DHT temperature sensor library.

git clone https://github.com/jingl3s/DHT11-DHT22-Python-library-Orange-PI.git

Put a copy of the dht.py file of the library in the folder where you want to run the test program for your DHT sensor on pin PA6.

cp DHT11-DHT22-Python-library-Orange-PI/dht.py dht.py

Create the source test.py with nano.

nano test.py
from pyA20.gpio import gpio
from pyA20.gpio import port

import dht
import time
import datetime

# initialize GPIO
PIN2 = port.PA6

# read data using pin
instance = dht.DHT(pin=PIN2)

while True:
    result = instance.read()
    if result.is_valid():
        print("Last valid input: " + str(datetime.datetime.now()))
        print("Temperature: {0:0.1f} C".format(result.temperature))
        print("Humidity: {0:0.1f} %".format(result.humidity))


Test the set with:

python3 test.py

The output:

Last valid result: 2020-10-03 04:17:58.325014
Temperature: 23.3 C
Humidity: 57.6 %