NodeMCU Projects: Difference between revisions

Content added Content deleted
Line 116: Line 116:
from dht import DHT11
from dht import DHT11
from esp8266_i2c_lcd import I2cLcd
from esp8266_i2c_lcd import I2cLcd

time.sleep(1)


d = DHT11(Pin(14)) # Pin D5
d = DHT11(Pin(14)) # Pin D5
Line 123: Line 125:


while True:
while True:
try:
d.measure()
d.measure()
lcd.putstr("Temperature: " + str(d.temperature()) + "C")
lcd.putstr("Humidity: " + str(d.humidity()) + "%")
print("temp: ", d.temperature(), "humidity: ", d.humidity())
lcd.putstr("Temperature: " + str(d.temperature()) + "C")
time.sleep(10)
lcd.putstr("Humidity: " + str(d.humidity()) + "%")
lcd.clear()
time.sleep(10)
lcd.clear()
except OSError:
print("Sensor read error!!")
lcd.putstr("Sensor read error!!")
time.sleep(5)
lcd.clear()
</syntaxhighlight>
</syntaxhighlight>