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.