Skip to content

Commit fa2cb2c

Browse files
Merge pull request #41 from jposada202020/adding_temperature_property
adding_temperature_property
2 parents 0a51775 + faf4e9a commit fa2cb2c

File tree

1 file changed

+35
-39
lines changed

1 file changed

+35
-39
lines changed

adafruit_lsm6ds/__init__.py

Lines changed: 35 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -1,64 +1,44 @@
11
# SPDX-FileCopyrightText: Copyright (c) 2020 Bryan Siepert for Adafruit Industries
22
#
33
# 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+
255
"""
266
`adafruit_lsm6ds`
277
================================================================================
288
299
CircuitPython helper library for the LSM6DS family of motion sensors from ST
3010
3111
32-
* Author(s): Bryan Siepert
12+
* Author(s): Bryan Siepert, Jose David M.
3313
3414
Implementation Notes
3515
--------------------
3616
3717
**Hardware:**
3818
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)
4121
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)
4424
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)
4727
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)
5030
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)
5333
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)
5636
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)
5939
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)
6242
6343
6444
**Software and Dependencies:**
@@ -184,8 +164,9 @@ class LSM6DS: # pylint: disable=too-many-instance-attributes
184164
# Structs
185165
_raw_accel_data = Struct(_LSM6DS_OUTX_L_A, "<hhh")
186166
_raw_gyro_data = Struct(_LSM6DS_OUTX_L_G, "<hhh")
187-
# RWBits:
167+
_raw_temp_data = Struct(_LSM6DS_OUT_TEMP_L, "<h")
188168

169+
# RWBits:
189170
_accel_range = RWBits(2, _LSM6DS_CTRL1_XL, 2)
190171
_accel_data_rate = RWBits(4, _LSM6DS_CTRL1_XL, 4)
191172

@@ -374,3 +355,18 @@ def high_pass_filter(self, value):
374355
if not AccelHPF.is_valid(value):
375356
raise AttributeError("range must be an `AccelHPF`")
376357
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

Comments
 (0)