capteur-i2c-bmp280.ino

Arduino Portenta H7 · File : capteur-i2c-bmp280.ino · Language : Arduino · Use case : Lire un capteur pression/température BMP280 en I2C

The BMP280 on the Portenta I2C bus with plain Wire writes: reset, forced mode, trigger and 20-bit pressure read. Understanding the protocol before pulling in ready-made libraries.

Hardware

An Arduino Portenta H7 (ST STM32H747 dual-core module Cortex-M7 @ 480 MHz + M4 @ 240 MHz, 8 MB SDRAM, high-density connector), powered by USB-C or 5 V. 1 BMP280 module (I2C, address 0x76 or 0x77), 3.3 V supply.

Wiring

SDA/SCL to the connector I2C pins (see carrier schematic), VCC 3.3 V, GND. Pull-ups usually present on the module.

How it works

Wire drives the H7 I2C controller at 400 kHz; each forced measurement is triggered by a write then read as 20 bits. The physical conversion uses the factory calibration.

Running it

Arduino IDE with the « Arduino Mbed OS Portenta Boards » core: pick « Portenta H7 » (M7 core), the USB-C port, then Upload. The DFU mode M7/M4 selector also loads the M4 core.

Variants

Hook up the Adafruit_BMP280 library for ready-made conversion, or watch pressure every minute in deep sleep.

capteur-i2c-bmp280.ino

// BMP280 (0x76) sur le bus Wire de la Portenta.
#include <Wire.h>

#define ADRESSE 0x76

uint16_t lire16(uint8_t reg) {
  Wire.beginTransmission(ADRESSE);
  Wire.write(reg);
  Wire.endTransmission(false);
  Wire.requestFrom((uint8_t)ADRESSE, (uint8_t)2);
  uint8_t lsb = Wire.read();
  uint8_t msb = Wire.read();
  return (msb << 8) | lsb;
}

void setup() {
  Serial.begin(9600);
  Wire.begin();
  Wire.setClock(400000);

  // Reinitialisation puis mode forcé.
  Wire.beginTransmission(ADRESSE);
  Wire.write(0xE0); Wire.write(0xB6);   // soft reset
  Wire.endTransmission();
  delay(10);
  Wire.beginTransmission(ADRESSE);
  Wire.write(0xF4); Wire.write(0x27);   // x16/x16, mode force
  Wire.endTransmission();
}

void loop() {
  Wire.beginTransmission(ADRESSE);
  Wire.write(0x2C);                      // declenche une mesure
  Wire.endTransmission();
  delay(20);

  int32_t p = ((uint32_t)lire16(0xF7) << 12) | (lire16(0xF9) >> 4);
  int32_t t = ((uint32_t)lire16(0xFA) << 12) | (lire16(0xFC) >> 4);
  Serial.printf("pression brute=%ld  temperature brute=%ld\n", p, t);
  delay(1000);
}

// Valeurs brutes : la conversion complete (Bosch datasheet)
// utilise les registres de calibration 0x88..0xA1.

← Back to the board