How to read data from a DHT22 (AM2302) temperature sensor?

Hi everyone,

Bit new to Rock Pi and SBC’s in general.
I’d like to read data on a DHT22 temperature sensor from SPI pin (23) but I’m struggling to find any solution compatible with a Rock Pi. I’ve tried Adafruit and others but they all seem to be only made for Raspberry Pi and I only get messages that tell me to get lost and buy a Raspberry instead.
I’ve tried libmraa but it only returns 1, wether the sensor is connected or not. I’m a bit lost here. Any help would be appreciated. Thanks

I just got done building a forked driver for Radxa Zero which talks to DHT22 sensors via GPIO, if you’re okay with that. It’s based on the excellent Adafruit DHT sensor driver (Which I’m not allowed to link because of forum rules). It SHOULD work for other devices using libmraa, as it really only talks to the mraa C-library.
You can check out my driver on github if you want to try. I haven’t yet updated the description, but installation should be as simple as calling ‘sudo python3 install’ in the project directory. If it does not autodetect your device, add ‘–force-radxa0’ to the call.
The driver builds against libmraa (which btw can’t really read pins from the command line, I don’t know why.)
When installed, you can get sensor values with
import Rockfruit_DHT as dhtdriver
dht22_port = 8 # Your GPIO port!
humidity,temperature = dhtdriver.read_retry(dhtdriver.DHT22, dht22_port)
in python3 (with admin rights).
I wrote the driver mostly for myself, but let me know if you try!
If you want to use SPI, maybe look at or similar?

Thank you so much for the help, I was desperate :slight_smile:
I’m going to try this !

Have a wonderful day !

Thank you for your work!
I’m trying to get this working on a RockPi 4 SE, but I’ve found some problems:

  • there’s an error in, so --force-radxa0 doesn’t work (line 89 should be “elif platform == ‘RADXA_ZERO’:” )
  • after running “python3 --force-radxa0 --force-mraa install” there’s no error and the module seems installed, but running exits with “No module named ‘Rockfruit_DHT’”.

Hey! Thanks for the feedback :slight_smile:
Just pushed a fix - I really messed up the naming scheme when adding the libgpiod driver, so the driver could not build correctly.
I also fixed the bug when using --force-radxa0 (that flag is now called --force-radxa, without the 0).
If you want to try again, remember to call sudo python3 clean --all and uninstalling the driver with sudo python3 -m pip uninstall Rockfruit_DHT first.
Let me know if it works!

Hi Did anyone get this to work, we have the same issue and can not get this driver to work on Rock pi E using a dht22 on pin 7

Hi - any specific error message? I can try to help you, but I’ve got no access to a Rock E I’m afraid.

We finally got it to run, but only if we max the cpu or create a fake thread that loads the cpu 20% continuously. otherwise it simply does not read or read once a few hours.

Does this support Rock 3C? I tried, lots of errors.

Same issue on the RockPi 4b

In file included from source/Radxa_Zero/rzero_dht_gpiod_read.c:21 :

source/Radxa_Zero/rzero_dht_gpiod_read.h:26:10: fatal error: gpiod.h: No such file or directory

26 | #include <gpiod.h>

I have the same issue. Did you get around it?

Actually I did get around it but now I keep getting message:
Segmentation fault