I tried to write a script that would output the dht 11 sensor data to a .txt
file.
I reviewed the standard examples given for the Adafruit library.
My code:
import time
import Adafruit_DHT
# infinite while loop
while True:
sensor = Adafruit_DHT.DHT11
pin = 4
humidity, temperature = Adafruit_DHT.read_retry(sensor, pin)
if humidity is not None and temperature is not None:
print('Temp={0:0.1f}* Humidity{1:0.1f}%'.format(temperature,humidity))
else:
print('Failed to get reading. Try again!')
time.sleep(5)
When I run it with Thonny IDE, I get the following error message:
Traceback (most recent call last):
File "/home/pi/Downloads/Sensor1/Adafruit_Python_DHT/examples/simpletest2loop.py", line 5, in <module>
import Adafruit_DHT
ImportError: No module named 'Adafruit_DHT'
I'm able to read the sensor from terminal using the command:
sudo ./AdafruitDHT.py 11 4
with another script listed in: https://tutorials-raspberrypi.com/raspberry-pi-measure-humidity-temperature-dht11-dht22/
I did some research, but I can't figure it out, I kindly ask if someone can help me to troubleshoot this.
Research:
I tried moving the file, but still doesn't work
- GPIO Error on Raspberry Pi when following Adafruit Tutorial
pi@raspberrypi:~/Downloads/Sensor1/Adafruit_Python_DHT/examples $ ls -altr total 28
-rw-r--r-- 1 pi pi 2035 Jul 5 15:28 simpletest.py
-rwxr-xr-x 1 pi pi 5715 Jul 5 15:28 google_spreadsheet.py
drwxr-xr-x 10 pi pi 4096 Jul 5 15:28 ..
-rwxr-xr-x 1 pi pi 2340 Jul 6 13:19 AdafruitDHT.py
drwxr-xr-x 2 pi pi 4096 Jul 13 14:08 .
-rwxrwxrwx 1 pi pi 1037 Jul 13 14:19 simpletest2loop.py <code>
Seems they are under same user and group. Do i have to copy the library to some folder?