2424`adafruit_lps2x`
2525================================================================================
2626
27- Library for the ST LPS2x family of pressure sensors
27+ Library for the ST LPS2X family of pressure sensors
2828
2929* Author(s): Bryan Siepert
3030
3333
3434**Hardware:**
3535
36- * `LPS25HW Breakout <https://www.adafruit.com/products/4258 >`_
36+ * `LPS25HB Breakout <https://www.adafruit.com/products/45XX >`_
3737
3838**Software and Dependencies:**
3939 * Adafruit CircuitPython firmware for the supported boards:
4343
4444"""
4545__version__ = "0.0.0-auto.0"
46- __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_LPS2x.git"
47- # The MIT License (MIT)
48- #
49- # Copyright (c) 2019 Bryan Siepert for Adafruit Industries
50- #
51- # Permission is hereby granted, free of charge, to any person obtaining a copy
52- # of this software and associated documentation files (the "Software"), to deal
53- # in the Software without restriction, including without limitation the rights
54- # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
55- # copies of the Software, and to permit persons to whom the Software is
56- # furnished to do so, subject to the following conditions:
57- #
58- # The above copyright notice and this permission notice shall be included in
59- # all copies or substantial portions of the Software.
60- #
61- # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
62- # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
63- # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
64- # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
65- # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
66- # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
67- # THE SOFTWARE.
68-
69- __version__ = "0.0.0-auto.0"
70- __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_LPS2XW.git"
46+ __repo__ = "https://github.com/adafruit/Adafruit_CircuitPython_LPS2X.git"
7147from micropython import const
7248import adafruit_bus_device .i2c_device as i2cdevice
73- from adafruit_register .i2c_struct import UnaryStruct
49+ from adafruit_register .i2c_struct import ROUnaryStruct
7450from adafruit_register .i2c_bits import RWBits , ROBits
7551from adafruit_register .i2c_bit import RWBit
7652
77- # pylint: disable=bad-whitespace
78- # _INTERRUPT_CFG = const(0x0B)
79- # _THS_P_L = const(0x0C)
80- # _THS_P_H = const(0x0D)
8153_WHO_AM_I = const (0x0F )
8254_CTRL_REG1 = const (0x20 )
8355_CTRL_REG2 = const (0x21 )
84- # _CTRL_REG3 = const(0x2)
85- # _FIFO_CTRL = const(0x14)
86- # _REF_P_XL = const(0x15)
87- # _REF_P_L = const(0x16)
88- # _REF_P_H = const(0x17)
89- # _RPDS_L = const(0x18)
90- # _RPDS_H = const(0x19)
91- # _RES_CONF = const(0x1A)
92- # _INT_SOURCE = const(0x25)
93- # _FIFO_STATUS = const(0x26)
94- # _STATUS = const(0x27)
95- _PRESS_OUT_XL = const (0x28 | 0x80 ) # 0x28 | 0x80 to set auto increment
96- # _PRESS_OUT_XL = const(0x28)
97- _PRESS_OUT_L = const (0x29 )
98- _PRESS_OUT_H = const (0x2A )
99- _TEMP_OUT_L = const (0x2B )
100- # _TEMP_OUT_H = const(0x2C)
101- # _LPFP_RES = const(0x33)
56+ _PRESS_OUT_XL = const (0x28 | 0x80 ) # | 0x80 to set auto increment on multi-byte read
57+ _TEMP_OUT_L = const (0x2B | 0x80 ) # | 0x80 to set auto increment on multi-byte read
10258
10359_LPS25_CHIP_ID = 0xBD
10460_LPS25_DEFAULT_ADDRESS = 0x5D
105- # pylint: enable=bad-whitespace
61+
62+
10663class CV :
10764 """struct helper"""
10865
@@ -158,68 +115,33 @@ class Rate(CV):
158115)
159116
160117
161- class LPS25HW : # pylint: disable=too-many-instance-attributes
118+ class LPS2X : # pylint: disable=too-many-instance-attributes
162119 """Library for the ST LPS2x family of pressure sensors
163120
164- :param ~busio.I2C i2c_bus: The I2C bus the LPS34HW is connected to.
121+ :param ~busio.I2C i2c_bus: The I2C bus the LPS25HB is connected to.
165122 :param address: The I2C device address for the sensor. Default is ``0x5d`` but will accept
166123 ``0x5c`` when the ``SDO`` pin is connected to Ground.
167124
168125 """
169126
170- _chip_id = UnaryStruct (_WHO_AM_I , "<B" )
127+ _chip_id = ROUnaryStruct (_WHO_AM_I , "<B" )
171128 _reset = RWBit (_CTRL_REG2 , 2 )
172129 enabled = RWBit (_CTRL_REG1 , 7 )
173130 """Controls the power down state of the sensor. Setting to `False` will shut the sensor down"""
174131 _data_rate = RWBits (3 , _CTRL_REG1 , 4 )
175-
176- _raw_temperature = ROBits (16 , _TEMP_OUT_L , 0 , 2 )
132+ _raw_temperature = ROUnaryStruct (_TEMP_OUT_L , "<h" )
177133 _raw_pressure = ROBits (24 , _PRESS_OUT_XL , 0 , 3 )
178- # _reference_pressure = RWBits(24, _REF_P_XL, 0, 3)
179- # _pressure_offset = RWBits(16, _RPDS_L, 0, 2)
180-
181- # _block_updates = RWBit(_CTRL_REG1, 1)
182-
183- # _one_shot = RWBit(_CTRL_REG2, 0)
184134
185- # registers for configuring INT pin behavior
186- # _interrupt_cfg = UnaryStruct(_CTRL_REG3, "<B") # to read all values for latching?
187-
188- # # INT status registers
189- # _interrupt_active = RWBit(_INT_SOURCE, 2)
190- # _pressure_low = RWBit(_INT_SOURCE, 1)
191- # _pressure_high = RWBit(_INT_SOURCE, 0)
192-
193- # _auto_zero = RWBit(_INTERRUPT_CFG, 5)
194- # _reset_zero = RWBit(_INTERRUPT_CFG, 4)
195-
196- # _interrupts_enabled = RWBit(_INTERRUPT_CFG, 3)
197- # _interrupt_latch = RWBit(_INTERRUPT_CFG, 2)
198- # _interrupt_low = RWBit(_INTERRUPT_CFG, 1)
199- # _interrupt_high = RWBit(_INTERRUPT_CFG, 0)
200-
201- # _reset_filter = ROBits(8, _LPFP_RES, 0, 1)
202-
203- # _pressure_threshold = UnaryStruct(_THS_P_L, "<H")
204-
205- # low_pass_enabled = RWBit(_CTRL_REG1, 3)
206- # """True if the low pass filter is enabled. Setting to `True` will reduce the sensor bandwidth
207- # from ``data_rate/2`` to ``data_rate/9``, filtering out high-frequency noise."""
208-
209- # low_pass_config = RWBit(_CTRL_REG1, 2)
210- # """Setting to `True` will reduce the sensor bandwidth
211- # from ``data_rate/9`` to ``data_rate/20``, filtering out high-frequency noise."""
212135 def __init__ (self , i2c_bus , address = _LPS25_DEFAULT_ADDRESS ):
213136 self .i2c_device = i2cdevice .I2CDevice (i2c_bus , address )
214137 if not self ._chip_id in [_LPS25_CHIP_ID ]:
215- raise RuntimeError ("Failed to find LPS25HW! Chip ID 0x%x" % self ._chip_id )
138+ raise RuntimeError (
139+ "Failed to find LPS25HB! Found chip ID 0x%x" % self ._chip_id
140+ )
216141
217142 self .reset ()
218143 self .enabled = True
219144 self .data_rate = Rate .RATE_25_HZ # pylint:disable=no-member
220- print ("poopietest" )
221- # self._block_updates = True
222- # self._interrupt_latch = True
223145
224146 def reset (self ):
225147 """Reset the sensor, restoring all configuration registers to their defaults"""
@@ -231,9 +153,6 @@ def reset(self):
231153 @property
232154 def pressure (self ):
233155 """The current pressure measurement in hPa"""
234- # reset the filter to prevent spurious readings
235- # self._reset_filter # pylint: disable=pointless-statement
236-
237156 raw = self ._raw_pressure
238157
239158 if raw & (1 << 23 ) != 0 :
@@ -244,9 +163,7 @@ def pressure(self):
244163 def temperature (self ):
245164 """The current temperature measurement in degrees C"""
246165 raw_temperature = self ._raw_temperature
247- # if raw_temperature & 0x8000:
248- # raw_temperature = data - 0xffff
249- return 42.5 + raw_temperature / 480
166+ return (raw_temperature / 480 ) + 42.5
250167
251168 @property
252169 def data_rate (self ):
@@ -263,78 +180,3 @@ def data_rate(self, value):
263180 raise AttributeError ("data_rate must be a `Rate`" )
264181
265182 self ._data_rate = value
266-
267- # def read_pressure(self):
268- # """ returns pressure in hPa """
269- # data = int.from_bytes(self.i2c.mem_read(3, self.address, LPS_PRESSURE_OUT | 0x80))
270- # if data & 0x80000000:
271- # data = data - 0xffffffff
272- # return data / 4096
273-
274- # def read_temperature(self):
275- # """ return temperature in degrees celsius """
276- # data = int.from_bytes(self.i2c.mem_read(2, self.address, LPS_TEMP_OUT | 0x80))
277- # if data & 0x8000:
278- # data = data - 0xffff
279- # return 42.5 + data/480
280-
281- # def take_measurement(self):
282- # """Update the value of ``pressure`` and ``temperature`` by taking a single measurement.
283- # Only meaningful if ``data_rate`` is set to ``ONE_SHOT``"""
284- # self._one_shot = True
285- # while self._one_shot:
286- # pass
287-
288- # def zero_pressure(self):
289- # """Set the current pressure as zero and report the ``pressure`` relative to it"""
290- # self._auto_zero = True
291- # while self._auto_zero:
292- # pass
293-
294- # def reset_pressure(self):
295- # """Reset ``pressure`` to be reported as the measured absolute value"""
296- # self._reset_zero = True
297-
298- # @property
299- # def pressure_threshold(self):
300- # """The high presure threshold. Use ``high_threshold_enabled`` or
301- # ``high_threshold_enabled``to use it"""
302- # return self._pressure_threshold / 16
303-
304- # @pressure_threshold.setter
305- # def pressure_threshold(self, value):
306- # """The high value threshold"""
307- # self._pressure_threshold = (value * 16)
308-
309- # @property
310- # def high_threshold_enabled(self):
311- # """Set to `True` or `False` to enable or disable the high pressure threshold"""
312- # return self._interrupts_enabled and self._interrupt_high
313-
314- # @high_threshold_enabled.setter
315- # def high_threshold_enabled(self, value):
316- # self._interrupts_enabled = value
317- # self._interrupt_high = value
318-
319- # @property
320- # def low_threshold_enabled(self):
321- # """Set to `True` or `False` to enable or disable the low pressure threshold. **Note the
322- # low pressure threshold only works in relative mode**"""
323- # return self._interrupts_enabled and self._interrupt_low
324-
325- # @low_threshold_enabled.setter
326- # def low_threshold_enabled(self, value):
327- # self._interrupts_enabled = value
328- # self._interrupt_low = value
329-
330- # @property
331- # def high_threshold_exceeded(self):
332- # """Returns `True` if the pressure high threshold has been exceeded. Must be enabled by
333- # setting ``high_threshold_enabled`` to `True` and setting a ``pressure_threshold``."""
334- # return self._pressure_high
335-
336- # @property
337- # def low_threshold_exceeded(self):
338- # """Returns `True` if the pressure low threshold has been exceeded. Must be enabled by
339- # setting ``high_threshold_enabled`` to `True` and setting a ``pressure_threshold``."""
340- # return self._pressure_low
0 commit comments