Arduino Asked on December 28, 2021
I have a BMP280 and BMP180 pressure sensor and I have both of them connected via I²C to a ESP8266.
For the BMP180, I can get the sea level air pressure when I pass the pressure and altitude like so:
// https://github.com/sparkfun/BMP180_Breakout_Arduino_Library
#include <SFE_BMP180.h>
SFE_BMP180 bmp180;
[...]
Serial.print(bmp180.sealevel(pressure, 800));
Is there a similar thing for the BMP280? Reading pressure and temperature works fine:
#include <Adafruit_BMP280.h>
Adafruit_BMP280 bmp280;
[...]
double temperature = bmp280.readTemperature();
double pressure = bmp280.readPressure() / 100;
Try this following segment: I used it myself and it worked fine.
As you don't get any default Method for returning the sea-level pressure from BMP280, I had to calculate on my own.
#include <Wire.h>
#include "SPI.h" //Why? Because library supports SPI and I2C connection
#include <Adafruit_Sensor.h>
#include <Adafruit_BMP280.h>
//Setup connection of the sensor
Adafruit_BMP280 bmp; // I2C
/*//For SPI connection!
#define BMP_SCK 13
#define BMP_MISO 12
#define BMP_MOSI 11
#define BMP_CS 10
//Adafruit_BMP280 bme(BMP_CS); // hardware SPI
//Adafruit_BMP280 bme(BMP_CS, BMP_MOSI, BMP_MISO, BMP_SCK);
*/
//Variables
float pressure; //To store the barometric pressure (Pa)
float temperature; //To store the temperature (oC)
float SLpressure_mB;
int ELEVATION = 9; //PUT HERE THE ELEVATION OF YOUR LOCATION IN METERS
void setup() {
bmp.begin(); //Begin the sensor
Serial.begin(9600); //Begin serial communication at 9600bps
Serial.println("Equivalent Sea Level Pressure Test:");
}
void loop() {
//Read values from the sensor:
pressure = bmp.readPressure();
temperature = bmp.readTemperature();
SLpressure_mB = (((pressure * 100.0)/pow((1-((float)(ELEVATION))/44330), 5.255))/100.0)
//Print values to serial monitor:
Serial.print(F("Pressure: "));
Serial.print(pressure, 2);
Serial.print(" Pa");
Serial.print("t");
Serial.print(("Temp: "));
Serial.print(temperature);
Serial.print(" oC");
Serial.print("t");
Serial.print("Equivalent Sea Level Pressure: ");
Serial.print(SLpressure_mB, 2);
Serial.println(" mB");
delay(5000); //Update every 5 sec
}
Answered by prikarsartam on December 28, 2021
It seems this was planned for the Adafruit BMP280 library but not implemented. Looking at Adafruit_BMP280.h
we see commented code that has a method seaLevelForAltitude()
:
/*
class Adafruit_BMP280_Unified : public Adafruit_Sensor
{
public:
Adafruit_BMP280_Unified(int32_t sensorID = -1);
bool begin(uint8_t addr = BMP280_ADDRESS, uint8_t chipid = BMP280_CHIPID);
void getTemperature(float *temp);
void getPressure(float *pressure);
float pressureToAltitude(float seaLevel, float atmospheric, float temp);
float seaLevelForAltitude(float altitude, float atmospheric, float temp);
void getEvent(sensors_event_t*);
void getSensor(sensor_t*);
private:
uint8_t _i2c_addr;
int32_t _sensorID;
};
*/
In another library, BMP280-arduino-library, I found a function that seems to work:
double BMP280::sealevel(double P, double A)
// Given a pressure P (mb) taken at a specific altitude (meters),
// return the equivalent pressure (mb) at sea level.
// This produces pressure readings that can be used for weather measurements.
{
return(P/pow(1-(A/44330.0),5.255));
}
First, I just copied that function into my code (without the class name), due to the friendly pizza license. Later I switched to that library and it also worked fine.
Answered by Thomas Weller on December 28, 2021
Get help from others!
Recent Answers
Recent Questions
© 2024 TransWikia.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP