1

I have DHT22 sensor hooked up to my Raspberry Pi2 running default Raspbian image. I have similar setup on Raspberry Pi B and it is working. I am using Adafruit library for DH22. However when I try running the code to read data from DHT22 I get the following exception (using the example code that comes with library):

Traceback (most recent call last):
  File "AdafruitDHT.py", line 41, in <module>
    humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
  File "build/bdist.linux-armv7l/egg/Adafruit_DHT/common.py", line 90, in read_retry
  File "build/bdist.linux-armv7l/egg/Adafruit_DHT/common.py", line 77, in read
  File "build/bdist.linux-armv7l/egg/Adafruit_DHT/Raspberry_Pi_2.py", line 34, in read
RuntimeError: Error accessing GPIO.

I have found on internet that the exception it related to lack of permission and that running the code as sudo should fix the problem. But I had no luck so far with it.

I have tried running the code as:

1.

python AdafruitDHT.py 2302 4

2.

sudo python AdafruitDHT.py 2302 4

3.

su -
python AdafruitDHT.py 2302 4

However all ways yield the same exception. How can I fix this problem?

  • Have you tried using a different GPIO? Don't move the DHT22, just check if giving a different GPIO number gives the same error. – joan Jul 18 '16 at 8:47
  • Yes, I have tried several GPIO ports and the exception is always the same. – Denis Vitez Jul 18 '16 at 10:31
  • Can't help. You need to see if you can access the GPIO with other software and try to localise the problem. – joan Jul 18 '16 at 11:02
  • I have tried the pigpio library that I assume you created? However I am now getting readings of -999. I will check the wiring and try another sensor to exclude problem with my setup. – Denis Vitez Jul 19 '16 at 7:07
  • -999 means no reading. Probably because pigpio only uses (Broadcom) GPIO numbering. See abyz.co.uk/rpi/pigpio/#Type_3. I suggest you use abyz.co.uk/rpi/pigpio/examples.html#pdif2_DHTXXD with pigpio. – joan Jul 19 '16 at 7:25

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.