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

Hey!
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 setup.py 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 https://github.com/SIGSEGV111/dht22-spi-driver 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 setup.py, so --force-radxa0 doesn’t work (line 89 should be “elif platform == ‘RADXA_ZERO’:” )
  • after running “python3 setup.py --force-radxa0 --force-mraa install” there’s no error and the module seems installed, but running AdafruitDHT.py 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 setup.py clean --all and uninstalling the driver with sudo python3 -m pip uninstall Rockfruit_DHT first.
Let me know if it works!