0

I want to connect my DHT11 sensor to my Raspberry pi 2 Model B. I am using the adafruit tutorial (https://github.com/adafruit/Adafruit_Python_DHT). I've copied the simpletest.pyand ran it with sudo (sudo python DHT11.py). When I did this I get the following message:

RuntimeError: Error acessing GPIO. Make sure program is run as root with sudo!

What am I doing wrong, I've installed all the necessary software to run this.

Specs:

  • Raspberry Pi 2 Model B
  • Raspbian Wheezy
  • DHT11 sensor
  • Data pin = 27

Script:

#!/usr/bin/python

import Adafruit_DHT

sensor = Adafruit_DHT.DHT11
pin = 27
humidity, temperature = Adafruit_DHT.read_retry(sensor, 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 get reading. Try again!'
  • If you had a recent installation (jessie rather than wheezy) you shouldn't need to use sudo to access the GPIO. Could you edit your question and include the command you run and the system response. Could you also include the listing of the Python script you are using. – joan Mar 20 '16 at 17:17
  • I can't see that you have done anything wrong. Presumably somewhere along the chain of Python there is a file which needs updating. I don't have any idea which one that might be. – joan Mar 20 '16 at 18:18
0

I went and looked for an alternative solution, I found this (much longer) code: https://github.com/joan2937/pigpio/blob/master/EXAMPLES/Python/DHT11_SENSOR/dht11.py I just changed the input GPIO pin and it works like a charm.

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.