diff --git a/Adafruit_BMP085.cpp b/Adafruit_BMP085.cpp index 0c78e8d..4ecd49d 100644 --- a/Adafruit_BMP085.cpp +++ b/Adafruit_BMP085.cpp @@ -311,14 +311,28 @@ void Adafruit_BMP085::getPressure(float *pressure) /**************************************************************************/ void Adafruit_BMP085::getTemperature(float *temp) { - int32_t ut, x1, x2; + int32_t UT, X1, X2, B5; // following ds convention + float t; - readRawTemperature(&ut); + readRawTemperature(&UT); - x1 = (ut - _bmp085_coeffs.ac6) * _bmp085_coeffs.ac5 >> 15; - x2 = (_bmp085_coeffs.mc << 11) / (x1 + _bmp085_coeffs.md); - *temp = (x1+x2+8) >> 4; - *temp /= 10; + #if BMP085_USE_DATASHEET_VALS + // use datasheet numbers! + UT = 27898; + _bmp085_coeffs.ac6 = 23153; + _bmp085_coeffs.ac5 = 32757; + _bmp085_coeffs.mc = -8711; + _bmp085_coeffs.md = 2868; + #endif + + // step 1 + X1 = (UT - (int32_t)_bmp085_coeffs.ac6) * ((int32_t)_bmp085_coeffs.ac5) / pow(2,15); + X2 = ((int32_t)_bmp085_coeffs.mc * pow(2,11)) / (X1+(int32_t)_bmp085_coeffs.md); + B5 = X1 + X2; + t = (B5+8)/pow(2,4); + t /= 10; + + *temp = t; } /**************************************************************************/ diff --git a/examples/sensorapi/sensorapi.pde b/examples/sensorapi/sensorapi.pde index 22caa1b..d705d23 100644 --- a/examples/sensorapi/sensorapi.pde +++ b/examples/sensorapi/sensorapi.pde @@ -89,7 +89,9 @@ void loop(void) if (event.pressure) { /* Display atmospheric pressue in hPa */ - Serial.print(event.pressure); Serial.print(" hPa"); + Serial.print("Pressure: "); + Serial.print(event.pressure); + Serial.println(" hPa"); /* Calculating altitude with reasonable accuracy requires pressure * * sea level pressure for your position at the moment the data is * @@ -106,19 +108,26 @@ void loop(void) * For example, for Paris, France you can check the current mean * * pressure and sea level at: http://bit.ly/16Au8ol */ - float seaLevelPressure = SENSORS_PRESSURE_SEALEVELHPA; + /* First we get the current temperature from the BMP085 */ float temperature; bmp.getTemperature(&temperature); - - Serial.print(" ("); - Serial.print(bmp.pressureToAltitude(seaLevelPressure, + Serial.print("Temperature: "); + Serial.print(temperature); + Serial.println(" C"); + + /* Then convert the atmospheric pressure, SLP and temp to altitude */ + /* Update this next line with the current SLP for better results */ + float seaLevelPressure = SENSORS_PRESSURE_SEALEVELHPA; + Serial.print("Altitude: "); + Serial.print(bmp.pressureToAltitude(seaLevelPressure, event.pressure, temperature)); - Serial.println(" m)"); + Serial.println(" m"); + Serial.println(""); } else { Serial.println("Sensor error"); } - delay(250); + delay(1000); }