GrowSystem/dht22.py

36 lines
1008 B
Python

from dht import DHT22
from machine import ADC, Pin
class TemperatureHumiditySensor:
dht22_sensor_pin_int = -1
dht22_sensor = None
most_recent_values = []
def __init__(self, settings):
print("Hello from dht22 sensor class")
print(settings)
self.dht22_sensor_pin_int = settings['pin_int']
self.dht22_sensor = DHT22(Pin(self.dht22_sensor_pin_int, Pin.IN, Pin.PULL_UP))
def read(self):
try:
self.dht22_sensor.measure()
self.most_recent_values = [
{
'type': 'temperature',
'value': self.dht22_sensor.temperature(),
'unit': 'C'
},
{
'type': 'humidity',
'value': self.dht22_sensor.humidity(),
'unit': '%'
}
]
except OSError:
print('DHT22 Error reading temperature/humidity. Check wires')
print()