I have a BMP280 sensor and when I detect altitude, while it is still, it will be constantly changing. For example, I have code that take 1000 readings from the altitude sensor and averages them then subtracts from all readings. So The altitude say starts at 0.2, and then it will go down to like -0.3 while staying still. Is this normal behavior? P.S. I am using the adafruit_BMP280 library.
code:
#include "bmp280.h"
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_BMP280.h>
void BMP280::initBmp280() {
status = bmp.begin();
if (!status) {
Serial.println("Flight computer has not identified valid bmp280 sensor.");
while (1) delay(10);
} else {
Serial.println("Flight computer has identified and connected with bmp280 sensor.");
}
/* Default settings from datasheet. */
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_500); /* Standby time. */
}
void BMP280::calibrate() {
Serial.println("Calibrating bmp280, keep it still.");
for (int i = 0; i < 1000; ++i) {
altitudeOffset+=bmp.readAltitude(1013.25);
}
altitudeOffset/=1000;
Serial.println("bmp280 calibrated.");
Serial.print("Altitude offset: ");
Serial.println(altitudeOffset);
}
float BMP280::getAltitude() {
float curAlt = bmp.readAltitude(1013.25)-altitudeOffset;
Serial.print(F("Approx altitude = "));
Serial.print(curAlt); /* Adjusted to local forecast! */
Serial.println(" m");
Serial.println();
return curAlt;
}