|
1 | 1 | # SPDX-FileCopyrightText: Copyright (c) 2020 Bryan Siepert for Adafruit Industries
|
2 | 2 | #
|
3 | 3 | # SPDX-License-Identifier: MIT
|
4 |
| -# The MIT License (MIT) |
5 |
| -# |
6 |
| -# Copyright (c) 2019 Bryan Siepert for Adafruit Industries |
7 |
| -# |
8 |
| -# Permission is hereby granted, free of charge, to any person obtaining a copy |
9 |
| -# of this software and associated documentation files (the "Software"), to deal |
10 |
| -# in the Software without restriction, including without limitation the rights |
11 |
| -# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell |
12 |
| -# copies of the Software, and to permit persons to whom the Software is |
13 |
| -# furnished to do so, subject to the following conditions: |
14 |
| -# |
15 |
| -# The above copyright notice and this permission notice shall be included in |
16 |
| -# all copies or substantial portions of the Software. |
17 |
| -# |
18 |
| -# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR |
19 |
| -# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, |
20 |
| -# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE |
21 |
| -# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER |
22 |
| -# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, |
23 |
| -# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN |
24 |
| -# THE SOFTWARE. |
| 4 | + |
25 | 5 | """
|
26 | 6 | `adafruit_lsm6ds`
|
27 | 7 | ================================================================================
|
28 | 8 |
|
29 | 9 | CircuitPython helper library for the LSM6DS family of motion sensors from ST
|
30 | 10 |
|
31 | 11 |
|
32 |
| -* Author(s): Bryan Siepert |
| 12 | +* Author(s): Bryan Siepert, Jose David M. |
33 | 13 |
|
34 | 14 | Implementation Notes
|
35 | 15 | --------------------
|
36 | 16 |
|
37 | 17 | **Hardware:**
|
38 | 18 |
|
39 |
| -* Adafruit `LSM6DSOX 6 DoF Accelerometer and Gyroscope |
40 |
| - <https://www.adafruit.com/product/4438>`_ |
| 19 | +* `Adafruit LSM6DSOX 6 DoF Accelerometer and Gyroscope |
| 20 | + <https://www.adafruit.com/product/4438>`_ (Product ID: 4438) |
41 | 21 |
|
42 |
| -* Adafruit `ISM330DHCX - 6 DoF IMU - Accelerometer and Gyroscope |
43 |
| - <https://www.adafruit.com/product/4502>`_ |
| 22 | +* `Adafruit ISM330DHCX - 6 DoF IMU - Accelerometer and Gyroscope |
| 23 | + <https://www.adafruit.com/product/4502>`_ (Product ID: 4502) |
44 | 24 |
|
45 |
| -* Adafruit `LSM6DSO32 6-DoF Accelerometer and Gyroscope |
46 |
| - <https://www.adafruit.com/product/4692>`_ |
| 25 | +* `Adafruit LSM6DSO32 6-DoF Accelerometer and Gyroscope |
| 26 | + <https://www.adafruit.com/product/4692>`_ (Product ID: 4692) |
47 | 27 |
|
48 |
| -* Adafruit `LSM6DS33 6-DoF Accel + Gyro IMU |
49 |
| - <https://www.adafruit.com/product/4480>`_ |
| 28 | +* `Adafruit LSM6DS33 6-DoF Accel + Gyro IMU |
| 29 | + <https://www.adafruit.com/product/4480>`_ (Product ID: 4480) |
50 | 30 |
|
51 |
| -* Adafruit `ISM330DHCX + LIS3MDL FeatherWing - High Precision 9-DoF IMU |
52 |
| - <https://www.adafruit.com/product/4569>`_ |
| 31 | +* `Adafruit ISM330DHCX + LIS3MDL FeatherWing - High Precision 9-DoF IMU |
| 32 | + <https://www.adafruit.com/product/4569>`_ (Product ID: 4569) |
53 | 33 |
|
54 |
| -* Adafruit `LSM6DSOX + LIS3MDL - Precision 9 DoF IMU |
55 |
| - <https://www.adafruit.com/product/4517>`_ |
| 34 | +* `Adafruit LSM6DSOX + LIS3MDL - Precision 9 DoF IMU |
| 35 | + <https://www.adafruit.com/product/4517>`_ (Product ID: 4517) |
56 | 36 |
|
57 |
| -* Adafruit `LSM6DS33 + LIS3MDL - 9 DoF IMU with Accel / Gyro / Mag |
58 |
| - <https://www.adafruit.com/product/4485>`_ |
| 37 | +* `Adafruit LSM6DS33 + LIS3MDL - 9 DoF IMU with Accel / Gyro / Mag |
| 38 | + <https://www.adafruit.com/product/4485>`_ (Product ID: 4485) |
59 | 39 |
|
60 |
| -* Adafruit `LSM6DSOX + LIS3MDL FeatherWing - Precision 9-DoF IMU |
61 |
| - <https://www.adafruit.com/product/4565>`_ |
| 40 | +* `Adafruit LSM6DSOX + LIS3MDL FeatherWing - Precision 9-DoF IMU |
| 41 | + <https://www.adafruit.com/product/4565>`_ (Product ID: 4565) |
62 | 42 |
|
63 | 43 |
|
64 | 44 | **Software and Dependencies:**
|
@@ -184,8 +164,9 @@ class LSM6DS: # pylint: disable=too-many-instance-attributes
|
184 | 164 | # Structs
|
185 | 165 | _raw_accel_data = Struct(_LSM6DS_OUTX_L_A, "<hhh")
|
186 | 166 | _raw_gyro_data = Struct(_LSM6DS_OUTX_L_G, "<hhh")
|
187 |
| - # RWBits: |
| 167 | + _raw_temp_data = Struct(_LSM6DS_OUT_TEMP_L, "<h") |
188 | 168 |
|
| 169 | + # RWBits: |
189 | 170 | _accel_range = RWBits(2, _LSM6DS_CTRL1_XL, 2)
|
190 | 171 | _accel_data_rate = RWBits(4, _LSM6DS_CTRL1_XL, 4)
|
191 | 172 |
|
@@ -374,3 +355,18 @@ def high_pass_filter(self, value):
|
374 | 355 | if not AccelHPF.is_valid(value):
|
375 | 356 | raise AttributeError("range must be an `AccelHPF`")
|
376 | 357 | self._high_pass_filter = value
|
| 358 | + |
| 359 | + @property |
| 360 | + def temperature(self): |
| 361 | + """Temperature in Celsius""" |
| 362 | + # Data from Datasheet Table 4.3 |
| 363 | + # Temp range -40 to 85 Celsius |
| 364 | + # T_ADC_RES = ADC Res 16 bit |
| 365 | + # Stabilization time 500 μs |
| 366 | + |
| 367 | + temp = self._raw_temp_data[0] |
| 368 | + |
| 369 | + if temp > 0x550: |
| 370 | + return (temp - 2 ** 13) * 0.0625 |
| 371 | + |
| 372 | + return temp * 0.0625 |
0 commit comments