It's been awhile, but I had a similar problem with a DHT22 when I first set up a weather station. I can't remember how I found the following but it may be a basis for what you need.
Here is how I have it postitioned in relation to the INIT function
Code:
#************************************************************************************************def clear_line_D22(): # If you get "Unable to set line 4 to input" then the background job libgpiod_pulsein # may be in runaway and need to be killed. This happens because the Python program was # simply STOPPED and did not end normally. # I can't find any adafruit_dht function to release D22 PROCNAME = "libgpiod_pulsein" if not ss.shore_air: return for proc in process_iter(): # check whether the process name matches if proc.name() == PROCNAME: if params.debug: print(log_time("clear_line_22")+"Found and killed process "+PROCNAME+" potentially holding line D22") proc.kill() return
Code:
#************************************************************************************************#def init_air_sensor(): global air_sensor success=False if not ss.shore_air: return True try: clear_line_D22() # See comments in function air_sensor = adafruit_dht.DHT22(board.D22) success=True except Exception as err: with open(params.log_file,"a") as f: f.write(log_time("init_air_sensor")+"Exception caught\n") print_exc(file=f) success=False return success
Statistics: Posted by DS256 — Mon Nov 25, 2024 12:04 pm