This script works from https://randomnerdtutorials.com/raspber ... 22-python/ but once you stop it, you get an error not being able to connect to GPIO4 again if you try to start the script again. How do I reset the GPIO 4 pin to make this work without resetting my Rpi each time?
error is:
Unable to set line 4 to input
error is:
Unable to set line 4 to input
Code:
# Complete Project Details: https://RandomNerdTutorials.com/raspberry-pi-dht11-dht22-python/# Based on Adafruit_CircuitPython_DHT Library Exampleimport timeimport boardimport adafruit_dht# Sensor data pin is connected to GPIO 4# = adafruit_dht.DHT22(board.D4)# Uncomment for DHT11sensor = adafruit_dht.DHT11(board.D4)#sensor.exit()while True: try: # Print the values to the serial port temperature_c = sensor.temperature temperature_f = temperature_c * (9 / 5) + 32 humidity = sensor.humidity print("Temp={0:0.1f}ºC, Temp={1:0.1f}ºF, Humidity={2:0.1f}%".format(temperature_c, temperature_f, 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) continue except Exception as error: sensor.exit() raise error time.sleep(3.0)
Statistics: Posted by eflwi — Mon Nov 25, 2024 4:17 am