davidecibel
Posts: 5
Joined: Wed Apr 25, 2018 8:17 am

DHT22 temp/humidity sensor often fails to read

Mon May 21, 2018 9:38 am

So, I got myself a DHT22 temperature/humidity sensor and set it up using the info in this page: http://www.instructables.com/id/Raspber ... midity-lo/

Now, it does work, but often it fails to get reading from the sensor.

I've tried to take a look at the log files in /home/pi/DHT22-TemperatureLogger/Debugger/Logs/ , and everytime it fails there's this error:

Code: Select all

21-05-18 11:10:02 INFO Sensors.SensorReader Start reading values for sensor type 22 in gpio 27
21-05-18 11:10:42 ERROR Sensors.SensorReader Failed to get readings for sensor: Inside
Traceback (most recent call last):
  File "/home/pi/DHT22-TemperatureLogger/Sensors/SensorReader.py", line 58, in getSensorReadings
    temperature,humidity = self._getSensorReadings(sensorType,gpio)
  File "/home/pi/DHT22-TemperatureLogger/Sensors/SensorReader.py", line 133, in _getSensorReadings
    sensorReadings = subprocess.check_output(['sudo',self.adafruitPathConfig,sensorType,gpio])
  File "/usr/lib/python2.7/subprocess.py", line 219, in check_output
    raise CalledProcessError(retcode, cmd, output=output)
CalledProcessError: Command '['sudo', u'/home/pi/Adafruit_Python_DHT/examples/AdafruitDHT.py', u'22', u'27']' returned non-zero exit status 1
21-05-18 11:10:42 INFO Sensors.SensorReader Sensor readings collected
21-05-18 11:10:42 INFO Sensors.SensorDataHandler Successfully read: 0 sensors. Failed to read: 1 sensor(s)
21-05-18 11:10:42 ERROR Sensors.SensorDataHandler Failed to get readings from any of the sensors. Execution terminated
Does anyone know what could cause it? I've scheduled a reading every 5 minutes with crontab and it seems to fail randomly. I've tried to change the voltage to 5.5v and the cable is very short, so the connection shouldn't be the issue (I haven't tried a different GPIO pin yet, though).

hippy
Posts: 3044
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: DHT22 temp/humidity sensor often fails to read

Mon May 21, 2018 9:49 am

davidecibel wrote:
Mon May 21, 2018 9:38 am
I've tried to change the voltage to 5.5v
Note that Pi GPIO's are not 5V tolerant and you may cause permanent and irreparable damage to your Pi when a voltage above 3V3 is applied to any GPIO I/O pin.

The DHT sensors use a proprietary protocol using a single bi-directional signal line with rather fast bit timings ( in region of the tens of microseconds ) so it may be an issue with the software, its timing, or even the way GPIO interaction is handled. It may be worth contacting the author of the code to see if they can shed any light on the issue.

davidecibel
Posts: 5
Joined: Wed Apr 25, 2018 8:17 am

Re: DHT22 temp/humidity sensor often fails to read

Mon May 21, 2018 9:53 am

hippy wrote:
Mon May 21, 2018 9:49 am
davidecibel wrote:
Mon May 21, 2018 9:38 am
I've tried to change the voltage to 5.5v
Note that Pi GPIO's are not 5V tolerant and you may cause permanent and irreparable damage to your Pi when a voltage above 3V3 is applied to any GPIO I/O pin.
Thanks for the reply. Please forgive my ignorance, but why does the GPIO have 5V pins, then? I'll switch back to 3.3v when I get back home, anyways. In the meanwhile I'll try github for my question, thanks.

hippy
Posts: 3044
Joined: Fri Sep 09, 2011 10:34 pm
Location: UK

Re: DHT22 temp/humidity sensor often fails to read

Mon May 21, 2018 10:52 am

davidecibel wrote:
Mon May 21, 2018 9:53 am
Please forgive my ignorance, but why does the GPIO have 5V pins, then?
The GPIO connector provides power plus I/O pin connections. 5V is supplied for components and circuits attached which require 5V but all I/O pin connections must still be 3V3.

The 5V power output is capable of supplying more current than the 3V3 power output can so this suits circuitry which may have higher current requirements than the 3V3 power output can deliver. In those cases a circuit designer will usually use the 5V output and include a 5V to 3V3 regulator on their circuit board.

OldPCGuy
Posts: 81
Joined: Mon Jan 02, 2017 4:53 pm
Location: Detroit Michigan

Re: DHT22 temp/humidity sensor often fails to read

Mon May 21, 2018 11:13 pm

For that sensor I use the PIGPIO libraries vs the default gpio.

http://abyz.me.uk/rpi/pigpio/download.html

I read somewhere someone was seeing missed readings using the gpio over long periods of time and they switched to PIGPIO. I don't know if it was true or not, but I can say I have no issues running that sensor with PIGPIO on a data logger running for days on end.

In the for what its worth column I do run the default I2C gpio for DS18B20.

davidecibel
Posts: 5
Joined: Wed Apr 25, 2018 8:17 am

Re: DHT22 temp/humidity sensor often fails to read

Tue May 22, 2018 7:20 am

OldPCGuy wrote:
Mon May 21, 2018 11:13 pm
For that sensor I use the PIGPIO libraries vs the default gpio.

http://abyz.me.uk/rpi/pigpio/download.html

I read somewhere someone was seeing missed readings using the gpio over long periods of time and they switched to PIGPIO. I don't know if it was true or not, but I can say I have no issues running that sensor with PIGPIO on a data logger running for days on end.

In the for what its worth column I do run the default I2C gpio for DS18B20.
Thanks for the suggestion. I have asked on the manufacturer forums (https://forums.adafruit.com/viewtopic.php?f=19&t=135884) and apparently is not uncommon for it to fail readings, so since I'm already ignoring them I reckon I shouldn't bother too much. Still, I'm tempted to see if readings will fail less often with these libraries, so a quick question.

Do I need to uninstall something before I install pigpio with apt-get, or can I just run

Code: Select all

sudo apt-get update
sudo apt-get install pigpio python-pigpio python3-pigpio
sudo pigpiod
and it will work?

OldPCGuy
Posts: 81
Joined: Mon Jan 02, 2017 4:53 pm
Location: Detroit Michigan

Re: DHT22 temp/humidity sensor often fails to read

Tue May 22, 2018 11:15 pm

No need to uninstall anything.

Just install per the site instructions. What you show looks correct if memory serves me.

Here are some links to sites I pulled info on using the PIGPIO.

viewtopic.php?f=37&t=86771

https://www.rototron.info/dht22-tutoria ... pberry-pi/

And the PIGPIO site has DHT22 sample code also.

Good Luck.

Return to “Python”

Who is online

Users browsing this forum: No registered users and 11 guests