Advertisement
safwan092

Untitled

Jan 16th, 2024
16
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.75 KB | None | 0 0
  1. import I2C_LCD_driver
  2. from time import *
  3. import board
  4. import adafruit_dht
  5.  
  6. dhtDevice = adafruit_dht.DHT11(board.D4)
  7. mylcd = I2C_LCD_driver.lcd()
  8.  
  9. #mylcd.lcd_display_string("Hello World!", 1)
  10.  
  11. while True:
  12. try:
  13. # Print the values to the serial port
  14. temperature = dhtDevice.temperature
  15. humidity = dhtDevice.humidity
  16. mylcd.lcd_display_string("Temp:"+str(temperature)+"C"+" Hum:" +str(humidity)+"%", 1)
  17. mylcd.lcd_display_string("Time", 2)
  18. print("Temp: {:.1f} C Humidity: {}% "
  19. .format(temperature, humidity))
  20.  
  21. except RuntimeError as error: # Errors happen fairly often, DHT's are hard to read, just keep going
  22. print(error.args[0])
  23. sleep(2.0)
  24.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement