7

I am facing issues running DHT 11 temperature sensor in PI 2 with Python2.7 GPIO 0.5.11. I am referring to http://www.uugear.com/portfolio/dht11-humidity-temperature-sensor-module/ sample code.

Same code works fine on PI 1 B+. In PI 2 i get "ERR_RANGE" as Error. I tried debugging the issue seems like data read @ GPIO pin 4 needs to be increased.

After increasing the data read value to 2000, the value for temperature and humidity returned is 255 all the time. Has anyone faced the issue do help me on how to solve.

Thanks, Bharadvaj

sevenOfNine
  • 1,509
  • 16
  • 37
  • This may be your problem https://blog.adafruit.com/2015/02/27/i2c-spi-i2s-lirc-pps-stopped-working-read-this-piday-raspberrypi-raspberry_pi/ but we will need more info to help you can you post a picture(s) showing the connections and your source code. – Steve Robillard Mar 08 '15 at 12:16
  • Thanks for the reference link i will verify and update. – Bharadvaj Jayachandra Mar 12 '15 at 13:48

3 Answers3

13

You can also check the following small library. It depends only on GPIO module:

https://github.com/szazo/DHT11_Python

Example:

import RPi.GPIO as GPIO
import dht11

# initialize GPIO
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
GPIO.cleanup()

# read data using pin 14
instance = dht11.DHT11(pin = 14)
result = instance.read()

if result.is_valid():
    print("Temperature: %d C" % result.temperature)
    print("Humidity: %d %%" % result.humidity)
else:
    print("Error: %d" % result.error_code)
Zoltán Szarvas
  • 131
  • 1
  • 4
3

Maybe more information will help to solve your problem. I have the same sensor like you.

I followed this tutorial : https://learn.adafruit.com/dht-humidity-sensing-on-raspberry-pi-with-gdocs-logging/software-install-updated

git clone https://github.com/adafruit/Adafruit_Python_DHT.git
cd Adafruit_Python_DHT
sudo apt-get update
sudo apt-get install build-essential python-dev
sudo python setup.py install

And this is my testing python script :

#!/usr/bin/python
import sys
import Adafruit_DHT
humidity, temperature = Adafruit_DHT.read_retry(11, 4)
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!'

Save it as for example dht_test.py , Chmod : sudo chmod a+x dht_test.py and run as sudo : sudo ./dht_test.py Maybe this helps you.

Tomas Pytel
  • 188
  • 2
  • 14
  • I could get temperature and humidity according to your answer. But it seems that the fractional parts of both data are always 0. For example, Temp=25.0*C Humidity=35.0%. – sevenOfNine Oct 25 '15 at 11:48
  • I found that DHT11 does not measure the fractional part. So, the measurement is successful. – sevenOfNine Oct 25 '15 at 12:42
0

The below code works on Pi 2 Model B:

https://github.com/netikras/r-pi_DHT11/blob/master/dht11.py

Kani
  • 179
  • 1
  • 4