#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', 12, 3, 1)
oled.text(f'Temp : {temp_str} C', 1, 18, 1)
oled.text(f'Humi : {humid_str} %', 1, 30, 1)
oled.text('Soil : 76.25 %', 1, 42, 1)
oled.text('Light: 1234 lux', 1, 54, 1)
oled.rect(0, 0, 128, 15, 1)
oled.rect(0, 15, 128, 48, 1)
print("*"*20)
oled.show()
#oled.hline(0, 8, 60, 1)
#oled.vline(0, 8, 40, 1)
#oled.line(0, 0, 127, 63, 1)
#oled.rect(10, 10, 107, 43, 1)
Loading
esp32-devkit-c-v4
esp32-devkit-c-v4
Loading
ssd1306
ssd1306