Skip to content

Removing pressure limitations, to unify behavior to BME280 #30

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Apr 23, 2021
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 13 additions & 11 deletions adafruit_bmp280.py
Original file line number Diff line number Diff line change
Expand Up @@ -35,9 +35,6 @@
_REGISTER_PRESSUREDATA = const(0xF7)
_REGISTER_TEMPDATA = const(0xFA)

_BMP280_PRESSURE_MIN_HPA = const(300)
_BMP280_PRESSURE_MAX_HPA = const(1100)


"""iir_filter values"""
IIR_FILTER_DISABLE = const(0)
Expand Down Expand Up @@ -105,7 +102,13 @@
class Adafruit_BMP280: # pylint: disable=invalid-name
"""Base BMP280 object. Use `Adafruit_BMP280_I2C` or `Adafruit_BMP280_SPI` instead of this. This
checks the BMP280 was found, reads the coefficients and enables the sensor for continuous
reads"""
reads

.. note::
The operational range of the BMP280 is 300-1100 hPa.
Pressure measurements outside this range may not be as accurate.

"""

def __init__(self):
# Check device ID.
Expand Down Expand Up @@ -158,7 +161,7 @@ def _reset(self):
def _write_ctrl_meas(self):
"""
Write the values to the ctrl_meas register in the device
ctrl_meas sets the pressure and temperature data acquistion options
ctrl_meas sets the pressure and temperature data acquisition options
"""
self._write_register_byte(_REGISTER_CTRL_MEAS, self._ctrl_meas)

Expand Down Expand Up @@ -320,18 +323,17 @@ def pressure(self):
var3 = self._pressure_calib[2] * var1 * var1 / 524288.0
var1 = (var3 + self._pressure_calib[1] * var1) / 524288.0
var1 = (1.0 + var1 / 32768.0) * self._pressure_calib[0]
if not var1:
return _BMP280_PRESSURE_MIN_HPA
if not var1: # avoid exception caused by division by zero
raise ArithmeticError(
"Invalid result possibly related to error while reading the calibration registers"
)
pressure = 1048576.0 - adc
pressure = ((pressure - var2 / 4096.0) * 6250.0) / var1
var1 = self._pressure_calib[8] * pressure * pressure / 2147483648.0
var2 = pressure * self._pressure_calib[7] / 32768.0
pressure = pressure + (var1 + var2 + self._pressure_calib[6]) / 16.0
pressure /= 100
if pressure < _BMP280_PRESSURE_MIN_HPA:
return _BMP280_PRESSURE_MIN_HPA
if pressure > _BMP280_PRESSURE_MAX_HPA:
return _BMP280_PRESSURE_MAX_HPA

return pressure

@property
Expand Down