Difficulty: ★★☆☆☆
There is some misleading advice out there, suggesting the need for a 10k ohm resistor. But the the three lead DHT22 comes with an inbuilt resistor, which seems to do the job, also the majority of advice is for RaspberryPI OS. I thought I would share my experience:
-
I suggest connecting to pin 1 for 3.3 volt supply (RaspberryPi3/4), pin 11 for
gpio17
and pin 9 forgnd
. -
You should also install software from Adafruit, use
pacman
to installpip
andgcc
if needed.sudo pip3 install Adafruit_DHT
-
You need a python script to access the sensor
import Adafruit_DHT DHT_SENSOR = Adafruit_DHT.AM2302 DHT_PIN = 17 while True: humidity, temperature = Adafruit_DHT.read_retry(DHT_SENSOR, DHT_PIN) if humidity is not None and temperature is not None: print("Temp={0:0.1f}*C Humidity={1:0.1f}%".format(temperature, humidity)) else: print("Failed to retrieve data from humidity sensor")
-
Unfortunately you need root permission to access the sensor, therefore I:
- copied
60-rpi.gpio-common.rules
from RaspberryOS to/lib/udev/rules.d
SUBSYSTEM=="bcm2835-gpiomem", KERNEL=="gpiomem", GROUP="dialout", MODE="0660" SUBSYSTEM=="gpio", KERNEL=="gpiochip*", ACTION=="add", PROGRAM="/bin/sh -c 'chown root:dialout /sys/class/gpio/export /sys/class/gpio/unexport ; chmod 220 /sys/class/gpio/export /sys/class/gpio/unexport'" SUBSYSTEM=="gpio", KERNEL=="gpio*", ACTION=="add", PROGRAM="/bin/sh -c 'chown root:dialout /sys%p/active_low /sys%p/direction /sys%p/edge /sys%p/value ; chmod 660 /sys%p/active_low /sys%p/direction /sys%p/edge /sys%p/value'"
- created a
dialout
group and added myself as user, and now I don’t need root privileges.groupadd dialout usermod --append dialout $USER
- copied