Skip to content

Commit e6cdd23

Browse files
committed
fixed temp scaling and updated example
1 parent 1ac62fd commit e6cdd23

File tree

2 files changed

+10
-8
lines changed

2 files changed

+10
-8
lines changed

adafruit_lps2x.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,6 @@ def __init__(self, i2c_bus, address=_LPS2X_DEFAULT_ADDRESS, chip_id=None):
144144
raise RuntimeError(
145145
"Failed to find LPS2X! Found chip ID 0x%x" % self._chip_id
146146
)
147-
148147
self.reset()
149148
self.initialize()
150149
sleep(0.010) # delay 10ms for first reading
@@ -174,8 +173,11 @@ def pressure(self):
174173
@property
175174
def temperature(self):
176175
"""The current temperature measurement in degrees C"""
176+
177177
raw_temperature = self._raw_temperature
178-
return (raw_temperature / self._temp_scaling) + 42.5 # pylint:disable=no-member
178+
return (
179+
raw_temperature / self._temp_scaling # pylint:disable=no-member
180+
) + self._temp_offset # pylint:disable=no-member
179181

180182
@property
181183
def data_rate(self):
@@ -222,10 +224,10 @@ def __init__(self, i2c_bus, address=_LPS2X_DEFAULT_ADDRESS):
222224
("LPS25_RATE_25_HZ", 4, 25, None),
223225
)
224226
)
225-
226227
super().__init__(i2c_bus, address, chip_id=_LPS25HB_CHIP_ID)
227228

228229
self._temp_scaling = 480
230+
self._temp_offset = 42.5
229231
# self._inc_spi_flag = 0x40
230232

231233
def initialize(self):
@@ -249,9 +251,7 @@ class LPS22(LPS2X):
249251
_reset = RWBit(_LPS22_CTRL_REG2, 2)
250252
_data_rate = RWBits(3, _LPS22_CTRL_REG1, 4)
251253

252-
def __init__(
253-
self, i2c_bus, address=_LPS2X_DEFAULT_ADDRESS, chip_id=_LPS22HB_CHIP_ID
254-
):
254+
def __init__(self, i2c_bus, address=_LPS2X_DEFAULT_ADDRESS):
255255
# Only adding Class-appropriate rates
256256
Rate.add_values(
257257
(
@@ -264,12 +264,12 @@ def __init__(
264264
)
265265
)
266266

267-
super().__init__(i2c_bus, address)
267+
super().__init__(i2c_bus, address, chip_id=_LPS22HB_CHIP_ID)
268268
self._temp_scaling = 100
269+
self._temp_offset = 0
269270

270271
def initialize(self):
271272
"""Configure the sensor with the default settings. For use after calling `reset()`"""
272-
# self.enabled = True
273273
self.data_rate = Rate.LPS22_RATE_75_HZ # pylint:disable=no-member
274274

275275
# void configureInterrupt(bool activelow, bool opendrain, bool data_ready,

examples/lps2x_simpletest.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
import adafruit_lps2x
55

66
i2c = busio.I2C(board.SCL, board.SDA)
7+
# uncomment and comment out the line after to use with the LPS22
8+
# lps = adafruit_lps2x.LPS22(i2c)
79
lps = adafruit_lps2x.LPS25(i2c)
810
while True:
911
print("Pressure: %.2f hPa" % lps.pressure)

0 commit comments

Comments
 (0)