from machine import Pin, ADC, SoftI2C
import ssd1306
import time
adc = ADC(Pin(26))
# Configuracion i2c por software
i2c = SoftI2C(sda = Pin(0), scl = Pin(1), freq = 100000)
time.sleep(0.5)
oled = ssd1306.SSD1306_I2C(128, 64, i2c)
while True:
raw = adc.read_u16()
v_out = raw * (3.3 / 65535.0)
# Restringir el voltaje
v_out = max(0.1, min(3.1, v_out))
# Reconstrucción del voltaje del sensor
v_sensor = (v_out + 1.025) / 3.75
# Cálculo de la temperatura
temp = (v_sensor - 0.5) * 100.0
print(f"Voltaje:{v_out:.2f},Temperatura:{temp:.1f}")
time.sleep(0.2)
oled.fill(0)
oled.text(f"Voltaje:{v_out:.2f}V", 0, 10)
oled.text(f"Temperatura:{temp:.1f} C", 0, 30)
oled.show()
time.sleep(0.2)