🛠 Connecter un capteur I2C sur le GIGA R1
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
- 1 Arduino GIGA R1 WiFi board
- 1 external I2C sensor (BME680, BME280, or BMP280) — 3.3 V power supply
- 4 female jumper wires, USB-C cable
- Optionally, 4.7 kΩ pull-up resistors if the module does not have them
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
- Wrong address: If the module's ADDR pin is not connected, 0x76 becomes 0x77; run the scanner first.
- Missing pull-ups on SDA/SCL: The bus remains stuck in the low state, and the scanner finds nothing.
- Powering a non-tolerant module with 5 V: Prefer 3.3 V, which is the board's logic voltage.
- Swapped SDA/SCL: No device detected, the bus appears dead.
- Two sensors at the same address: There are two other I2C buses available on the board to separate them.
Other tutorials for this board
- Faire clignoter la LED de l'Arduino GIGA R1
- Bouton poussoir et console série sur le GIGA R1
- Potentiomètre et sortie DAC sur la prise audio du GIGA R1
- Piloter un micro-servo avec la PWM du GIGA R1
- Publier des données en MQTT/HTTP via le Wi-Fi du GIGA R1
- Programmer les deux cœurs M7 et M4 du GIGA R1 et les faire communiquer
Code examples for this board
clignotante.inoArduinobouton.inoArduinorespiration.inoArduinoanalogique.inoArduinodac-onde.inoArduinooled-i2c.inoArduino