mirror of
https://github.com/adafruit/Adafruit_BMP085_Unified.git
synced 2025-07-30 17:07:14 +02:00
Fixed temp calculations
This commit is contained in:
@ -311,14 +311,28 @@ void Adafruit_BMP085::getPressure(float *pressure)
|
|||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
void Adafruit_BMP085::getTemperature(float *temp)
|
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;
|
#if BMP085_USE_DATASHEET_VALS
|
||||||
x2 = (_bmp085_coeffs.mc << 11) / (x1 + _bmp085_coeffs.md);
|
// use datasheet numbers!
|
||||||
*temp = (x1+x2+8) >> 4;
|
UT = 27898;
|
||||||
*temp /= 10;
|
_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;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
|
@ -89,7 +89,9 @@ void loop(void)
|
|||||||
if (event.pressure)
|
if (event.pressure)
|
||||||
{
|
{
|
||||||
/* Display atmospheric pressue in hPa */
|
/* 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 *
|
/* Calculating altitude with reasonable accuracy requires pressure *
|
||||||
* sea level pressure for your position at the moment the data is *
|
* 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 *
|
* For example, for Paris, France you can check the current mean *
|
||||||
* pressure and sea level at: http://bit.ly/16Au8ol */
|
* 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;
|
float temperature;
|
||||||
bmp.getTemperature(&temperature);
|
bmp.getTemperature(&temperature);
|
||||||
|
Serial.print("Temperature: ");
|
||||||
Serial.print(" (");
|
Serial.print(temperature);
|
||||||
Serial.print(bmp.pressureToAltitude(seaLevelPressure,
|
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,
|
event.pressure,
|
||||||
temperature));
|
temperature));
|
||||||
Serial.println(" m)");
|
Serial.println(" m");
|
||||||
|
Serial.println("");
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
Serial.println("Sensor error");
|
Serial.println("Sensor error");
|
||||||
}
|
}
|
||||||
delay(250);
|
delay(1000);
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user