from machine import Pin, ADC, I2C, Timer
from pico_i2c_lcd import I2cLcd
from lcd_api import LcdApi
from math import log
adc = ADC(2)
BETA = 3950
sda = Pin(0)
scl = Pin(1)
i2c = I2C(0, sda=sda, scl=scl, freq=400000)
devices = i2c.scan()
i2cadd = devices[0]
lcd = I2cLcd(i2c, i2cadd, 2, 16)
def read_temp(timer):
adc_value = adc.read_u16()
temp_celuis = (1/((log((1/65535) * adc_value - 1)/ BETA) + (1/298.15))) - 273.15
lcd.clear()
lcd.putstr(f"Digital:{adc_value}")
lcd.putsrt(f"\nTemp:{temp_celcius:.2f} C")
timer = Timer(freq=5, mode=Timer.PERIODIC, callback=read_temp)
read_temp(timer)