#10_i2c_OLED.py
from machine import Pin, SoftI2C
from time import sleep
import ssd1306
import dht
i2c = SoftI2C(scl=Pin(22), sda=Pin(21), freq=400000)
oled = ssd1306.SSD1306_I2C(128, 64, i2c)
sensor_dht22 = dht.DHT22(Pin(15))
while True:
sensor_dht22.measure()
temp = sensor_dht22.temperature()
humid = sensor_dht22.humidity()
print("Temperature: ", temp, "C")
print("Humidity: ", humid, "%")
sleep(2)
#print(type(temp))
#print(type(humid))
temp_str = str(temp)
humid_str = str(humid)
oled.fill(0)
oled.text('Weather Today', 8, 3, 1)
#oled.text('Temp: 25.35 C', 1, 17, 1)
#oled.text('Humi: 80.45 %', 1, 29, 1)
oled.text(f'Temp: {temp_str} C', 1, 17, 1)
oled.text(f'Humi: {humid_str} %', 1, 29, 1)
oled.text('Soil: 76.25 %', 1, 41, 1)
oled.text('Light:1234 lux', 1, 53, 1)
oled.rect(0, 0, 127, 63, 1)
oled.rect(0, 0, 127, 15, 1)
oled.show()
print("*"*20)