BMP280 Sampling rate

I’m currently working with an BMP280 (using the Adafruit BMP280 library) and an Arduino Pro Mini. I’m building a small home-made rocket and I want to know how high it’s going. Since flight time is very short (from start to max altitude, about 2-3 seconds), I want to measure altitude as fast as possible (ideally at least at 100Hz).

According to the datasheet, the BMP280 should be able to measure at this rate. Since sampling rate is important for my project, I want to know how long it takes to complete a measurement.

Datasheet : https://cdn-shop.adafruit.com/datasheets/BST-BMP280-DS001-11.pdf
Adafruit Library : Adafruit_BMP280_Library/Adafruit_BMP280.h at master · adafruit/Adafruit_BMP280_Library · GitHub
How to use BMP280 : https://www.best-microcontroller-projects.com/bmp280.html

I modified the example code in order to get the time in microseconds.

/***************************************************************************
  This is a library for the BMP280 humidity, temperature & pressure sensor

  Designed specifically to work with the Adafruit BMEP280 Breakout
  ----> http://www.adafruit.com/products/2651

  These sensors use I2C or SPI to communicate, 2 or 4 pins are required
  to interface.

  Adafruit invests time and resources providing this open source code,
  please support Adafruit andopen-source hardware by purchasing products
  from Adafruit!

  Written by Limor Fried & Kevin Townsend for Adafruit Industries.
  BSD license, all text above must be included in any redistribution
 ***************************************************************************/

#include "Wire.h"
#include "Adafruit_BMP280.h"

Adafruit_BMP280 bmp; // I2C

long current_Loop_Time;
long interval;
float altitude;


void setup() {
  Serial.begin(38400);
  if (!bmp.begin(0X76)) {
    Serial.println(F("Could not find a valid BMP280 sensor, check wiring!"));
    while (1);
  }

  /* Default settings from datasheet. */
  // https://cdn-shop.adafruit.com/datasheets/BST-BMP280-DS001-11.pdf   // BMP280 Datasheet
  // https://github.com/adafruit/Adafruit_BMP280_Library/blob/master/Adafruit_BMP280.h  // Adafruit BMP280 Library
  // https://www.best-microcontroller-projects.com/bmp280.html // How to use BMP280
  bmp.setSampling(Adafruit_BMP280::MODE_NORMAL,     /* Operating Mode. */
                  Adafruit_BMP280::SAMPLING_X2,     /* Temp. oversampling */
                  Adafruit_BMP280::SAMPLING_X16,    /* Pressure oversampling */
                  Adafruit_BMP280::FILTER_X16,      /* Filtering. */
                  Adafruit_BMP280::STANDBY_MS_4000); /* Standby time. */
}

void loop() {
  current_Loop_Time = micros();

  altitude = bmp.readAltitude(1013.25);

  interval = micros() - current_Loop_Time;
  
  Serial.print(interval); Serial.print(" ");
  Serial.print(altitude); Serial.print("m");
  Serial.println();
}

According to the sketch, I takes about 2100 microseconds (2.1 milliseconds) to complete a measure at my require setting, which is nice since I would easily be able to do over 100 measurement a second.
Setting :
Mode Normal
Sampling X1 (temp. oversampling)
Sampling X2 (pressure oversampling)
Filter X2
Standby MS 1

2112 828.78m
2120 828.47m
2108 828.71m
2132 828.78m
2108 828.78m
2124 828.78m
2108 828.96m
2112 828.71m
2104 828.71m
2116 828.41m
2108 828.41m
2112 828.16m
2116 828.47m
2108 828.47m
2116 828.23m
2108 828.23m

The issue is that no matter what setting I choose; I get about 2.1 milliseconds which I think should not happen. Even if a choose the "slowest" setting :

Mode Normal
Sampling X2 (temp. oversampling)
Sampling X16 (pressure oversampling)
Filter X16
Standby MS 4000

The only difference a notice between my setting and the “slowest” one is that altitude measure “stay” the same for much long, it’s not update as fast as with my setting. But still not 4 seconds as I would expect (since I setup standby time to be 4000 miliseconds).

What is wrong with my sketch (why am I getting the same time for both setting) ?
According the datasheet (3.8.1 Measurement time), the measurement time (in ms) with my setting should be around 7.5ms. Why am I measuring 2.1 milliseconds ?

Could someone please help my figuring out what the issue is?

Any help appreciated. Thanks.

According to the sketch, I takes about 2100 microseconds (2.1 milliseconds) to complete a measure at my require setting, which is nice since I would easily be able to do over 100 measurement a second.

That measure how long you need to read the measured value from the sensor. It doesn't say how long the sensor needs to do the measurement.

There are several ways to optimize the measurement rate:

  • use oversampling 1x for both temperature and pressure
  • don't read the temperature for every read of the pressure/altitude (needs library change)
  • change to SPI to read the sensor or increase the I2C speed (needs short bus length!)

Thanks pylon for your input.

How can it be that the measured time I read is faster than what the sensor should be capable of? In that case would it mean that the sensor measurement is faster than what the datasheet says?

Is it possible to measure how long the sensor needs to do the measurement? I still don’t get how I can read the sensor’s measurement (those 2.1 milliseconds) even though it should take longer than 2.1 milliseconds at the “slowest” setting to even give me a measure? Is it because I’m actually reading the same measurement over and over again until the sensor updates its measure, in other word, I’m asking for a measurement, but the sensor hasn’t had time to update so it’s “giving” me the previous measure? Is that what is happening?

In that specific sketch I did not change the I2C speed but in the main sketch it is set at 400Hz, or I might just use it in SPI mode. To be fair the speed is ok for me since I’m theoretically (according to the datasheet anyways) under 10 milliseconds which is me initial goal.

Finally, regarding the change of library do you have a specific library in mind?

Again, thank you for your input on this topic, it is very much appreciated.

How can it be that the measured time I read is faster than what the sensor should be capable of? In that case would it mean that the sensor measurement is faster than what the datasheet says?

No, you measure the time it takes to read the corresponding registers in the sensor. If you read them to fast you simply get twice the same value as no update happened in the meantime.

Is it possible to measure how long the sensor needs to do the measurement?

Yes and no. There is a bit in one register that tells you the sensor is measuring but at the rates you set your sensor to update you won't be fast enough reading that bit to get a suitable result.

But the datasheet tells you how long the measurement take for a given configuration. If you bought a real Bosch sensor you can count on these values (at least that's my experience with Bosch sensors).

I still don't get how I can read the sensor's measurement (those 2.1 milliseconds) even though it should take longer than 2.1 milliseconds at the "slowest" setting to even give me a measure?

Did you read my answer? I told you how you can make these readings faster. But you have to either change the library or change the physical interface.

Is it because I'm actually reading the same measurement over and over again until the sensor updates its measure, in other word, I'm asking for a measurement, but the sensor hasn't had time to update so it's "giving" me the previous measure? Is that what is happening?

Exactly.

Finally, regarding the change of library do you have a specific library in mind?

That was meant as modifying the library you have not choosing another one.

Thank you pylon for your help, I understand the sensor a bit better know.

Hello Rediron,

What was the final outcome? I'm soon going to be facing the same issue(s) with my experimental rocketry systems later this year (2020).

I read somewhere that data received by the BME280 (and, for that matter, the BMP280 as well) needs also to be averaged out over a given number of samples. I can't remember at the moment where this came across my desk but the person took 10 samples at a time and averaged them during the flights.

So, my goal would he similar to yours in that I'd like to have 10 data points per second requiring a 100/sec. logging rate.

I hope I am not confusing the original question.

Ralph

The BME280 can be configured to do oversampling automatically to reduce noise so you don't have to implement it on software

See the datasheet

hzrnbgy:
The BME280 can be configured to do oversampling automatically to reduce noise so you don't have to implement it on software

See the datasheet

Thank you, hzrnbgv,

I'm just getting started learning about components and their data sheets so I am still working on figuring out what these sheets are telling the reader. Apologies for the dumb question(s) on my part.

Ralph