from machine import Pin, SoftI2C
from machine import Pin, I2C
import ssd1306
from dht20 import DHT20
from utime import sleep

i2c0_sda = Pin(8)
i2c0_scl = Pin(9)
i2c0 = I2C(0, sda=i2c0_sda, scl=i2c0_scl, freq= 400000)

dht20 = DHT20(0x38, i2c0)
measurements = dht20.measurements
temp = measurements['t']
hum = measurements['rh']

oled_width = 128
oled_height = 64
oled = ssd1306.SSD1306_I2C(oled_width, oled_height, i2c0)

while True:
    measurements = dht20.measurements
    temp = measurements['t']
    hum = measurements['rh']
    print(f"Temperature: {measurements['t']} °C, humidity: {measurements['rh']} %RH")
    sleep(1)
    oled.fill(0)
    oled.text('Wetterstation', 0, 0)
    oled.text('HILF! 2024', 0, 10)
    oled.text(f"Temp: {measurements['t']} C",0,20)
    oled.text(f"Hum:  {measurements['rh']} %RH", 0, 30)
    oled.text('Hum: ',0,40)
    oled.text(str(round(hum,1)),50,40)
    oled.text('Temp: ',0,50)
    oled.text(' %RH ',85,40)
    oled.text(str(round(temp,1)),50,50)
    oled.text(' C ',85,50)
    oled.show()
    sleep(1)