from esp_pid import PID
from machine import I2C, Pin, PWM
import dht
from time import sleep
sensor = dht.DHT22(Pin(14))
pid = PID(1, 0.1, 0.05, setpoint=30)
hotend = Pin(32, Pin.OUT) #нагреватель
while True:
try:
sensor.measure()
temp = sensor.temperature()
hum = sensor.humidity()
out_pid = pid(temp)
print(out_pid)
if out_pid < 0:
hotend.value(0)
else:
hotend.value(1)
except OSError as e:
print('Failed to read sensor.')