from machine import Pin, SoftI2C, ADC
from math import log
from i2c_lcd import I2cLcd
ADC_temp = ADC(Pin(2)) # pin 2 will be used to monitor temperature
lcd1_address = 0x27
i2c = SoftI2C(scl = Pin(22), sda = Pin(23), freq = 400000) # set up I2C bus
lcd1 = I2cLcd(i2c, lcd1_address, 2, 16) # the display has 2 rows and 16 columns
def get_temperature():
beta = 3950 # beta coefficient of the thermistor being used
kelvin = 273.15 # value of temperature in Kelvin at zero Celsius
temp_value = ADC_temp.read()
# Convert the analog value into temperature
temperature_in_celsius = 1 / (log(1 / (4096 / temp_value - 1))/beta + 1.0 / 298.15) - kelvin
temperature_in_celsius=round(temperature_in_celsius,1)
return temperature_in_celsius
while True:
lcd1.move_to(0,0)
temp_reading = get_temperature()
lcd1.putstr('Temp is: ') # print to first LCD display
lcd1.putstr(str(temp_reading))
lcd1.putstr(' ')