First measure of BMP388 always wrong

Hi,

I'm trying to read data (pressure) from a BMP388 sensor.
The issue is that, at startup (or after a reset), the first measure is wrong (see log below).

Here is my very simple sketch (as you can see, I've tried removing the oversampling and filtering, but the issue stays the same) :

// I2C include
#include <Wire.h>

// Includes for BMP388 Pressure sensor
#include <Adafruit_Sensor.h>
#include "Adafruit_BMP3XX.h"

// BMP388 Pressure sensor defines
#define BMP_SCK 14
#define BMP_MISO 12
#define BMP_MOSI 13
#define BMP_CS 15
#define SEALEVELPRESSURE_HPA (1013.25)

// BMP388 Pressure Sensor object
Adafruit_BMP3XX bmp;



//==============================================================================
// SETUP METHOD
//
void setup() {
  // Initialize the serial port
  Serial.begin(115200);

  //----------------------------------------------------------------------------
  // BMP388 Pressure sensor initialization
  if (!bmp.begin_I2C()) {   // hardware I2C mode, can pass in address & alt Wire
    Serial.println("Could not find a valid BMP3 sensor, check wiring!");
    while (1);
  }
  // set up oversampling and filter initialization
  bmp.setTemperatureOversampling(BMP3_NO_OVERSAMPLING); //BMP3_OVERSAMPLING_8X
  bmp.setPressureOversampling(BMP3_NO_OVERSAMPLING); //BMP3_OVERSAMPLING_4X
  bmp.setIIRFilterCoeff(BMP3_IIR_FILTER_DISABLE); //BMP3_IIR_FILTER_COEFF_3
  //bmp.setOutputDataRate(BMP3_ODR_50_HZ);

}



//==============================================================================
// LOOP METHOD
//
void loop() {
  delay(10000);
 
  //----------------------------------------------------------------------------
  // BMP388 Pressure Sensor reading
  if (! bmp.performReading()) {
    Serial.println("Failed to perform reading :(");
    return;
  }
  Serial.print("Temperature = ");
  Serial.print(bmp.temperature);
  Serial.println(" *C");

  Serial.print("Pressure = ");
  Serial.print(bmp.pressure / 100.0);
  Serial.println(" hPa");

  Serial.println("");
}

And here is a log example :

Temperature = 24.37 *C      <--- wrong temperature,
Pressure = 805.28 hPa       <--- wrong pressure,

Temperature = 20.82 *C
Pressure = 1013.79 hPa

Temperature = 20.81 *C
Pressure = 1013.82 hPa

Temperature = 20.80 *C
Pressure = 1013.80 hPa

Temperature = 20.82 *C
Pressure = 1013.76 hPa

Have you any idea what is wrong here?

Hello silverspur

Did you read the spec?

Sea level pressure

A variable called SEALEVELPRESSURE_HPA is created.

#define SEALEVELPRESSURE_HPA (1013.25)

This variable saves the pressure at the sea level in hectopascal (is equivalent to milibar). This variable is used to estimate the altitude for a given pressure by comparing it with the sea level pressure. This example uses the default value, but for more accurate results, replace the value with the current sea level pressure at your location

Have a nice day and enjoy coding in C++.

It is always a good idea to average some measurements, before believing any of them, as measurement errors are a fact of life. Startup is a good example, and data transfer errors can arise at any time.

When using the pressure sensor as an altimeter, it has already been pointed out that you need to calibrate it according to the current sea level pressure, as reported by airports and on line weather services. That value changes significantly day to day, and even by the hour if a storm is passing.

@paulpaulson Yes, I did read the full spec :slight_smile: I'm not sure if your answer is relevant here as I'm not complaining about the altitude values (which are indeed wrong since, as you point out, I did not take the trouble of setting a real-life sea level reference for this test), but rather I want to understand why the first measurement significally differs from the subsequent ones, especially as far as temperature and pressure are concerned (altitude being merely the result of a computation out of the pressure value).

I've removed the altitude mentions in the original post to make my point clearer.

@anon94801460 I fully agree on the averaging need. However, I'm still intrigued by two things :

  • The choice of the oversampling and filtering modes have no influence whatsoever on this first measurement error, so even when the sensor is itself averaging, the error arises.
  • This first measurement is always wrong, but always with the same value at each reset. It indeed looks like a transmission error, but I cannot see why it happens (nothing in the sensor datasheet about that, and the I2C is not supposed to cause such a systematic transmission error, even on first exchange!!).

I would just ignore the first value.

For example, when switching ADC channels on a typical microprocessor, most people toss the first reading as a matter of course.

why don’t you take first throw away measurement in set up?

Hi @silverspur

Throwing away the first measurement is pretty much par for the course when it comes to many MEMS sensors.

The Bosch BMP388 barometer is very good though and is light years ahead of older models and their foibles.

A case in point was the Measurement Specialities MS5611 barometer, popular around 7 to 8 years ago. Taking temperature and pressure measurements would cause the device heat up affecting the results. It usually took around 20 measurements to get it warmed up enough before the readings settled down.

The earlier Bosch BMP085's barometer output plot would resemble a profile of the Alps and require considerable filtering in software to get meaningful results. However, Bosch has relentlessly persevered and is now the market leader in the field of MEMS barometers with some very nice devices.

Tiny, inexpensive MEMS sensors are amazing. The new models are rapidly improving, but they're not perfect, ...well not yet at least.

Hi all,

Thanks for your answers. My goal here was to make sure I did not make any mistakes in code or wiring, but it looks like from your answers that what I see is a normal sensor behaviour.

I will discard values up to a point where two consecutive values are sufficiently close together (which, from the results I have so far, always seems to happen for second and third measurements).

When you went to the Adafruit BMP3XX site and asked Adafruit, they make the sensor and library you are using - guess, what did they have to say about this issue?

adafruit/Adafruit_BMP3XX (github.com)