import machine
import time
import ssd1306
# Initialize I2C communication
i2c = machine.I2C(0, sda=machine.Pin(4), scl=machine.Pin(5), freq=400000)
# Initialize OLED display (128x64 pixels)
oled = ssd1306.SSD1306_I2C(128, 64,i2c)
# Initialize ADC for internal temperature sensor (Channel 4)
sensor_temp = machine.ADC(4)
conversion_factor = 3.3 / 65535
print("Experiment 3.2: I2C OLED Display Starting...")
while True:
# Read raw data and convert to voltage
reading = sensor_temp.read_u16() * conversion_factor
# Formula to convert voltage to Celsius
temperature = 27 - (reading - 0.706) / 0.001721
# The next part of the code is cut off in the image,
# but typically you would update the OLED here:
oled.fill(0)
oled.text("IOT MONITOR",20,0)
oled.hline(0,10,128,1)
oled.text("status: ONLINE",0,20)
oled.text(f"Temp:{temperatue:.1f} C", 0, 40)
oled.show()
time.sleep(1)