1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24
| import utime from machine import I2C, Pin, ADC from lcd_api import LcdApi from pico_i2c_lcd import I2cLcd I2C_ADDR = 63 I2C_NUM_ROWS = 2 I2C_NUM_COLS = 16
i2c = I2C(0, sda=Pin(0), scl=Pin(1), freq=400000) lcd = I2cLcd(i2c, I2C_ADDR, I2C_NUM_ROWS, I2C_NUM_COLS) def read_temp(): sensor_temp = ADC(4) conversion_factor = 3.3 / (65535) reading = sensor_temp.read_u16() * conversion_factor temperature = 27 - (reading - 0.706)/0.001721 formatted_temperature = "{:.2f}".format(temperature) string_temperature = str("Temp:" + formatted_temperature) print(string_temperature) utime.sleep(2) return string_temperature while True: temperature = read_temp() lcd.move_to(0,0) lcd.putstr(temperature)
|