New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Raspberry Pi 3 and Adafruit_Python_DHT #44

Closed
tcalbrecht opened this Issue Apr 10, 2016 · 10 comments

Comments

Projects
None yet
10 participants
@tcalbrecht

tcalbrecht commented Apr 10, 2016

Greetings.

I'm having a problem with the Adafruit DHT Python code.

  • Installed all the required packages.
  • sudo python setup.py install
  • Connected the DHT11 signal to GPIO04 (pin 7).
  • Tried to run:
    sudo ./AdafruitDHT.py 11 4
    and (after a few seconds) got:
    Failed to get reading. Try again!

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.

  • pi@PI3:~/src/DHT11 $ uname -a
    Linux PI3 4.1.19-v7+ #858 SMP Tue Mar 15 15:56:00 GMT 2016 armv7l GNU/Linux

Thanks.

@JockeNasvall

This comment has been minimized.

Show comment
Hide comment
@JockeNasvall

JockeNasvall Apr 25, 2016

I have the same problem. Any plans to support pi 3?

JockeNasvall commented Apr 25, 2016

I have the same problem. Any plans to support pi 3?

@tdicola

This comment has been minimized.

Show comment
Hide comment
@tdicola

tdicola Apr 25, 2016

Contributor

Hrm I can't repro any issues on the Pi 3, just tried reading an AM2302 and it works great with the current lib and the latest Raspbian Jessie. Try installing a fresh SD card image and the library again to check there isn't something else going on.

Also make sure you don't have a lot of CPU intensive things running in the background. The library works by trying to very quickly read the output of the sensor but it can get tripped up if the kernel is interrupting it to let processor intensive tasks run.

And one last little thing to check is how you're powering the device. Give it 3.3V power from the Pi instead of 5V power--the signal line has a pull-up resistor so you don't want to have it pull up to 5V and then feed that into an input on the Pi.

Contributor

tdicola commented Apr 25, 2016

Hrm I can't repro any issues on the Pi 3, just tried reading an AM2302 and it works great with the current lib and the latest Raspbian Jessie. Try installing a fresh SD card image and the library again to check there isn't something else going on.

Also make sure you don't have a lot of CPU intensive things running in the background. The library works by trying to very quickly read the output of the sensor but it can get tripped up if the kernel is interrupting it to let processor intensive tasks run.

And one last little thing to check is how you're powering the device. Give it 3.3V power from the Pi instead of 5V power--the signal line has a pull-up resistor so you don't want to have it pull up to 5V and then feed that into an input on the Pi.

@tdicola tdicola closed this Apr 25, 2016

@TiagoGouvea

This comment has been minimized.

Show comment
Hide comment
@TiagoGouvea

TiagoGouvea Dec 21, 2016

I'm getting on raspberry pi 3:

  File "dht11_test.py", line 21, in <module>
    umid, temp = Adafruit_DHT.read_retry(sensor, pino_sensor);
  File "/home/pi/scripts/Adafruit_DHT/common.py", line 92, in read_retry
    humidity, temperature = read(sensor, pin, platform)
  File "/home/pi/scripts/Adafruit_DHT/common.py", line 78, in read
    platform = get_platform()
  File "/home/pi/scripts/Adafruit_DHT/common.py", line 53, in get_platform
    from . import Raspberry_Pi_2
  File "/home/pi/scripts/Adafruit_DHT/Raspberry_Pi_2.py", line 22, in <module>
    from . import Raspberry_Pi_2_Driver as driver
ImportError: cannot import name Raspberry_Pi_2_Driver````

even using --force-pi2 on setup

TiagoGouvea commented Dec 21, 2016

I'm getting on raspberry pi 3:

  File "dht11_test.py", line 21, in <module>
    umid, temp = Adafruit_DHT.read_retry(sensor, pino_sensor);
  File "/home/pi/scripts/Adafruit_DHT/common.py", line 92, in read_retry
    humidity, temperature = read(sensor, pin, platform)
  File "/home/pi/scripts/Adafruit_DHT/common.py", line 78, in read
    platform = get_platform()
  File "/home/pi/scripts/Adafruit_DHT/common.py", line 53, in get_platform
    from . import Raspberry_Pi_2
  File "/home/pi/scripts/Adafruit_DHT/Raspberry_Pi_2.py", line 22, in <module>
    from . import Raspberry_Pi_2_Driver as driver
ImportError: cannot import name Raspberry_Pi_2_Driver````

even using --force-pi2 on setup
@TiagoGouvea

This comment has been minimized.

Show comment
Hide comment
@TiagoGouvea

TiagoGouvea Dec 21, 2016

In fact it just my low knowlegde on python.. some related to folders and files locations... :(

TiagoGouvea commented Dec 21, 2016

In fact it just my low knowlegde on python.. some related to folders and files locations... :(

@deepakkusahoo

This comment has been minimized.

Show comment
Hide comment
@deepakkusahoo

deepakkusahoo Jul 1, 2017

@TiagoGouvea How did you manage to resolve this? I am also getting the exact same error.

deepakkusahoo commented Jul 1, 2017

@TiagoGouvea How did you manage to resolve this? I am also getting the exact same error.

@manfye

This comment has been minimized.

Show comment
Hide comment
@manfye

manfye Sep 3, 2017

@TiagoGouvea i also have similar issue, how to solve it?

manfye commented Sep 3, 2017

@TiagoGouvea i also have similar issue, how to solve it?

@Cartmanishere

This comment has been minimized.

Show comment
Hide comment
@Cartmanishere

Cartmanishere Sep 13, 2017

For anyone else facing the same issue that @TiagoGouvea mentioned.
Try to run your program from outside the Adafruit_DHT directory that was cloned.
It happens because when you run -
import Adafruit_DHT
It imports the Adafruit_DHT folder in your current directory instead of the one installed in your site-packages directory.
When run from anywhere else, it is working fine.
Hope this helped.

Cartmanishere commented Sep 13, 2017

For anyone else facing the same issue that @TiagoGouvea mentioned.
Try to run your program from outside the Adafruit_DHT directory that was cloned.
It happens because when you run -
import Adafruit_DHT
It imports the Adafruit_DHT folder in your current directory instead of the one installed in your site-packages directory.
When run from anywhere else, it is working fine.
Hope this helped.

@teerna

This comment has been minimized.

Show comment
Hide comment
@teerna

teerna Jan 18, 2018

I got the same error in my R Pi 3 and I found a fix for it after some research.

So for those getting an error such as this one:
Traceback (most recent call last):
File "simpletest.py", line 39, in
humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
File "/home/pi/Adafruit_Python_DHT/Adafruit_DHT/common.py", line 94, in read_retry
humidity, temperature = read(sensor, pin, platform)
File "/home/pi/Adafruit_Python_DHT/Adafruit_DHT/common.py", line 80, in read
platform = get_platform()
File "/home/pi/Adafruit_Python_DHT/Adafruit_DHT/common.py", line 55, in get_platform
from . import Raspberry_Pi_2
File "/home/pi/Adafruit_Python_DHT/Adafruit_DHT/Raspberry_Pi_2.py", line 22, in
from . import Raspberry_Pi_2_Driver as driver
ImportError: cannot import name Raspberry_Pi_2_Driver

Here is the fix(as per a comment by Mr Bogd):

  1. Use sudo python3 setup.py install during the setup installation as you are more likely to be running Python 2 but the codes require Python 3.

  2. After the setup, run your .py file in any directory(home or any other) apart from the Adafruit_Python_DHT directory.
    (Use the command cp yourpythonfilename.py yourdirectoryname/ to copy the file to your desired directory where yourpythonfilename is the name of your python file and yourdirectoryname is the name of your directory you wish to copy the file to).
    This is because the python file imports the Adafruit_DHT directory(through this line: import Adafruit_DHT) so it should not be in the same directory.

teerna commented Jan 18, 2018

I got the same error in my R Pi 3 and I found a fix for it after some research.

So for those getting an error such as this one:
Traceback (most recent call last):
File "simpletest.py", line 39, in
humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
File "/home/pi/Adafruit_Python_DHT/Adafruit_DHT/common.py", line 94, in read_retry
humidity, temperature = read(sensor, pin, platform)
File "/home/pi/Adafruit_Python_DHT/Adafruit_DHT/common.py", line 80, in read
platform = get_platform()
File "/home/pi/Adafruit_Python_DHT/Adafruit_DHT/common.py", line 55, in get_platform
from . import Raspberry_Pi_2
File "/home/pi/Adafruit_Python_DHT/Adafruit_DHT/Raspberry_Pi_2.py", line 22, in
from . import Raspberry_Pi_2_Driver as driver
ImportError: cannot import name Raspberry_Pi_2_Driver

Here is the fix(as per a comment by Mr Bogd):

  1. Use sudo python3 setup.py install during the setup installation as you are more likely to be running Python 2 but the codes require Python 3.

  2. After the setup, run your .py file in any directory(home or any other) apart from the Adafruit_Python_DHT directory.
    (Use the command cp yourpythonfilename.py yourdirectoryname/ to copy the file to your desired directory where yourpythonfilename is the name of your python file and yourdirectoryname is the name of your directory you wish to copy the file to).
    This is because the python file imports the Adafruit_DHT directory(through this line: import Adafruit_DHT) so it should not be in the same directory.

@Lynexo

This comment has been minimized.

Show comment
Hide comment
@Lynexo

Lynexo Mar 16, 2018

How exactly do I do this @Cartmanishere ?

Lynexo commented Mar 16, 2018

How exactly do I do this @Cartmanishere ?

@edgarbc

This comment has been minimized.

Show comment
Hide comment
@edgarbc

edgarbc Sep 12, 2018

Thank you! This worked for me.

I got the same error in my R Pi 3 and I found a fix for it after some research.

So for those getting an error such as this one:
Traceback (most recent call last):
File "simpletest.py", line 39, in
humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
File "/home/pi/Adafruit_Python_DHT/Adafruit_DHT/common.py", line 94, in read_retry
humidity, temperature = read(sensor, pin, platform)
File "/home/pi/Adafruit_Python_DHT/Adafruit_DHT/common.py", line 80, in read
platform = get_platform()
File "/home/pi/Adafruit_Python_DHT/Adafruit_DHT/common.py", line 55, in get_platform
from . import Raspberry_Pi_2
File "/home/pi/Adafruit_Python_DHT/Adafruit_DHT/Raspberry_Pi_2.py", line 22, in
from . import Raspberry_Pi_2_Driver as driver
ImportError: cannot import name Raspberry_Pi_2_Driver

Here is the fix(as per a comment by Mr Bogd):

1. Use `sudo python3 setup.py` install during the setup installation as you are more likely to be running Python 2 but the codes require Python 3.

2. After the setup, run your .py file in any directory(home or any other) apart from the Adafruit_Python_DHT directory.
   (Use the command `cp yourpythonfilename.py yourdirectoryname/` to copy the file to your desired directory where yourpythonfilename is the name of your python file and yourdirectoryname is the name of your directory you wish to copy the file to).
   This is because the python file imports the Adafruit_DHT directory(through this line: `import Adafruit_DHT`) so it should not be in the same directory.

edgarbc commented Sep 12, 2018

Thank you! This worked for me.

I got the same error in my R Pi 3 and I found a fix for it after some research.

So for those getting an error such as this one:
Traceback (most recent call last):
File "simpletest.py", line 39, in
humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
File "/home/pi/Adafruit_Python_DHT/Adafruit_DHT/common.py", line 94, in read_retry
humidity, temperature = read(sensor, pin, platform)
File "/home/pi/Adafruit_Python_DHT/Adafruit_DHT/common.py", line 80, in read
platform = get_platform()
File "/home/pi/Adafruit_Python_DHT/Adafruit_DHT/common.py", line 55, in get_platform
from . import Raspberry_Pi_2
File "/home/pi/Adafruit_Python_DHT/Adafruit_DHT/Raspberry_Pi_2.py", line 22, in
from . import Raspberry_Pi_2_Driver as driver
ImportError: cannot import name Raspberry_Pi_2_Driver

Here is the fix(as per a comment by Mr Bogd):

1. Use `sudo python3 setup.py` install during the setup installation as you are more likely to be running Python 2 but the codes require Python 3.

2. After the setup, run your .py file in any directory(home or any other) apart from the Adafruit_Python_DHT directory.
   (Use the command `cp yourpythonfilename.py yourdirectoryname/` to copy the file to your desired directory where yourpythonfilename is the name of your python file and yourdirectoryname is the name of your directory you wish to copy the file to).
   This is because the python file imports the Adafruit_DHT directory(through this line: `import Adafruit_DHT`) so it should not be in the same directory.

@adafruit adafruit deleted a comment from Gaurav70042 Sep 18, 2018

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment