adafruit / Adafruit_BME280_Library

Arduino Library for BME280 sensors
Other
328 stars 301 forks source link

use compensation from reference implementation #79

Closed el-han closed 3 years ago

el-han commented 4 years ago

This PR is a proposed fix for #78

It uses the reference implementation of the compensation algorithm from the datasheet. This implementation uses division operations instead of bit shifts.

caternuson commented 4 years ago

Current code seems to match section 4.2.3 of datasheet: https://www.bosch-sensortec.com/media/boschsensortec/downloads/datasheets/bst-bme280-ds002.pdf Can you clarify where you are seeing the implementation you have coded?

el-han commented 4 years ago

I used the driver which is provided by Bosch as a reference: https://github.com/BoschSensortec/BME280_driver

caternuson commented 4 years ago

Thanks, so:

Running the library example bme280test with your updated code seems to work OK except for pressure, which looks to be off by a factor of 256 (or 2.56?). Test was run near sea level, so ~14.7 psi -> 101352.9 Pa = 1013.5 hPa

Screenshot from 2020-04-30 08-53-32

el-han commented 4 years ago

Aw bummer! Seems like I have overlooked the return line in readPressure(). Sorry for that! Yes, the pressure is off by factor 2.56. I will fix that.

caternuson commented 3 years ago

@elli89 Sorry for not getting back to this in a while. See suggested code change above. Also - did you test this, similar to my test above, to make sure the readings come out generally as expected?

caternuson commented 3 years ago

I'm going to go ahead and merge this. The one code suggestion was fairly cosmetic. Hopefully these updates help with #78.

Just tested one more time with latest updates and looks good. Screenshot from 2021-07-29 15-43-37