adafruit / adafruit_python_dht Goto Github PK
View Code? Open in Web Editor NEWPython library to read the DHT series of humidity and temperature sensors on a Raspberry Pi or Beaglebone Black.
License: MIT License
Python library to read the DHT series of humidity and temperature sensors on a Raspberry Pi or Beaglebone Black.
License: MIT License
Hi ,
i was trying to run the code on the Raspberry pi zero w , and even if i can install it with forcing the pi option
since it can't detect what platform is that when trying to use the code i get the following error :
Traceback (most recent call last):
File "/home/pi/Scripts/Live-Temperature-DHT11/AdafruitDHT.py", line 41, in
humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
File "build/bdist.linux-armv6l/egg/Adafruit_DHT/common.py", line 91, in read_retry
File "build/bdist.linux-armv6l/egg/Adafruit_DHT/common.py", line 77, in read
File "build/bdist.linux-armv6l/egg/Adafruit_DHT/common.py", line 60, in get_platform
RuntimeError: Unknown platform.
so the work around was to copy the lib dir Adafruit_DHT to my script dir , and to made the following change in common.py
def get_platform():
"""Return a DHT platform interface for the currently detected platform."""
plat = platform_detect.platform_detect()
plat = platform_detect.RASPBERRY_PI <<<<<<<<<<<<<
if plat == platform_detect.RASPBERRY_PI:
# Check for version 1 or 2 of the pi.
version = platform_detect.pi_version()
version = 1 <<<<<<<<<<<<<<<<<
if version == 1:
from . import Raspberry_Pi
return Raspberry_Pi
elif version == 2:
from . import Raspberry_Pi_2
return Raspberry_Pi_2
else:
the question can you create an official solution for this please , thanks .....
Raspberry 1 pi model B uncompatible with AM2302
Traceback (most recent call last):
File "./AdafruitDHT.py", line 41, in
humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
File "build/bdist.linux-armv6l/egg/Adafruit_DHT/common.py", line 90, in read_retry
File "build/bdist.linux-armv6l/egg/Adafruit_DHT/common.py", line 77, in read
File "build/bdist.linux-armv6l/egg/Adafruit_DHT/Raspberry_Pi.py", line 34, in read
RuntimeError: Error accessing GPIO.
It works with old commit 9e8109b .
Every time I ask for temperature and humidity, no decimal is returned.
Only exact value. It's correct?
sudo ./AdafruitDHT.py 11 4
Temp=22.0 Humidity=35.0
It seems that this library may not work on Raspbian stretch; I recently upgraded from jessie, and it seems it hasn't worked since then with my AM2302.
Platform/operating system (i.e. Raspberry Pi with Raspbian operating system,
Windows 32-bit, Windows 64-bit, Mac OSX 64-bit, etc.): Raspberry Pi B+ (Rev 0010), Raspbian 9.1 (stretch)
Python version (run python -version
or python3 -version
): Python 2.7.13
Error message you are receiving, including any Python exception traces:
pi@rpi-01:~/git/Adafruit_Python_DHT$ time python ./examples/simpletest.py
Failed to get reading. Try again!
real 0m44.628s
user 0m6.430s
sys 0m0.410s
simpletest.py
, adjusted for my particular hardware setup:pi@rpi-01:~/git/Adafruit_Python_DHT$ git diff
diff --git a/examples/simpletest.py b/examples/simpletest.py
index 06c4d9e..9849772 100644
--- a/examples/simpletest.py
+++ b/examples/simpletest.py
@@ -24,15 +24,17 @@ import Adafruit_DHT
# Sensor should be set to Adafruit_DHT.DHT11,
# Adafruit_DHT.DHT22, or Adafruit_DHT.AM2302.
-sensor = Adafruit_DHT.DHT22
+#sensor = Adafruit_DHT.DHT22
+sensor = Adafruit_DHT.AM2302
# Example using a Beaglebone Black with DHT sensor
# connected to pin P8_11.
-pin = 'P8_11'
+#pin = 'P8_11'
# Example using a Raspberry Pi with DHT sensor
# connected to GPIO23.
#pin = 23
+pin = 4
# Try to grab a sensor reading. Use the read_retry method which will retry up
# to 15 times to get a sensor reading (waiting 2 seconds between each retry).
Hi,
I want to use a DHT22 sensor connected to the GPIO port of a RPi2. Is it possible to activate the built-in pull-up resistor?
The following code will set the pull-up resistor or Adafruit_DHT.read_retry will reset it?
import Adafruit_DHT
import RPi.GPIO as GPIO
sensor_pin = 4
sensor_type = Adafruit_DHT.DHT22
GPIO.setmode(GPIO.BCM)
GPIO.setup(sensor_pin, GPIO.IN, GPIO.PUD_UP)
humidity, temperature = Adafruit_DHT.read_retry(sensor_type, sensor_pin)
If the pull-up resistor is not working, humidity and temperature will be None or they will just have an incorrect value, like 23% and 24°C instead of 64% and 19°C?
Thanks
Hello,
this library didn't work if me using two sensor dht22 on my raspberry pi3 (raspbian, python2). My program only read one sensor. how to resolve it, thanks before.
code:
import Adafruit_DHT
while 1:
sensor = Adafruit_DHT.DHT22
pin = 13
pin2 = 26
humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
humidity2, temperature2 = Adafruit_DHT.read_retry(sensor, pin2)
if humidity != None and temperature != None :
print('Temp={0:0.1f}*C Humidity={1:0.1f}%'.format(temperature, humidity))
if humidity2 != None and temperature2 != None :
print('Temp2={0:0.1f}*C Humidity2={1:0.1f}%'.format(temperature2, humidity2))
else:
print('Failed to get reading. Try again!')
when execute the setup command, i'm getting this error
`
arm-linux-gnueabihf-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fno-strict-aliasing -D_FORTIFY_SOURCE=2 -g -fstack-protector-strong -Wformat -Werror=format-security -fPIC -I/usr/include/python2.7 -c source/_Raspberry_Pi_2_Driver.c -o build/temp.linux-armv7l-2.7/source/_Raspberry_Pi_2_Driver.o -std=gnu99
In file included from /usr/include/python2.7/Python.h:7:0,
from source/_Raspberry_Pi_2_Driver.c:21:
/usr/include/python2.7/patchlevel.h:1:1: warning: null character(s) ignored
^
In file included from /usr/include/python2.7/Python.h:9:0,
from source/_Raspberry_Pi_2_Driver.c:21:
/usr/include/python2.7/pymacconfig.h:1:1: warning: null character(s) ignored
^
In file included from /usr/include/python2.7/pyport.h:325:0,
from /usr/include/python2.7/Python.h:58,
from source/_Raspberry_Pi_2_Driver.c:21:
/usr/include/math.h:479:0: error: unterminated #ifndef
^
/usr/include/math.h:435:0: error: unterminated #ifdef
#ifdef __USE_ISOC99
^
In file included from /usr/include/python2.7/pyport.h:325:0,
from /usr/include/python2.7/Python.h:58,
from source/_Raspberry_Pi_2_Driver.c:21:
/usr/include/math.h:23:0: error: unterminated #ifndef
#ifndef _MATH_H
^
In file included from /usr/include/python2.7/Python.h:110:0,
from source/_Raspberry_Pi_2_Driver.c:21:
/usr/include/python2.7/pycapsule.h:1:1: warning: null character(s) ignored
^
In file included from /usr/include/python2.7/Python.h:139:0,
from source/_Raspberry_Pi_2_Driver.c:21:
/usr/include/python2.7/pystrtod.h:1:1: warning: null character(s) ignored
^
In file included from /usr/include/python2.7/pyfpe.h:131:0,
from /usr/include/python2.7/Python.h:156,
from source/_Raspberry_Pi_2_Driver.c:21:
/usr/include/math.h:479:0: error: unterminated #ifndef
^
/usr/include/math.h:435:0: error: unterminated #ifdef
#ifdef __USE_ISOC99
^
/usr/include/math.h:23:0: error: unterminated #ifndef
#ifndef _MATH_H
^
error: command 'arm-linux-gnueabihf-gcc' failed with exit status 1
`
raspberry pi 2
python 2.7.9
Would be nice to have a debug.py instead of having to edit
https://github.com/adafruit/Adafruit_Python_DHT/blob/master/source/Raspberry_Pi/pi_dht_read.c#L136
etc just to know if the hardware is dead or if it's a software issue.
Added pull request #16 to expose the debug information.
Is Python 3 support planned or already on its way?
It'd be really handy if this was uploaded to PyPi so the library can be easily installed with pip
. The setup.py
is already provided so it just needs uploading.
Hi and thanks for this nice little library!
I've wired up my Pi 2 with this variant of the DHT11 on GPIO 23 (http://www.kjell.com/se/sortiment/el-verktyg/elektronik/arduino/moduler/temperatur-och-luftfuktighetssensor-for-arduino-p87877#ProductDetailedInformation) it has a pre mounted 10kOhm resistor between data and vcc.
When running:
sudo ./AdafruitDHT.py 11 23
I only get the message:
Failed to get reading. Try again!
I've done this setup now two times with two different DHT11:s and two different RPI2:s and it's failing consistently.
Any ideas on what might be the problem?
Regards, Daniel
Thank you for opening an issue on an Adafruit Python library repository. To
improve the speed of resolution please review the following guidelines and
common troubleshooting steps below before creating the issue:
Do not use GitHub issues for troubleshooting projects and issues. Instead use
the forums at http://forums.adafruit.com to ask questions and troubleshoot why
something isn't working as expected. In many cases the problem is a common issue
that you will more quickly receive help from the forum community. GitHub issues
are meant for known defects in the code. If you don't know if there is a defect
in the code then start with troubleshooting on the forum first.
If following a tutorial or guide be sure you didn't miss a step. Carefully
check all of the steps and commands to run have been followed. Consult the
forum if you're unsure or have questions about steps in a guide/tutorial.
For Python/Raspberry Pi projects check these very common issues to ensure they don't apply:
If you are receiving an ImportError: No module named... error then a
library the code depends on is not installed. Check the tutorial/guide or
README to ensure you have installed the necessary libraries. Usually the
missing library can be installed with the pip
tool, but check the tutorial/guide
for the exact command.
Be sure you are supplying adequate power to the board. Check the specs of
your board and power in an external power supply. In many cases just
plugging a board into your computer is not enough to power it and other
peripherals.
Double check all soldering joints and connections. Flakey connections
cause many mysterious problems. See the guide to excellent soldering for examples of good solder joints.
If you're sure this issue is a defect in the code and checked the steps above
please fill in the following fields to provide enough troubleshooting information.
You may delete the guideline and text above to just leave the following details:
Platform/operating system (i.e. Raspberry Pi with Raspbian operating system,
Windows 32-bit, Windows 64-bit, Mac OSX 64-bit, etc.): INSERT PLATFORM/OPERATING
SYSTEM HERE
Python version (run python -version
or python3 -version
): INSERT PYTHON
VERSION HERE
Error message you are receiving, including any Python exception traces: INSERT
ERROR MESAGE/EXCEPTION TRACES HERE*
List the steps to reproduce the problem below (if possible attach code or commands
to run): LIST REPRO STEPS BELOW
The newest version of raspbian has been released and not longer requires the use of sudo to interface with the GPIO pins is there something that needs needs to be updated in the code to take advantage of this.
Hi,
I have an issue with the usage of the read_retry(sensor, pin) function.
I have imported Adafruit_DHT into a python script and I am using the read function from this script with:
humidity, temperature = Adafruit_DHT.read_retry(Adafruit_DHT.DHT22, gpiopin)
It reads out values correctly but whenever the function is called the whole program slows down heavily until the function is finished.
To clarify this, the program is running several threads and all running threads and the main slow down.
I just wrote a little script where you can see the issue:
import Adafruit_DHT # adafruit dht module for temp/humi sensor reading
import time
import threading
class Thread(threading.Thread): #class to enable threading
def __init__(self, target, *args):
self._target = target
self._args = args
threading.Thread.__init__(self)
def run(self):
while 1:
self._target(*self._args)
def read3dhts(): #read dhts every 2 seconds
time.sleep(2)
print ("reading")
humidity1, temperature1 = Adafruit_DHT.read_retry(Adafruit_DHT.DHT22, 16)
humidity2, temperature2 = Adafruit_DHT.read_retry(Adafruit_DHT.DHT22, 20)
humidity3, temperature3 = Adafruit_DHT.read_retry(Adafruit_DHT.DHT22, 21)
t1= Thread(read3dhts)
t1.daemon = True
t1.start() #run dht reading in a thread
while 1:
time.sleep(.1)
print ("Program Running")
If you run it you can see that the printing of "Program Running" significantly slows down when reading the sensor even though the reading runs in an own thread. I have read three of them to make the effect bigger, but if you only read one it is basicly the same. If you read out a pin that doesnt have a sensor at all it also slows down a little bit.
However when I take out the sensor reading function from my program and call the function from a second python script it does not slow down the original program anymore.
Any ideas how to solve this?
thanks in advance
Hi There,
I have a few raspberry pi's wired with DHT22 sensors. It would be very expensive for me to wire them all back up.
This is a working raspberry pi with raspbian:
root@localhost:~# python AdafruitDHT.py 22 17
Temp=24.2* Humidity=29.9%
The non working raspberry pi with rasbian is:
root@localhost:~# python AdafruitDHT.py 22 17
Traceback (most recent call last):
File "AdafruitDHT.py", line 41, in <module>
humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
File "/usr/local/lib/python2.7/dist-packages/Adafruit_DHT/common.py", line 90, in read_retry
humidity, temperature = read(sensor, pin, platform)
File "/usr/local/lib/python2.7/dist-packages/Adafruit_DHT/common.py", line 77, in read
return platform.read(sensor, pin)
File "/usr/local/lib/python2.7/dist-packages/Adafruit_DHT/Beaglebone_Black.py", line 206, in read
raise ValueError('Pin must be a valid GPIO identifier like P9_12 or GPIO1_28.')
ValueError: Pin must be a valid GPIO identifier like P9_12 or GPIO1_28.
The only difference between the two Raspberry Pis is that I ran rpi-update on one, which is now not working. The are both wired up identically, have the identical image (however I updated one).
My Wiring looks like this:
GPIO17 / Raspberry Pi Pin 11 - DHT22 Pin 2
+5VDC / Raspberry Pi Pin 2 - DHT22 Pin 1
GND / Raspberry Pi Pin 6 - DHT22 Pin 4
Hello
With an Arduino the same DHT is working but not on the BBB.
I add following lines in bbb_dht_read.c after: busy_wait_milliseconds(20);
busy_wait_milliseconds(20);
// Set pin to high before set as input (pull-up resistor can't so fast) HvL
bbb_mmio_set_high(pin);
and now is working fine ;-)
I have a Raspberry Pi 1 Model B 1.2 and the current code detects it as a Raspberry Pi 2 and then cannot talk to GPIO.
cat /proc/cpuinfo
processor : 0
model name : ARMv6-compatible processor rev 7 (v6l)
BogoMIPS : 697.95
Features : half thumb fastmult vfp edsp java tls
CPU implementer : 0x41
CPU architecture: 7
CPU variant : 0x0
CPU part : 0xb76
CPU revision : 7
Switching based on the Hardware field seems inaccurate as many Pi 1 use the 2835 platform.
Maybe just using the revision entry and following
https://elinux.org/RPi_HardwareHistory#Board_Revision_History
might be a better choice.
Hi!
I realise you only support python2, but I'm trying to fiddle with this on python3 inside a venv. And I can't install from pypi, however I can install from this git repo. Pypi hasn't been updated in a couple of years, I am hoping I may be able to convince you to give it a poke.
Cheers,
Pete.
Fron the examples and my testing, it appears that this library only supports using the GPIO.BCM pin numberings.
If you had an application that uses the GPIO.board numbering, it makes the code inconsistent.
Is there a way to use this library with the raspberry pi board pin numbers?
Using the standard libraries for DHT 11 / RPI / Python and GDocs (https://learn.adafruit.com/dht-humidity-sensing-on-raspberry-pi-with-gdocs-logging/overview) works perfectly.
The issue is that when the DHT sensor encounters temperatues below 0 degrees, the negative values are not captured or displayed. This same issue is encountered when the simpletest.py, AdafruitDHT.py or google_spreadsheet.py (yes - tested DHT11 in the freezer....), the lowest value captured was 1.
Raspberry Pi with Raspbian
Raspberry Pi reference 2016-09-23
Generated using pi-gen, https://github.com/RPi-Distro/pi-gen, 62406bad92ed23728f46711b3539c04c37dfb62c, stage2
Linux rpi1 4.4.21+ #911 Thu Sep 15 14:17:52 BST 2016 armv6l GNU/Linux
PRETTY_NAME="Raspbian GNU/Linux 8 (jessie)"
python -version
or python3 -version
):Python 2.7.9
No errors or traces, output reported as above
Put DHT11 in Freezer for 10 minutes, and keep running simple.py or the other standard scripts.
pi@rpi1:~/Adafruit_Python_DHT/examples $ sudo ./simple.py
Temp=1.0*C Humidity=18.0%
Lowest value of 1.0*C reported.
Similar issue reported here way back when: https://www.raspberrypi.org/forums/viewtopic.php?t=62467&p=464881
I'ml trying to use my DHT11 sensor.
When I simpletest.py file, like this
sudo python simpletest.py
I always have this error : Make sure program is run as root with sudo
Thank you for your help
Hi,
have you planned supporting OrangePi platform? I'm using happily DHT11's and BMP180 on and old RPi revision; I tried installing these python libraries on OrangePi... of course, they don't work. Adafruit-DHT.py raises errors accessing GPIO (line 90 read, line 77 read_retry). AFAYK, should they work? Maybe I just didn't identifiy correcltly GPIO pin?
Raspberry Pi with Raspbian operating system
Python version Python 3.4.2 & Python 2.7.9
sudo python setup.py install
http://pastebin.com/7qLjNYhN
I've written a version under Python3 for Raspberry and i'll publish it soon
Can this library please be released occasionally with tags created something like:
git tag v0.1.1 HEAD
Other projects such as home assistant use this lib and it would be nicer to use actual tagged tarballs vs random commits.
There is an error statement every time I try to run the commit.py
ImportError: cannot import name 'Raspberry_Pi_2_Driver
I am on Raspberry Pi 3, and I know you already made a patch for this, (I just recently got it so I have the patch.) I'm not sure how or why this is happening.
Hi!
I'm loading and running python scripts with Jython. Unfortunately, there seem to be compatibility issues between Jython and this library - I can't get scripts using this library to work with Jython.
Would there be a possiblity to resolve this problem?
Example of errors I get:
Exception in thread "Thread-1" Traceback (most recent call last): File "Scripts/getTempScript.py", line 20, in retrieveData humidity, temperature = Adafruit_DHT.read_retry(Adafruit_DHT.AM2302, 4) File "/usr/local/lib/python2.7/dist-packages/Adafruit_DHT-1.1.0-py2.7-linux-armv7l.egg/Adafrut_DHT/common.py", line 90, in read_retry File "/usr/local/lib/python2.7/dist-packages/Adafruit_DHT-1.1.0-py2.7-linux-armv7l.egg/Adafrut_DHT/common.py", line 76, in read File "/usr/local/lib/python2.7/dist-packages/Adafruit_DHT-1.1.0-py2.7-linux-armv7l.egg/Adafrut_DHT/common.py", line 59, in get_platform RuntimeError: Unknown platform.
If I hardcode the Raspberry 2 Type in the get_platform function, I get this error:
Exception in thread "Thread-1" Traceback (most recent call last): File "Scripts/getTempScript.py", line 20, in retrieveData humidity, temperature = Adafruit_DHT.read_retry(Adafruit_DHT.AM2302, 4) File "/usr/local/lib/python2.7/dist-packages/Adafruit_DHT-1.1.0-py2.7-linux-armv7l.egg/Adafrut_DHT/common.py", line 74, in read_retry File "/usr/local/lib/python2.7/dist-packages/Adafruit_DHT-1.1.0-py2.7-linux-armv7l.egg/Adafrut_DHT/common.py", line 60, in read File "/usr/local/lib/python2.7/dist-packages/Adafruit_DHT-1.1.0-py2.7-linux-armv7l.egg/Adafrut_DHT/common.py", line 42, in get_platform File "/usr/local/lib/python2.7/dist-packages/Adafruit_DHT-1.1.0-py2.7-linux-armv7l.egg/Adafrut_DHT/Raspberry_Pi_2.py", line 22, in <module> File "/usr/local/lib/python2.7/dist-packages/Adafruit_DHT-1.1.0-py2.7-linux-armv7l.egg/Adafrut_DHT/Raspberry_Pi_2_Driver.py", line 7, in <module> File "/usr/local/lib/python2.7/dist-packages/Adafruit_DHT-1.1.0-py2.7-linux-armv7l.egg/Adafrut_DHT/Raspberry_Pi_2_Driver.py", line 6, in bootstrap ImportError: No module named Adafruit_DHT.Raspberry_Pi_2_Driver
Thing is, I don't know at all how to fix this. It is probably an error concerning Jython only, but it would be kind of awesome if there was a possibility to resolve it by changing the library, too.
Kind regards
pi@raspberrypi1:~/Adafruit_Python_DHT/examples$ sudo ./AdafruitDHT.py 2302 18
Temp=12.0* Humidity=3287.7%
pi@raspberrypi1:~/Adafruit_Python_DHT/examples$ sudo ./AdafruitDHT.py 2302 18
Temp=12.0* Humidity=3287.7%
pi@raspberrypi1:~/Adafruit_Python_DHT/examples$ sudo ./AdafruitDHT.py 2302 18
Temp=12.0* Humidity=3287.8%
Raspberry Pi B+
Raspbian Jessie 4.1.11
Real temp ~ 24*, hum ~22%
Referring to examples/google_spreadsheet.py
I have a sample time set of 600 (ten minutes).
This results in an update every twenty minutes, as every second append requests always fails.
I suspect this is because the Google API login session expires in some time less than 5 minutes.
Two suggestions:
The sleep in the try/exception on line 125 should be static (e.g. 2), to allow a quicker retry.
At the very end of the script, I also added:
# force login if FREQUENCY_SECONDS is too high
if FREQUENCY_SECONDS > 120:
worksheet = None
Which eliminates the errors in the first place.
I don't know the "ideal" value of 120. I just know it is < 300.
Sometimes the DHT22 will crash and will never pull the pin low thereafter until it has been power cycled.
Please update the install instructions to use a GPIO instead of the 3v rail.
Please add logic to automatically power cycle the DHT22 if it fails to pull the pin low.
(for testing I made DHT_MAXCOUNT 10 times bigger and made DHT_ERROR_TIMEOUT_2 and 3 to distinguish where the timeout was happening)
Problem:
Traceback (most recent call last):
File "test_read.py", line 4, in <module>
print(Adafruit_Python_DHT.read_retry(Adafruit_Python_DHT.DHT22, 27))
AttributeError: 'module' object has no attribute 'read_retry'
Steps to reproduce:
git clone https://github.com/adafruit/Adafruit_Python_DHT.git
cd Adafruit_Python_DHT
I require it to work on python3, so we will install to python 2 and 3:
sudo python setup.py install
sudo python3 setup.py install # <---- note I'm installing to python 2 and 3
Verifying we can read the sensor:
cd ./Adafruit_Python_DHT/examples
sudo ./AdafruitDHT.py 22 27
Temp=20.0* Humidity=63.1%
Ok, so far so good.
Now, lets run it with python 3:
Temp=19.8* Humidity=63.6%
Now lets verify we're actually using python 3 inside the file we're running:
nano ./AdafruitDHT.py
Add:
import sys
print (sys.version)
Now lets run it again to make sure we're actually using python 3:
sysop@kivypie:~/Adafruit_Python_DHT/examples$ python3 AdafruitDHT.py 22 27
3.4.2 (default, Oct 19 2014, 13:31:11)
[GCC 4.9.1]
Temp=19.8* Humidity=63.7%
Perfect. So reading the sensor works on python3.
Now lets try it again, but now in a test file:
import Adafruit_Python_DHT
print(Adafruit_Python_DHT.read_retry(Adafruit_Python_DHT.DHT22, 27))
thats in test_read.py
in the home folder, and the Adafruit_Python_DHT folder is also in the home folder.
sysop@kivypie:~$ python3 test_read.py
Traceback (most recent call last):
File "test_read.py", line 4, in <module>
print(Adafruit_Python_DHT.read_retry(Adafruit_Python_DHT.DHT22, 27))
AttributeError: 'module' object has no attribute 'read_retry'
So the question is, why does it work on python3 in the example folder but not in my own file? I previously had this working great on python3 till I needed to reinstall the rpi OS and Adafruit_Python_DHT
From mail, a user suggested changing the logic to set the count threshold based on the length of the first 80us pulse sent by the sensor. From Bill's mail:
"The initial pulse from the device is 80µS according to the documentation and I think that is there to allow a controller to measure the time.
My change looks for "_count == -1" to indicate that it should self calibrate, so using something like "DHT dht(DHTPIN, DHTTYPE, -1);" to have it behave like this.
Here is the code to replace lines 147 to 154:
// ignore first 1 transition
if ( (i > 0) && (i%2 == 0)) {
// Is it the initial 80µS pulse?
if(i==2) {
// Should automatic calibration be used?
if(_count == -1) {
// 1st pulse is 80µS long, so the "1" pulse of 70µS
// should always be bigger than 1/2 of the counter
_count = counter / 2;
)
}
else {
// shove each bit into the storage bytes
data[j/8] <<= 1;
if (counter > _count)
data[j/8] |= 1;
j++;
}
}
"
Let's look at testing this change out and consider updating all the DHT libraries (Arduino, etc.) to use this kind of auto calibrating logic.
Hey there,
I've been playing around with this library, and realized that the sensor information isn't quite accurate. I'm getting a value, but the decimal part is always 0. The temperature will jump, for instance, from '25.0C' to '24.0C' and back to '25.0C'.
I'm using the DHT11 temperature sensor with the raspberry PI B+.
Given your simpletest (https://github.com/adafruit/Adafruit_Python_DHT/blob/master/examples/simpletest.py)
with the debug info here https://github.com/adafruit/Adafruit_Python_DHT/blob/master/source/Raspberry_Pi/pi_dht_read.c#L136
I'm get something like the following values :
pi@raspberrypi ~ $ sudo python sensor.py
Data: 0x1a 0x0 0x18 0x0 0x22
Data: 0x18 0x0 0x17 0x0 0x2f
Temp=23.0*C Humidity=24.0%
i've modified the following lines of the simpletest file
# sensor = Adafruit_DHT.DHT22
sensor = Adafruit_DHT.DHT11
AND
# pin = 'P8_11'
pin = 4
Issues with the current Raspbian update:
Linux raspberrypi 4.9.11+
Traceback (most recent call last): File "./AdafruitDHT.py", line 41, in <module> humidity, temperature = Adafruit_DHT.read_retry(sensor, pin) File "build/bdist.linux-armv6l/egg/Adafruit_DHT/common.py", line 90, in read_retry File "build/bdist.linux-armv6l/egg/Adafruit_DHT/common.py", line 76, in read File "build/bdist.linux-armv6l/egg/Adafruit_DHT/common.py", line 59, in get_platform RuntimeError: Unknown platform.
Thanks for fixing it.
Code runs perfectly fine with no errors etc. But it is unable to open the sheet. Please refer the code below. Unable to figure whats wrong here. Thanks!
import os
import ast
import requests, gspread
from oauth2client.client import SignedJwtAssertionCredentials
def authenticate_google_docs():
f = file(os.path.join('Shiva-c1c5516ecf00.p12'), 'rb')
SIGNED_KEY = f.read()
f.close()
scope = ['https://spreadsheets.google.com/feeds', 'https://docs.google.com/feeds']
credentials = SignedJwtAssertionCredentials('[email protected]', SIGNED_KEY, scope)
data = {
'refresh_token' : '241/ZLTD2DyOdiFJkN37mOZnmV-LtRu8wxY97o8Wn-nBkM4',
'client_id' : '2434760852908-5vi7v8ebilde26mvlran6ike982ovuhs.apps.googleusercontent.com',
'client_secret' : '24EDI-HPmWBjvoTlm_NzJkcBmp',
'grant_type' : 'refresh_token',
}
r = requests.post('https://accounts.google.com/o/oauth2/token', data = data)
credentials.access_token = ast.literal_eval(r.text)['access_token']
gc = gspread.authorize(credentials)
return gc
gc = authenticate_google_docs()
import pdb; pdb.set_trace()
sh = gc.open("Hero")
I tried sh=gc.open("Hero").sheet1 (didn't work either)
Hi,
I have trouble with the execution of a code, which reads data from a DHT11 sensor, when the installation of the library is done with the pip command. My Raspberry Pi is a model 3 and I realized that this version is not included in the code when detecting the platform (common.py file -> get_platform() function; platform_detect.py file -> pi_version() function). For this reason, RPi v3 is not recognized and the library returns to the default value (Beaglebone). The transfer of parameters is then of type String.
Please, the solution is to keep Pypi updated with the latest version of GitHub.
Information:
It's possible to add support for AM2301 ?
I installed using pip then remembered i needed to use pip3 instead. I uninstalled using pip but when I tried to install using pip3 i get the following errors. I traced the setup.py file and import and I'm not sure why it is unhappy.
`pi@BeeHiveRaspPi:~ $ pip3 install Adafruit_Python_DHT
Collecting Adafruit_Python_DHT
Using cached Adafruit_Python_DHT-1.1.2.tar.gz
Complete output from command python setup.py egg_info:
Traceback (most recent call last):
File "", line 1, in
File "/tmp/pip-build-ghg1_42x/Adafruit-Python-DHT/setup.py", line 5, in
import Adafruit_DHT.platform_detect as platform_detect
File "/tmp/pip-build-ghg1_42x/Adafruit-Python-DHT/Adafruit_DHT/init.py", line 21, in
from .common import DHT11, DHT22, AM2302, read, read_retry
File "/tmp/pip-build-ghg1_42x/Adafruit-Python-DHT/Adafruit_DHT/common.py", line 23, in
import platform_detect
ImportError: No module named 'platform_detect'
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-ghg1_42x/Adafruit-Python-DHT/
`
I also get the following similar error
pi@BeeHiveRaspPi:~/.local/lib/python3.5/site-packages/Adafruit_Python_DHT $ sudo python3 setup.py install Traceback (most recent call last): File "setup.py", line 5, in <module> import Adafruit_DHT.platform_detect as platform_detect File "/home/pi/.local/lib/python3.5/site-packages/Adafruit_Python_DHT/Adafruit_DHT/__init__.py", line 21, in <module> from .common import DHT11, DHT22, AM2302, read, read_retry File "/home/pi/.local/lib/python3.5/site-packages/Adafruit_Python_DHT/Adafruit_DHT/common.py", line 23, in <module> import platform_detect ImportError: No module named 'platform_detect'
root@jessie-rpi:~/Adafruit_Python_DHT/examples# python AdafruitDHT.py 11 4
Traceback (most recent call last):
File "AdafruitDHT.py", line 41, in
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. Make sure program is run as root with sudo!
I'm currently running as root, I also tried setting the gpio_base manually to 0x37200000 which is the correct address on Raspberry Pi 2 for the GPIO
Thank you for opening an issue on an Adafruit Python library repository. To
improve the speed of resolution please review the following guidelines and
common troubleshooting steps below before creating the issue:
Do not use GitHub issues for troubleshooting projects and issues. Instead use
the forums at http://forums.adafruit.com to ask questions and troubleshoot why
something isn't working as expected. In many cases the problem is a common issue
that you will more quickly receive help from the forum community. GitHub issues
are meant for known defects in the code. If you don't know if there is a defect
in the code then start with troubleshooting on the forum first.
If following a tutorial or guide be sure you didn't miss a step. Carefully
check all of the steps and commands to run have been followed. Consult the
forum if you're unsure or have questions about steps in a guide/tutorial.
For Python/Raspberry Pi projects check these very common issues to ensure they don't apply:
If you are receiving an ImportError: No module named... error then a
library the code depends on is not installed. Check the tutorial/guide or
README to ensure you have installed the necessary libraries. Usually the
missing library can be installed with the pip
tool, but check the tutorial/guide
for the exact command.
Be sure you are supplying adequate power to the board. Check the specs of
your board and power in an external power supply. In many cases just
plugging a board into your computer is not enough to power it and other
peripherals.
Double check all soldering joints and connections. Flakey connections
cause many mysterious problems. See the guide to excellent soldering for examples of good solder joints.
If you're sure this issue is a defect in the code and checked the steps above
please fill in the following fields to provide enough troubleshooting information.
You may delete the guideline and text above to just leave the following details:
Platform/operating system (i.e. Raspberry Pi with Raspbian operating system,
Windows 32-bit, Windows 64-bit, Mac OSX 64-bit, etc.): INSERT PLATFORM/OPERATING
SYSTEM HERE
Python version (run python -version
or python3 -version
): INSERT PYTHON
VERSION HERE
Error message you are receiving, including any Python exception traces: INSERT
ERROR MESAGE/EXCEPTION TRACES HERE*
List the steps to reproduce the problem below (if possible attach code or commands
to run): LIST REPRO STEPS BELOW
Is there a chance to update the lib to reflect also RPi3 as plattform?
Thank you.
Greetings.
I'm having a problem with the Adafruit DHT Python code.
The DHT11 sensor is working with C and the WiringPi library.
This is a Raspberry Pi 3, fresh Raspbian install, and all the latest software updates.
Thanks.
Scenario:
Expected: humidity and temperature reading will be same as previously(without mjpg_streamer)
Actual: readings are successful between 30-5 retries.
Other people also faced same issue Adafruit DHT temp/humid sensor. As I understand issue is that delayMicroseconds will not retrieve stable results with mjpg_stremer. SPI approach should be used instead.
Thank you for opening an issue on an Adafruit Python library repository. To
improve the speed of resolution please review the following guidelines and
common troubleshooting steps below before creating the issue:
pip
tool, but check the tutorial/guideIf you're sure this issue is a defect in the code and checked the steps above
please fill in the following fields to provide enough troubleshooting information.
You may delete the guideline and text above to just leave the following details:
python -version
or python3 -version
): INSERT PYTHONPlatform: Rasbperry Pi Model A with Raspbian Jessie
pi@tempercheck:~/Adafruit_Python_DHT$ python --version
Python 2.7.9
pi@tempercheck:~/Adafruit_Python_DHT$ sudo python setup.py install
Downloading https://pypi.python.org/packages/source/s/setuptools/setuptools-4.0.1.zip
Traceback (most recent call last):
File "setup.py", line 4, in
use_setuptools()
File "/home/pi/Adafruit_Python_DHT/ez_setup.py", line 145, in use_setuptools
return _do_download(version, download_base, to_dir, download_delay)
File "/home/pi/Adafruit_Python_DHT/ez_setup.py", line 119, in _do_download
to_dir, download_delay)
File "/home/pi/Adafruit_Python_DHT/ez_setup.py", line 287, in download_setuptools
downloader(url, saveto)
File "/home/pi/Adafruit_Python_DHT/ez_setup.py", line 209, in download_file_curl
_clean_check(cmd, target)
File "/home/pi/Adafruit_Python_DHT/ez_setup.py", line 169, in _clean_check
subprocess.check_call(cmd)
File "/usr/lib/python2.7/subprocess.py", line 540, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['curl', 'https://pypi.python.org/packages/source/s/setuptools/setuptools-4.0.1.zip', '--silent', '--output', '/home/pi/Adafruit_Python_DHT/setuptools-4.0.1.zip']' returned non-zero exit status 7
Steps to get here: followed directions on README.md (https://github.com/adafruit/Adafruit_Python_DHT)
Hi :-) i have a question , could you please help: How to run automatic after reboot the Raspberry Pi with DHT22 sensor
MANY MANY THANKS
Thank you for opening an issue on an Adafruit Python library repository. To
improve the speed of resolution please review the following guidelines and
common troubleshooting steps below before creating the issue:
Do not use GitHub issues for troubleshooting projects and issues. Instead use
the forums at http://forums.adafruit.com to ask questions and troubleshoot why
something isn't working as expected. In many cases the problem is a common issue
that you will more quickly receive help from the forum community. GitHub issues
are meant for known defects in the code. If you don't know if there is a defect
in the code then start with troubleshooting on the forum first.
If following a tutorial or guide be sure you didn't miss a step. Carefully
check all of the steps and commands to run have been followed. Consult the
forum if you're unsure or have questions about steps in a guide/tutorial.
For Python/Raspberry Pi projects check these very common issues to ensure they don't apply:
If you are receiving an ImportError: No module named... error then a
library the code depends on is not installed. Check the tutorial/guide or
README to ensure you have installed the necessary libraries. Usually the
missing library can be installed with the pip
tool, but check the tutorial/guide
for the exact command.
Be sure you are supplying adequate power to the board. Check the specs of
your board and power in an external power supply. In many cases just
plugging a board into your computer is not enough to power it and other
peripherals.
Double check all soldering joints and connections. Flakey connections
cause many mysterious problems. See the guide to excellent soldering for examples of good solder joints.
If you're sure this issue is a defect in the code and checked the steps above
please fill in the following fields to provide enough troubleshooting information.
You may delete the guideline and text above to just leave the following details:
Platform/operating system (i.e. Raspberry Pi with Raspbian operating system,
Windows 32-bit, Windows 64-bit, Mac OSX 64-bit, etc.): INSERT PLATFORM/OPERATING
SYSTEM HERE
Python version (run python -version
or python3 -version
): INSERT PYTHON
VERSION HERE
Error message you are receiving, including any Python exception traces: INSERT
ERROR MESAGE/EXCEPTION TRACES HERE*
List the steps to reproduce the problem below (if possible attach code or commands
to run): LIST REPRO STEPS BELOW
I've tested 2 DHT11 and 1 DHT22 devices. Both DHT11s show wrong readings on BBB, but on RPi they show correct readings. DHT22 works fine on both BBB and RPi. Is this known bug?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.