# OLED
from machine import Pin
from machine import Pin,I2C
import machine
import ssd1306
import dht
import time
i2c = I2C(scl=Pin(22), sda=Pin(23)) #Init i2c
oled=ssd1306.SSD1306_I2C(128,64,i2c,0x3c)
p15=Pin(13,Pin.IN)
d=dht.DHT22(p15)
while True:
d.measure() #Measurement of temperature and humidity
t=d.temperature() #Read Celsius temperature
h=d.humidity() #Read relative humidity
print('Temperature=',t,'C','Humidity=', h, '%')
time.sleep(1) #Delay of 1 second
oled.fill(0)
oled.text("Temperature",10,5)
oled.text(str(t),40,20)
oled.text("*C",60,20)
oled.text("Humidity",30,40)
oled.text(str(h),40,55)
oled.text("%", 60,55)
oled.show()
# while True:
# try:
# d.measure()
# time.sleep(2)
# t = d.temperature()
# h = d.humidity()
# temp = 'Temp: {:.2f} C'.format(t)
# humid = 'Humidity: {:.2f}%'.format(h)
# lcd.clear()
# lcd.putstr(temp)
# lcd.move_to(0,1)
# lcd.putstr(humid)
# time.sleep(5)
# except:
# pass
#Without I2C
# import machine
# from machine import Pin
# import time
# import dht
# from gpio_lcd import GpioLcd
# I2C_ADDR = 0x27
# totalRows = 2
# totalColumns = 16
# lcd = GpioLcd(rs_pin=Pin(4),
# enable_pin=Pin(2),
# d4_pin=Pin(21),
# d5_pin=Pin(19),
# d6_pin=Pin(18),
# d7_pin=Pin(5),
# num_lines=2,
# num_columns=16)
# # DHT11
# d = dht.DHT22(Pin(13))
# while True:
# d.measure()
# time.sleep(1)
# t = d.temperature()
# h = d.humidity()
# temp = 'Temp: {:.2f} C'.format(t)
# humid = 'Humidity: {:.2f}%'.format(h)
# lcd.clear()
# lcd.putstr(temp)
# lcd.move_to(0,1)
# lcd.putstr(humid)
# time.sleep(2)