pression_bmp390.ino
The BMP390 (24-bit, 300-1250 hPa, ±0.5 hPa) is read through BHY2 accessors: pressure in hPa and derived barometric altitude. Local weather tracking and a stairway detector fit in twenty lines.
Hardware
An Arduino Nicla Sense ME (nRF52832, BLE only) with Bosch BHI260AP hub, BMM150, BMP390, BME688 sensors, RGB LED on an I2C driver and LiPo charger. The board alone. For altitude, know today sea-level pressure (tune P_MER).
Wiring
No wiring. The BMP390 sits on the hub internal bus; avoid direct air drafts on the housing that skew the reading.
How it works
BHY2.enable(PRESSURE_HIGH_ACCURACY) arms the sensor in the firmware; readPressure returns the latest value. The barometric formula converts hPa into meters relative to P_MER.
Running it
Programmed from the Arduino IDE (ArduinoCore-mbed); Arduino_BHY2 and Nicla_System libraries; USB through a serial bridge.
Variants
Derive vertical speed (ΔP/Δt) to detect an elevator or a fall, keep P_MER synced to the local weather station, or log pressure to CSV over USB.
pression_bmp390.ino
// BMP390 : baromètre 24 bits (300-1250 hPa) derrière le hub.
// Les capteurs « d'environnement » du Sense ME se lisent via les
// accesseurs statiques BHY2 après activation.
#include "Arduino_BHY2.h"
const float P_MER = 1013.25; // pression de référence au niveau de la mer
void setup() {
Serial.begin(115200);
BHY2.begin();
BHY2.enable(BHY2_ENABLE_PRESSURE_HIGH_ACCURACY);
BHY2.update();
}
void loop() {
BHY2.update();
float pression = BHY2.readPressure(); // hPa
// Formule barométrique (approximation valide en dessous de ~1 km)
float altitude = 44330.0 * (1.0 - powf(pression / P_MER, 0.190295));
static unsigned long t = 0;
if (millis() - t > 1000) {
t = millis();
Serial.print("P="); Serial.print(pression, 2); Serial.print(" hPa");
Serial.print(" alt≈"); Serial.print(altitude, 1); Serial.println(" m");
}
delay(5);
}