from machine import Pin, SoftI2C
from ssd1306 import SSD1306_I2C
from utime import sleep
from dht import DHT22
weather = DHT22(Pin(25))
while True:
i2c = SoftI2C(sda=Pin(21), scl=Pin(22))
display = SSD1306_I2C(128, 64, i2c)
try:
weather.measure()
temp = weather.temperature()
hum = weather.humidity()
print(f'Temperature: {temp}C\nHumidity: {hum}%')
display.fill(0)
display.text('Temperature:', 0, 0, 1)
display.text(f'{temp:.1f}C', 0, 12, 1)
display.text('Humidity:', 0, 28, 1)
display.text(f'{hum:.1f}%', 0, 40, 1)
display.fill_rect(80, 20, 40, 30, 1)
display.line(80, 20, 75, 10, 1)
display.line(75, 10, 85, 20, 1)
display.fill_rect(77, 12, 4, 5, 0)
display.line(120, 20, 125, 10, 1)
display.line(125, 10, 115, 20, 1)
display.fill_rect(122, 12, 4, 5, 0)
display.fill_rect(88, 27, 8, 8, 0)
display.fill_rect(91, 30, 3, 4, 1)
display.pixel(90, 29, 1)
display.fill_rect(104, 27, 8, 8, 0)
display.fill_rect(107, 30, 3, 4, 1)
display.pixel(106, 29, 1)
display.fill_rect(96, 38, 4, 3, 1)
display.pixel(95, 39, 1)
display.pixel(100, 39, 1)
display.line(94, 42, 98, 45, 1)
display.line(98, 45, 102, 42, 1)
display.pixel(95, 43, 1)
display.pixel(101, 43, 1)
display.line(80, 35, 70, 32, 1)
display.line(80, 37, 70, 37, 1)
display.line(80, 39, 70, 42, 1)
display.line(80, 41, 68, 47, 1)
display.line(120, 35, 130, 32, 1)
display.line(120, 37, 130, 37, 1)
display.line(120, 39, 130, 42, 1)
display.line(120, 41, 132, 47, 1)
display.fill_rect(85, 50, 30, 10, 1)
display.fill_rect(75, 52, 50, 8, 1)
display.fill_rect(75, 60, 10, 4, 1)
display.fill_rect(95, 60, 10, 4, 1)
display.fill_rect(110, 45, 15, 4, 1)
display.fill_rect(120, 42, 8, 4, 1)
display.fill_rect(125, 40, 6, 4, 1)
display.fill_rect(128, 38, 4, 4, 1)
display.fill_rect(90, 52, 4, 3, 0)
display.fill_rect(105, 54, 3, 2, 0)
display.pixel(115, 56, 0)
display.rect(78, 18, 44, 34, 1)
display.text('Meow!', 85, 10, 1)
display.show()
except Exception as e:
print(f"Error: {e}")
display.fill(0)
display.text('Error reading', 10, 20, 1)
display.text('DHT22 sensor', 10, 30, 1)
display.show()
sleep(2)