#08_i2c_OLED.py
from machine import Pin, SoftI2C
from time import sleep
import ssd1306
i2c = SoftI2C(scl=Pin(22), sda=Pin(21), freq=400000)
print("Scanning I2C (Low Speed)...")
devices = i2c.scan()
if devices:
for device in devices:
print(f"Decimal: {device} | Hex: {hex(device)}")
else:
print("No device found")
oled = ssd1306.SSD1306_I2C(128, 64, i2c)
oled.fill(0)
oled.text('Weather Today', 13, 4, 1) #(X,Y,สีข้อความ)
oled.text('Temp : 25.35 C', 5, 19, 1)
oled.text('Humi : 80.45 %', 5, 30, 1)
oled.text('Soil : 76.25 %', 5, 41, 1)
oled.text('Light: 1234 lux', 5, 52, 1)
#oled.hline(0, 8, 60, 1)
#oled.vline(0, 8, 40, 1)
#oled.line(0, 0, 127, 63, 1)
oled.rect(0, 0, 128, 15, 1)
oled.rect(0, 16, 128, 48, 1)
oled.show()