Aliases: BMP388 breakout, Adafruit BMP388, BMP3XX, CJMCU-388, barometer, altimeter. The barometer of small drones and model rockets. Its readings are raw 24-bit counts; the library turns them into pascals and degrees with 21 trimming bytes Bosch writes into every chip at the factory, using the formulas in the datasheet. Pressure falls about 12 Pa a meter near sea level, so the altitude is a short sum away.
Pins
| Pin | What it does |
|---|---|
VIN |
Supply, 3.3 or 5 V on the board (the chip runs from 1.65 to 3.6 V; the board's regulator and level shifters feed it). |
GND |
Ground. |
SCL, SDA |
I2C. The board carries the pull-ups. Adafruit's board prints them SCK and SDI, their SPI names. |
SDO |
The address bit. Left alone (the board pulls it up) the address is 0x77; to GND it is 0x76, so two can share a bus. |
INT |
Data ready interrupt, when the sketch turns it on. |
Properties
pressure (hPa, 300 to 1250) and temperature (degrees C, -40 to 85) are the weather, the
datasheet's operating range. The two sliders change them while the circuit runs, and the
next measurement reports them.
Reading it on an Arduino
With Adafruit's library, which Mokxi ships as Adafruit_BMP3XX.h:
#include <Wire.h>
#include <Adafruit_BMP3XX.h>
Adafruit_BMP3XX bmp;
void setup() {
Serial.begin(9600);
if (!bmp.begin_I2C()) { // 0x77; begin_I2C(0x76) with SDO to GND
Serial.println("No BMP388");
while (1) {}
}
bmp.setTemperatureOversampling(BMP3_OVERSAMPLING_2X);
bmp.setPressureOversampling(BMP3_OVERSAMPLING_8X);
bmp.setIIRFilterCoeff(BMP3_IIR_FILTER_COEFF_3);
bmp.setOutputDataRate(BMP3_ODR_50_HZ);
}
void loop() {
if (bmp.performReading()) {
Serial.print(bmp.temperature); // C
Serial.print(" C ");
Serial.print(bmp.pressure / 100.0); // hPa
Serial.print(" hPa ");
Serial.print(bmp.readAltitude(1013.25)); // m
Serial.println(" m");
}
delay(1000);
}
readAltitude() takes the sea-level pressure in hPa and does a fresh reading of its own.
The gallery's BMP388 altimeter example prints the altitude every second.
How it talks
CHIP_IDat0x00reads0x50. After power on and a soft reset (0xB6toCMD,0x7E) the chip answers in 2 ms, andEVENT(0x10) reads 1 once.- The trimming bytes are at
0x31to0x45: T1 to T3 and P1 to P11. The sheet's floating-point compensation scales each by a power of two and turns the raw counts into degrees and pascals. PWR_CTRL(0x1B) turns the pressure and temperature readings on and picks the mode: sleep, forced (one measurement, then back to sleep) or normal (one everyODRperiod, 5 ms times a power of two).OSR(0x1C) sets the oversampling, x1 to x32 each; a measurement takes 234 us plus 392 us and 2 ms a pressure sample, and 313 us and 2 ms a temperature sample. Each step adds a bit: 16 bits at x1, 21 at x32.CONFIG(0x1F) sets the IIR filter: each new value counts 1 in (c + 1) against the last, for c of 0 (off), 1, 3, 7 up to 127. WritingCONFIGresets it.STATUS(0x03) hasdrdy_pressanddrdy_temp; reading the data registers clears them. The six data bytes at0x04are pressure then temperature, low byte first.- A write is pairs of register and value, so one transfer can set several registers.
- With
drdy_eninINT_CTRL(0x19),INTgoes active for 2.5 ms when a reading is ready (or untilINT_STATUSis read, withint_latch), high by default.
What it does not model
SPI (this board's I2C only), the FIFO and its interrupts, the sensor time counter and the
I2C watchdog. The readings are the sliders to the bit at the oversampling set, without the
noise oversampling removes; the real part is within 0.5 hPa and 0.3 °C, typically. The
sheet does not say when the chip flags a configuration error: here normal mode is refused,
with conf_err, when a measurement would not fit in the ODR period, the check Bosch's
driver makes.
Common mistakes
Forgetting the address: with SDO to GND the chip is at 0x76, and begin_I2C() looks at
0x77. Asking for normal mode at 200 Hz with x32 oversampling: a measurement takes 69 ms,
so the chip refuses. Expecting the altitude from the ground: readAltitude() is the height
above the sea-level pressure you give it, so use the day's local value for a true altitude.