Skip to content

Commit b5feb58

Browse files
committed
Fixed BME680 loss of precision int math error in pressure/altitude measurements
BME680.pressure / 100 was integer division before being passed onward resulting in loss of sensor resoluiton for both altitude and pressure changes. - Changed to float math to fix the value only moving in 1hPa steps - Pressure/altitude should no longer appear "stuck" waiting to jump the next 1hPa change - Tested on RAK19003+BME680 It looks like BME280, BMP280, etc. should not be affected as their readPressure() is a float. BMP085 may have a similar problem, but I do not have one to test with.
1 parent a81dcb3 commit b5feb58

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

src/helpers/sensors/EnvironmentSensorManager.cpp

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -357,8 +357,11 @@ bool EnvironmentSensorManager::querySensors(uint8_t requester_permissions, Cayen
357357
if (BME680.performReading()) {
358358
telemetry.addTemperature(TELEM_CHANNEL_SELF, BME680.temperature);
359359
telemetry.addRelativeHumidity(TELEM_CHANNEL_SELF, BME680.humidity);
360-
telemetry.addBarometricPressure(TELEM_CHANNEL_SELF, BME680.pressure / 100);
361-
telemetry.addAltitude(TELEM_CHANNEL_SELF, 44330.0 * (1.0 - pow((BME680.pressure / 100) / TELEM_BME680_SEALEVELPRESSURE_HPA, 0.1903)));
360+
// pressure is uint32_t Pa — use float division so hPa/altitude are not truncated to whole hPa
361+
const float pressure_hpa = BME680.pressure / 100.0f;
362+
telemetry.addBarometricPressure(TELEM_CHANNEL_SELF, pressure_hpa);
363+
telemetry.addAltitude(TELEM_CHANNEL_SELF,
364+
44330.0f * (1.0f - powf(pressure_hpa / (float)TELEM_BME680_SEALEVELPRESSURE_HPA, 0.1903f)));
362365
telemetry.addAnalogInput(next_available_channel, BME680.gas_resistance);
363366
next_available_channel++;
364367
}

0 commit comments

Comments
 (0)