#------------------------------------------------------------
# THERMISTOR TEMPERATURE MEASUREMENT
# ==================================
from machine import ADC
import utime
import math
import LCD
Thermistor = ADC(0)
LCD.lcd_init()
# ADC channel 0
# Initialize LCD
#
# Calculate the temperature using Steinhart-Hart equation
#
def Temperature(RawValue):
c1 = 0.001129148
c2 = 0.000234125
c3 = 0.0000000876741
R1 = 10000.0
ADC_Res = 65535.0
R2 = R1 / ((ADC_Res/RawValue - 1))
T = math.log(R2)
Tmp = 1.0 / (c1 + (c2 + (c3 * T * T)) * T)
Temp = Tmp - 273.15
return Temp
while True:
Raw = Thermistor.read_u16()
temp = Temperature(Raw)
LCD.lcd_clear()
LCD.lcd_puts("Temperature (C)")
LCD.lcd_goto(0, 1)
tempstr = str(temp)[:5]
LCD.lcd_puts(tempstr)
utime.sleep(2)
# Do forever
# Read channel 0
# Calculate temp
# Clear LCD
# Display heading
# Move cursor
# Convert to string
# Display temperature
# Wait 2 seconds