DHT22 Adafruit_DHT sensor import error
So, I correctly connected my DHT22 humidity sensor to my BeagleBone Black Rev C. I am running Mavericks OS on my MacBook Pro and I followed the directions provided by Adafruit on how to use my DHT22
The website I used was pretty clear: https://learn.adafruit.com/dht-humidity-sensing-on-raspberry-pi-with-gdocs-logging/software-install-updated
Also the github files are cloned here: https://github.com/adafruit/Adafruit_Python_DHT
I entered the following lines:
git clone https://github.com/adafruit/Adafruit_Python_DHT.git
cd Adafruit_Python_DHT
sudo apt-get upgrade
sudo apt-get install build-essential python-dev
sudo python setup.py install
cd examples
sudo ./AdafruitDHT.py 22 P8_11
I am successful until the last line. After entering this last line (sudo./AdafruitDHT.py 22 P8_11) the following error message appears:
Traceback (most recent call last):
File "./AdafruitDHT.py", line 23, in <module>
import Adafruit_DHT
ImportError: No module named Adafruit_DHT
I know there is an Adafruit_DHT file somewhere because when I am in the Adafruit_Python_DHT directory I get this:
root@beaglebone:~/Adafruit_Python_DHT# ls
Adafruit_DHT examples ez_setup.py ez_setup.pyc LICENSE README.md setup.py source
I tried reinstalling setup.py but the result is the same.
I've followed all the directions that Adafrut has suggested, but I just can't get past it. Any idea what is going on? This looks like a simple problem, but it is one of the main obstacles in getting readings from my DHT22. If there is more information needed to answer this problem, please let me know.
source to share
It seems that your script cannot find the Adafruit_DHT module. There are two ways.
-
Run the file in terminal as "Python Adafruit_Python_DHT"
-
Add the following code to the first line of your script. Should I put #! (shebang) in Python scripts and what form should it take?
source to share
Okay, try running this script with "sudo".
import sys
import Adafruit_DHT
def main():
sensor_args = { '11': Adafruit_DHT.DHT11,
'22': Adafruit_DHT.DHT22,
'2302': Adafruit_DHT.AM2302 }
if len(sys.argv) == 3 and sys.argv[1] in sensor_args:
sensor = sensor_args[sys.argv[1]]
pin = sys.argv[2]
else:
print 'usage: sudo ./Adafruit_DHT.py [11|22|2302] GPIOpin#'
print 'example: sudo ./Adafruit_DHT.py 2302 4 - Read from an AM2302 connected to GPIO #4'
sys.exit(1)
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 __name__ == '__main__':
main()
source to share