from machine import Pin, I2C
from machine import ADC
from ssd1306 import SSD1306_I2C
import utime
i2c=I2C(0,sda=Pin(0),scl=Pin(1),freq=400000)
oled = SSD1306_I2C(128, 64, i2c)
lin_hight = 9
col_width = 8
conv_coef = 3.3 / 65535 # facteur de conversion
def text_write(text,lin, col):
oled.text(text,col*col_width,lin*lin_hight)
oled.fill(0)
oled.invert(True)
while True:
voltage = ADC(4).read_u16() * conv_coef # conversion
T = 29 - (voltage - 0.706)/0.001721
T = round (T,1)
T = str(T)
text_write("la temperature", 1, 1)
text_write("est de :", 3, 4)
text_write(T, 5, 3)
text_write("degC", 5, 9)
oled.rect(5, 5, 116, 52, 1)
oled.show()
utime.sleep(5) # pause 1 seconde
oled.fill(0)
oled.show()