from machine import Pin, I2C
from time import sleep, localtime
from dht import DHT22
from ssd1306 import SSD1306_I2C
sensor = DHT22(Pin(2))
i2c=I2C(0,sda=Pin(16), scl=Pin(17), freq=200000) #initializing the I2C method
oled = SSD1306_I2C(128, 64, i2c)
while True:
oled.fill(0)
sensor.measure()
temp = str(sensor.temperature())
hum = str(sensor.humidity())
#now = localtime()
oled.text("Temp:",0,0)
oled.text(temp +" *C",50,0)
oled.text("Humidity: ",0,15)
oled.text(hum + " %",75,15)
#oled.text("Date: {}/{}/{}".format(now[2], now[1], now[0]), 0, 40)
#oled.text("Time: {}:{}".format(now[3], now[4]), 0, 52)
oled.show()
sleep(2)