🎄⛄❄️🎁 It's beginning to look a lot like ADABOX-mas! The next ADABOX from Adafruit ships soon! Get yours now, or give as a gift! 🎄⛄❄️🎁
0

DHT11 Sensor with adafruit_dht error
Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.

DHT11 Sensor with adafruit_dht error

by ameeruak on Fri Nov 08, 2019 7:55 am

I am using the DHT 11 sensor on raspberry pi but when I set the board.D4 the error it gives is
Unable to set Line 4 to input


What is the possible cause for this?

ameeruak
 
Posts: 2
Joined: Fri Nov 08, 2019 7:53 am

Re: DHT11 Sensor with adafruit_dht error

by jerryn on Fri Nov 08, 2019 11:06 am

I just ran this example without any problem:

Code: Select all | TOGGLE FULL SIZE
 
import time
import board
import adafruit_dht

# Initial the dht device, with data pin connected to:
dhtDevice = adafruit_dht.DHT11(board.D4)

while True:
    try:
        # Print the values to the serial port
        temperature_c = dhtDevice.temperature
        temperature_f = temperature_c * (9 / 5) + 32
        humidity = dhtDevice.humidity
        print("Temp: {:.1f} F / {:.1f} C    Humidity: {}% "
              .format(temperature_f, temperature_c, humidity))

    except RuntimeError as error:
        # Errors happen fairly often, DHT's are hard to read, just keep going
        print(error.args[0])

    time.sleep(2.0)


Did you install “Blinka” following this guide ? https://learn.adafruit.com/circuitpython-on-raspberrypi-linux

jerryn
 
Posts: 1052
Joined: Sat Sep 14, 2013 9:05 am

Re: DHT11 Sensor with adafruit_dht error

by ameeruak on Fri Nov 08, 2019 4:09 pm

Actually it runs once but when I run it on the same pin again it dosent work, something like it maybe does not GPIO.cleanup() the pins. I tried doing the cleanup in the code but I guess the pin still stays occupied and dosent work for some reason.

Are you facing the same problem if you rerun the code on the same pin?

ameeruak
 
Posts: 2
Joined: Fri Nov 08, 2019 7:53 am

Re: DHT11 Sensor with adafruit_dht error

by jerryn on Fri Nov 08, 2019 4:55 pm

No. It works repeatedly for me.

jerryn
 
Posts: 1052
Joined: Sat Sep 14, 2013 9:05 am

Re: DHT11 Sensor with adafruit_dht error

by jerryn on Fri Nov 08, 2019 4:58 pm

However -- I do get that error if I try to run two instances of the code at the same time!
I usually terminate the running program with a Control-C

Do you possibly have a old copy still running?

jerryn
 
Posts: 1052
Joined: Sat Sep 14, 2013 9:05 am

Please be positive and constructive with your questions and comments.