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
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 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!!).
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.
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?