BMP180 Calibration

Hello, I have a BMP180 and an Arduino UNO. I am using Adafruit_BMP085.h library. I want to get a more precise measurement of altitude and there is an explanation in the library example like this;

//you can get a more precise measurement of altitude
  // if you know the current sea level pressure which will
  // vary with weather and such. If it is 1015 millibars
  // that is equal to 101500 Pascals.
    Serial.print("Real altitude = ");
    Serial.print(bmp.readAltitude(101500));
    Serial.println(" meters");

I want to adjust that "101500" every time I start the board. So I wrote edit the code a bit;

#include <Wire.h>
#include <Adafruit_BMP085.h>
int basepressure;

/*************************************************** 
  This is an example for the BMP085 Barometric Pressure & Temp Sensor

  Designed specifically to work with the Adafruit BMP085 Breakout 
  ----> https://www.adafruit.com/products/391

  These displays use I2C to communicate, 2 pins are required to  
  interface
  Adafruit invests time and resources providing this open source code, 
  please support Adafruit and open-source hardware by purchasing 
  products from Adafruit!

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

// Connect VCC of the BMP085 sensor to 3.3V (NOT 5.0V!)
// Connect GND to Ground
// Connect SCL to i2c clock - on '168/'328 Arduino Uno/Duemilanove/etc thats Analog 5
// Connect SDA to i2c data - on '168/'328 Arduino Uno/Duemilanove/etc thats Analog 4
// EOC is not used, it signifies an end of conversion
// XCLR is a reset pin, also not used here

Adafruit_BMP085 bmp;
  
void setup() {
  Serial.begin(9600);
  if (!bmp.begin()) {
 Serial.println("Could not find a valid BMP085 sensor, check wiring!");
 while (1) {}
  }
  basepressure = bmp.readPressure(); //------------------------------------------------the part I added
}
  
void loop() {
    Serial.print("Temperature = ");
    Serial.print(bmp.readTemperature());
    Serial.println(" *C");
    
    Serial.print("Pressure = ");
    Serial.print(bmp.readPressure());
    Serial.println(" Pa");
    
    // Calculate altitude assuming 'standard' barometric
    // pressure of 1013.25 millibar = 101325 Pascal
    Serial.print("Altitude = ");
    Serial.print(bmp.readAltitude());
    Serial.println(" meters");

    Serial.print("Pressure at sealevel (calculated) = ");
    Serial.print(bmp.readSealevelPressure());
    Serial.println(" Pa");

  // you can get a more precise measurement of altitude
  // if you know the current sea level pressure which will
  // vary with weather and such. If it is 1015 millibars
  // that is equal to 101500 Pascals.
    Serial.print("Real altitude = ");
    Serial.print(bmp.readAltitude(basepressure)); //--------------------------------------the part I edited
    Serial.println(" meters");
    
    Serial.println();
    delay(500);
}

But this causes an output that can be seen in the image attached.

I took a look at the source code of the library and saw that the altitude parameter ("101500") is dependent on the SealevelPressure which is also calculated according to the Pressure (?). So, how can I make what I want? Should I use another library (if so, which one?) or is there any way to do that?

Thank you :slight_smile:

bmp_error.png

If you know your altitude, then the easiest way to calibrate the barometer (for the purpose of measuring the altitude at later times) is to calculate the equivalent sea level pressure P0 from the measured pressure P at your location.

Formula for calculating altitude H from P and P0 (in meters, at 15 degrees Celsius)

H = 44331*(1 - (P/P0)0.1903)

Formula for calculating P0 from altitude and P

P0 = P*(1 - H/44331)-5.256

jremington:
If you know your altitude, then the easiest way to calibrate the barometer (for the purpose of measuring the altitude at later times) is to calculate the equivalent sea level pressure P0 from the measured pressure P at your location.

Formula for calculating altitude H from P and P0 (in meters, at 15 degrees Celsius)

H = 44331*(1 - (P/P0)0.1903)

Formula for calculating P0 from altitude and P

P0 = P*(1 - H/44331)-5.256

Hi jremington, these are exactly what the code does here;

float Adafruit_BMP085::readAltitude(float sealevelPressure) {
  float altitude;

  float pressure = readPressure();

  altitude = 44330 * (1.0 - pow(pressure /sealevelPressure,0.1903));

  return altitude;
}

and here,

int32_t Adafruit_BMP085::readSealevelPressure(float altitude_meters) {
  float pressure = readPressure();
  return (int32_t)(pressure / pow(1.0-altitude_meters/44330, 5.255));
}

in the source code which is Adafruit_BMP085.cpp

So, do you have any solution for the problem mentioned above?

int basepressure;

Review the range of values that can be stored in an "int". Hint: sea level pressure in Pa.

jremington:

int basepressure;

Review the range of values that can be stored in an "int". Hint: sea level pressure in Pa.

The range is from -2147483648 to +2147483647 and the sea level pressure is around 101325

An int data type on an Uno can hold values from -32768 to 32767. Arduino data types.

The long data type can hold -2147483648 to +2147483647.

Hello, I have a BMP180 and an Arduino UNO.

jremington:

int basepressure;

Review the range of values that can be stored in an "int". Hint: sea level pressure in Pa.

groundFungus:
An int data type on an Uno can hold values from -32768 to 32767. Arduino data types.

The long data type can hold -2147483648 to +2147483647.

Woah, how a shame for me... I thank you at the bottom of my hearth jremington and groundFungus. And I apologize for my ignorance.