# Thermistor con Display serie

from machine import Pin, ADC
import utime
import math
#import ADC
from pico_i2c_lcd import I2cLcd
from machine import I2C
Thermistor = ADC(2)   #Se asigna otra entrada ADC para el sensor
i2c = I2C(id=1,scl=Pin(27),sda=Pin(26),freq=100000)
lcd = I2cLcd(i2c, 0x27, 2, 16)

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)
    #temp = Temperature(Raw)
  #  trig.value(0)
   # utime.sleep_us(5)
   # trig.value(1)
    #utime.sleep_us(10)
   # trig.value(0)
   # while echo.value() == 0:
   #     pass
   # Tmrinicio = utime.ticks_us()
  #  while echo.value() == 1:
   #     pass
    #Tmrfin = utime.ticks_us()
    #Duration = utime.ticks_diff(Tmrfin, Tmrinicio)
    #distancecm = Duration * 0.0171
    lcd.clear()
    lcd.move_to(0,0)
    lcd.putstr("Temperature "+ str(temp)[:5]  +"  C")
    #tempstr = str(temp)[:5]
    #Raw = Thermistor.read_u16()
    #temp = Temperature(Raw)
    utime.sleep(2)
BOOTSELLED1239USBRaspberryPiPico©2020RP2-8020/21P64M15.00TTT