Software source reference
"""
Initiates the heating loop for the SHT45 sensor if the measured humidity is above 98% for more than ten minutes
after the last heating loop or boot. This is done to prevent the accumulation of condensed water on the sensor.
Authors:
Min Tai Yap
"""
import board
import adafruit_sht4x
import busio
import time
from adafruit_blinka.microcontroller.bcm283x.pin import Pin
import asyncio
import os
# Heater function with non-blocking 1-minute operation
[docs]
async def sht45_heat_nb(i2c, interval):
"""
Initializes the SHT45 sensor driver and initiates the heating loop for one minute.
:param i2c: A busio.I2C object for the communication on the I2C bus
:param interval: Number of times the 1s-heating mode of SHT45 sensor is activated
:returns: None upon successful heating, a tuple of -1s when no sensor could be found
"""
try:
sht = adafruit_sht4x.SHT4x(i2c)
print("Heater enabled. Running for 1 minute...")
# Loop for 1 minute with non-blocking 1-second intervals
interval_use = interval - 1
for _ in range(interval_use):
sht.mode = adafruit_sht4x.Mode.HIGHHEAT_1S
# TODO: To be consistent with the documentation, this should maybe be set to 1.0, currently it may only run the heating loop
# half as long as specified
await asyncio.sleep(0.5) # Non-blocking wait for 0.5 second
print("Heater disabled after 1 minute.")
except Exception as e:
print(f"I2C device of SHT45 not found: {e}")
return -1, -1
