from machine import Pin,ADC, I2C
from utime import sleep
from math import log
import lcdi2c as lcd
ntc_sensor = ADC(0)
A = 1.009249522e-03
B = 2.378405444e-04
C = 2.019202697e-07
R_PULLUP = 10000
def read_temperature():
# Read raw ADC value (12-bit resolution)
raw_adc = ntc_sensor.read_u16()
voltage = raw_adc * (3.3 / 65535) # Convert to voltage
resistance = (R_PULLUP * voltage) / (3.3 - voltage) # Calculate resistance
# Calculate temperature using Steinhart-Hart equation
steinhart = A + B * (resistance ** -1) + C * (resistance ** -3)
temperature = 1 / steinhart - 273.15 # Convert to Celsius
return round(temperature, 2)
#tm = tm1637.TM1637(clk=Pin(0), dio=Pin(1))#
lcd.cmdwrite(0xc0)
lcd.strwrite("BMT4033")
sleep(2)
lcd.cmdwrite(0x01)
lcd.strwrite("SYAFIQA")
sleep(2)
while 1:
for i in range(100):
lcd.cmdwrite(0x85)
temp = read_temperature()
lcd.clear()
lcd.putstr(f"Temp: {temp}C")
sleep(1)
sleep(0.5)
BETA = 3950
sleep(0.01)
ntc=ADC(Pin(26))
while 1:
val=ntc.read_u16()
temp=1 / (log(1 / (65535. / val - 1)) / BETA + 1.0 / 298.15) - 273.15;
print(temp)
tm.temperature(int(temp))
sleep(0.3)