Skip to content

Commit 110242b

Browse files
authored
Merge pull request #30 from jposada202020/removing_pressure_reading_limitations
Removing pressure limitations, to unify behavior to BME280
2 parents 2431466 + dfc6011 commit 110242b

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

adafruit_bmp280.py

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -35,9 +35,6 @@
3535
_REGISTER_PRESSUREDATA = const(0xF7)
3636
_REGISTER_TEMPDATA = const(0xFA)
3737

38-
_BMP280_PRESSURE_MIN_HPA = const(300)
39-
_BMP280_PRESSURE_MAX_HPA = const(1100)
40-
4138

4239
"""iir_filter values"""
4340
IIR_FILTER_DISABLE = const(0)
@@ -105,7 +102,13 @@
105102
class Adafruit_BMP280: # pylint: disable=invalid-name
106103
"""Base BMP280 object. Use `Adafruit_BMP280_I2C` or `Adafruit_BMP280_SPI` instead of this. This
107104
checks the BMP280 was found, reads the coefficients and enables the sensor for continuous
108-
reads"""
105+
reads
106+
107+
.. note::
108+
The operational range of the BMP280 is 300-1100 hPa.
109+
Pressure measurements outside this range may not be as accurate.
110+
111+
"""
109112

110113
def __init__(self):
111114
# Check device ID.
@@ -158,7 +161,7 @@ def _reset(self):
158161
def _write_ctrl_meas(self):
159162
"""
160163
Write the values to the ctrl_meas register in the device
161-
ctrl_meas sets the pressure and temperature data acquistion options
164+
ctrl_meas sets the pressure and temperature data acquisition options
162165
"""
163166
self._write_register_byte(_REGISTER_CTRL_MEAS, self._ctrl_meas)
164167

@@ -320,18 +323,17 @@ def pressure(self):
320323
var3 = self._pressure_calib[2] * var1 * var1 / 524288.0
321324
var1 = (var3 + self._pressure_calib[1] * var1) / 524288.0
322325
var1 = (1.0 + var1 / 32768.0) * self._pressure_calib[0]
323-
if not var1:
324-
return _BMP280_PRESSURE_MIN_HPA
326+
if not var1: # avoid exception caused by division by zero
327+
raise ArithmeticError(
328+
"Invalid result possibly related to error while reading the calibration registers"
329+
)
325330
pressure = 1048576.0 - adc
326331
pressure = ((pressure - var2 / 4096.0) * 6250.0) / var1
327332
var1 = self._pressure_calib[8] * pressure * pressure / 2147483648.0
328333
var2 = pressure * self._pressure_calib[7] / 32768.0
329334
pressure = pressure + (var1 + var2 + self._pressure_calib[6]) / 16.0
330335
pressure /= 100
331-
if pressure < _BMP280_PRESSURE_MIN_HPA:
332-
return _BMP280_PRESSURE_MIN_HPA
333-
if pressure > _BMP280_PRESSURE_MAX_HPA:
334-
return _BMP280_PRESSURE_MAX_HPA
336+
335337
return pressure
336338

337339
@property

0 commit comments

Comments
 (0)