Fixed temp calculations

This commit is contained in:
KTOWN
2013-06-18 17:40:11 +02:00
parent 491d1375e7
commit 123b6711ec
2 changed files with 36 additions and 13 deletions

View File

@ -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;
}
/**************************************************************************/

View File

@ -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("Temperature: ");
Serial.print(temperature);
Serial.println(" C");
Serial.print(" (");
/* 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);
}