esp32-p4-hydra-stemma-i2c-sensor.ino
Demonstrates using the STEMMA QT connector to read environmental sensors via I2C without soldering.
Plug a STEMMA QT compatible sensor (e.g., BME280) into the JST connector. The code uses the Adafruit BME280 library. The Hydra's I2C bus is exposed on the STEMMA connector. If the sensor is not detected, try Wire1.begin() or check the I2C address (0x76 or 0x77).
esp32-p4-hydra-stemma-i2c-sensor.ino
#include <Arduino.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_BME280.h>
#define SEALEVELPRESSURE_HPA (1013.25)
// Le connecteur STEMMA QT sur la Hydra utilise l'bus I2C par défaut (souvent GPIO 8 et 9, à vérifier selon le schéma Hydra v1)
// Adafruit_BME280 utilise Wire par défaut si aucun pin n'est spécifié, ou Wire1.
// Sur la Hydra, le bus I2C externe est généralement Wire (SDA=8, SCL=9) ou Wire1.
// Testez avec Wire d'abord.
Adafruit_BME280 bme;
void setup() {
Serial.begin(115200);
Serial.println("Metro ESP32-P4 Hydra: STEMMA QT BME280 Test");
Wire.begin(); // Initialise le bus I2C par défaut
if (!bme.begin(0x76)) {
Serial.println("\nCould not find a valid BME280 sensor, check wiring!");
while (1);
}
Serial.println("BME280 Found!");
}
void loop() {
Serial.print("Temperature = ");
Serial.print(bme.readTemperature());
Serial.println(" *C");
Serial.print("Pressure = ");
Serial.print(bme.readPressure() / 100.0F);
Serial.println(" hPa");
delay(2000);
}