# from sensors.lib import grove_i2c_temp_hum_mini # t= grove_i2c_temp_hum_mini.th02() # def get_temperature(): # """Get the temperature in Celsius from the TH02 sensor.""" # # try: # return t.getTemperature() # # except Exception as e: # # print(f"Error reading temperature: {e}") # # return None # def get_humidity(): # """Get the humidity in percentage from the TH02 sensor.""" # # try: # return t.getHumidity() # # except Exception as e: # # print(f"Error reading humidity: {e}") # # return None # import seeed_dht # sensor = seeed_dht.DHT("11", 4) # DHT11 sensor on GPIO pin 4 # def get_humidity_and_temperature(): # humi, temp = sensor.read() # return humi, temp # import sensors.lib.grovepi as grovepi import grovepi import math from sensors.lock import grove_lock # Connect the Grove Temperature & Humidity Sensor Pro to digital port D3 # This example uses the blue colored sensor. # SIG,NC,VCC,GND sensor = 3 # The Sensor goes on digital port 3. # temp_humidity_sensor_type # Grove Base Kit comes with the blue sensor. blue = 0 # The Blue colored sensor. white = 1 # The White colored sensor. def get_temperature_and_humidity(): with grove_lock: [temp,humidity] = grovepi.dht(sensor,blue) if math.isnan(temp) == False and math.isnan(humidity) == False: return temp, humidity else: print("Error reading from DHT sensor") return None, None