import machine, onewire, ds18x20, time
from machine import I2C, Pin
from time import sleep
# very important
# this module needs to be saved in the Raspberry Pi Pico in order for the LCD I2C to be used
from pico_i2c_lcd import I2cLcd
# creating an I2C object, specifying the data (SDA) and clock (SCL) pins used in the Raspberry Pi Pico
# any SDA and SCL pins in the Raspberry Pi Pico can be used (check documentation for SDA and SCL pins)
i2c = I2C(0, sda=Pin(0), scl=Pin(1), freq=400000)
Temp = machine.Pin(26, machine.Pin.IN)
# getting I2C address
I2C_ADDR = i2c.scan()[0]
# creating an LCD object using the I2C address and specifying number of rows and columns in the LCD
# LCD number of rows = 2, number of columns = 16
lcd = I2cLcd(i2c, I2C_ADDR, 2, 16)
ds_pin = machine.Pin(26)
ds_sensor = ds18x20.DS18X20(onewire.OneWire(ds_pin))
roms = ds_sensor.scan()
print('Found DS devices: ', roms)
ds_sensor2 = ds18x20.DS18X20(onewire.OneWire(machine.Pin(27)))
roms2 = ds_sensor2.scan()
print('Found DS: ', roms2)
# continuously print and clear "Hello world!" text in the LCD screen while the board has power
while True:
# putstr method allows printing of the text in the LCD screen
# for other methods that can be used, check lcd_api module
ds_sensor.convert_temp()
ds_sensor2.convert_temp()
time.sleep_ms(200)
for rom in roms:
print(ds_sensor.read_temp(rom))
TempEx=ds_sensor.read_temp(rom);
lcd.putstr("Temperatura Externa:\n")
lcd.putstr(str(TempEx))
sleep(5) # "Hello world!" text would be displayed for 5 secs
lcd.clear()
for rom in roms2:
print(ds_sensor2.read_temp(rom))
TempIn=ds_sensor2.read_temp(rom);
lcd.putstr("Temperatura Interna:\n")
lcd.putstr(str(TempIn))
sleep(5) # "Hello world!" text would be displayed for 5 secs
lcd.clear()