from machine import Pin, I2C, ADC
from ssd1306 import SSD1306_I2C
from time import sleep
import math
thermistor = ADC(28)
Ro = 10000;A = 0.001129148;B = 0.000234125;C = 0.0000000876741
i2c=I2C(1,sda=Pin(26), scl=Pin(27), freq=400000)
oled = SSD1306_I2C(128, 64, i2c)
btn = Pin(16, Pin.IN, Pin.OUT)
def read_temperature():
# Get Voltage value from ADC
adc = thermistor.read_u16()
Vout = (3.3/65535) * adc
Rt = (Vout * Ro) / (3.3 - Vout)
TempK = 1 / (A + (B * math.log(Rt)) + C * math.pow(math.log(Rt), 3))
TempC = TempK - 273.15
return round(TempC, 1)
while True:
temperature = read_temperature()
print(str(int(temperature)))
oled.fill(0)
oled.text(str(int(temperature)) + " c", 5, 40)
oled.show()
sleep(0.5)