lattepanda-sigma2-rp2350-micropython-i2c-8.ino
Configures the RP2350 microcontroller I2C bus to query an external environmental sensor.
Hardware: LattePanda Sigma 2 (RP2350 coprocessor), I2C sensor (e.g., BME280) connected to GPIOs. Software: MicroPython flashed onto the RP2350. The script initializes I2C0 on the header's SDA/SCL pins. Verify your component's I2C addresses. Code runs on the MCU, not the x86 CPU.
lattepanda-sigma2-rp2350-micropython-i2c-8.ino
from machine import Pin, I2C
import time
# Configuration I2C sur le RP2350 (GPIO dédiés sur l'en-tête 30+4)
# SDA = Pin 6, SCL = Pin 5 (Vérifier le schéma exact pour le header 30-pin)
i2c = I2C(0, scl=Pin(5), sda=Pin(6), freq=400000)
# Adresse I2C standard pour les capteurs TMP36/DS18B20 (I2C variant) ou BME280
SENSOR_ADDR = 0x76 # Exemple pour BME280
def read_temp():
try:
# Envoyer la commande de lecture brute
# Note : Les registres dépendent du capteur spécifique (BME280 utilisé ici en exemple)
raw_temp = i2c.read_mem(0xF8, SENSOR_ADDR, 0x07, 3) # Lecture 3 octets
temp_raw = (raw_temp[0] << 12) | (raw_temp[1] << 4) | (raw_temp[2] >> 4)
temp_c = temp_raw / 16.0
return temp_c
except Exception as e:
return None
print("Initialisation du capteur I2C sur LattePanda Sigma 2...")
while True:
temp = read_temp()
if temp is not None:
print(f"Température: {temp:.2f} C")
else:
print("Erreur de lecture capteur")
time.sleep(1)