🛠 Connecter un capteur I2C sur le GIGA R1

Arduino GIGA R1 · intermediaire · Schéma : IMG-giga-r1-i2-1-i2c-capteur.svg — Capteur d'environnement I2C externe relié aux broches SDA et SCL du GIGA R1 avec résistances de pull-up et alimentation 3,3 V.

Objectives

Communicate with an external I2C device. The GIGA R1 features 3 I2C buses on the STM32H747XI; we will use the default bus of the Wire library with a commercial environmental sensor (temperature/humidity/pressure), such as a BME680 or BMP280. Note: the board itself does not include a temperature/humidity sensor — the sensor is external in this case.

Hardware

Complete Code

// GIGA R1 WiFi — scanner I2C puis lecture d'un capteur BMP280/BME680 (adresse 0x76/0x77)
#include <Arduino.h>
#include <Wire.h>

const uint8_t ADRESSE_CAPTEUR = 0x76;   // 0x77 selon le brochage ADDR du module

void setup {
  Serial.begin(115200);
  Wire.begin;                            // bus I2C par defaut (SDA/SCL)
  delay(1000);

  // Petit scanner : liste les peripheriques presents
  Serial.println("Scan du bus I2C :");
  for (uint8_t a = 1; a < 127; a++) {
    Wire.beginTransmission(a);
    if (Wire.endTransmission == 0) {
      Serial.printf("  peripherique trouve a 0x%02X\n", a);
    }
  }
}

void loop {
  // Lecture de l'identifiant de puce (registre 0xD0 pour BMP280/BME680)
  Wire.beginTransmission(ADRESSE_CAPTEUR);
  Wire.write(0xD0);
  Wire.endTransmission(false);
  Wire.requestFrom(ADRESSE_CAPTEUR, (uint8_t)1);
  if (Wire.available) {
    uint8_t chipId = Wire.read;
    Serial.printf("Chip ID = 0x%02X (attendu 0x58/0x60/0x61)\n", chipId);
  } else {
    Serial.println("Capteur absent : verifiez SDA/SCL et l'adresse");
  }
  delay(2000);
}

Wiring: VCC to 3.3 V, GND to GND, SDA to the GIGA's SDA pin, SCL to the GIGA's SCL pin.

Expected Verification

The I2C scan lists the sensor's address (0x76 or 0x77). Then, the Serial Monitor displays a consistent chip ID (0x58 for BMP280, 0x60/0x61 for BME680) every two seconds.

Common Errors

Other tutorials for this board

Code examples for this board

← Back to the board 🛠 All tutorials