from machine import Pin
import dht
from machine import I2C
import ssd1306
# import adafruit_ssd1306
import time
# ESP32 Pin assignment
i2c = I2C(0, scl=Pin(22), sda=Pin(21))
oled_width = 128
oled_height = 64
oled = ssd1306.SSD1306_I2C(oled_width, oled_height, i2c)
# oled = adafruit_ssd1306.SSD1306_I2C(oled_width, oled_height, i2c, addr=0x3c)
# oled.setTextSize(2)
oled.text('Starting temperature sensor...', 10, 10)
oled.show()
sensor = dht.DHT22(Pin(15))
while True:
sensor.measure()
temp = sensor.temperature()
humid= sensor.humidity()
temp_text = "Temp : " + str(temp) + "*C"
humid_text = "Humid: " + str(humid) + "%"
oled.fill(0)
oled.text(temp_text, 10, 10)
oled.text(humid_text, 10, 20)
oled.show()
time.sleep(1)
# print("Heat Index", sensor.computeHeatIndex(t, h, false)
"""
# DHT Code Test
sensor = dht.DHT22(Pin(15))
while True:
sensor.measure()
print("temp", sensor.temperature())
print("humidity", sensor.humidity())
# print("Heat Index", sensor.computeHeatIndex(t, h, false))
"""
"""
# OLED Display Test
# ESP32 Pin assignment
i2c = I2C(0, scl=Pin(22), sda=Pin(21))
oled_width = 128
oled_height = 64
oled = ssd1306.SSD1306_I2C(oled_width, oled_height, i2c)
oled.text('Hello, Wokwi!', 10, 10)
oled.show()
"""