Skip to content

Commit

Permalink
Merge pull request #36 from Ninic0c0/master
Browse files Browse the repository at this point in the history
Add temperature support
  • Loading branch information
dhalbert committed Apr 25, 2021
2 parents 25ea19f + f6748a3 commit 3c0bf24
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
15 changes: 13 additions & 2 deletions adafruit_lsm6ds/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -164,8 +164,7 @@ class LSM6DS: # pylint: disable=too-many-instance-attributes
"""Driver for the LSM6DSOX 6-axis accelerometer and gyroscope.
:param ~busio.I2C i2c_bus: The I2C bus the LSM6DSOX is connected to.
:param address: The I2C slave address of the sensor
:param address: The I2C address of the sensor
"""

# ROUnaryStructs:
Expand All @@ -174,6 +173,8 @@ class LSM6DS: # pylint: disable=too-many-instance-attributes
# Structs
_raw_accel_data = Struct(_LSM6DS_OUTX_L_A, "<hhh")
_raw_gyro_data = Struct(_LSM6DS_OUTX_L_G, "<hhh")
_raw_temp_data = Struct(_LSM6DS_OUT_TEMP_L, "<bb")

# RWBits:

_accel_range = RWBits(2, _LSM6DS_CTRL1_XL, 2)
Expand Down Expand Up @@ -248,6 +249,16 @@ def _add_accel_ranges():
)
)

@property
def temperature(self):
"""The temperature, in degrees Celsius."""
raw_temp_data = self._raw_temp_data

temperature_raw = raw_temp_data[0] | (raw_temp_data[1] << 8)
temperature_c = temperature_raw / 16.0 + 25.0

return temperature_c

@property
def acceleration(self):
"""The x, y, z acceleration values returned in a 3-tuple and are in m / s ^ 2."""
Expand Down
3 changes: 1 addition & 2 deletions adafruit_lsm6ds/ism330dhcx.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,7 @@ class ISM330DHCX(LSM6DS): # pylint: disable=too-many-instance-attributes
"""Driver for the LSM6DS33 6-axis accelerometer and gyroscope.
:param ~busio.I2C i2c_bus: The I2C bus the LSM6DS33 is connected to.
:param address: The I2C slave address of the sensor
:param address: The I2C address of the sensor
"""

CHIP_ID = 0x6B
Expand Down
3 changes: 1 addition & 2 deletions adafruit_lsm6ds/lsm6ds33.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ class LSM6DS33(LSM6DS): # pylint: disable=too-many-instance-attributes
"""Driver for the LSM6DS33 6-axis accelerometer and gyroscope.
:param ~busio.I2C i2c_bus: The I2C bus the LSM6DS33 is connected to.
:param address: The I2C slave address of the sensor
:param address: The I2C address of the sensor
"""

CHIP_ID = 0x69
3 changes: 1 addition & 2 deletions adafruit_lsm6ds/lsm6dso32.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ class LSM6DSO32(LSM6DS): # pylint: disable=too-many-instance-attributes
"""Driver for the LSM6DSO32 6-axis accelerometer and gyroscope.
:param ~busio.I2C i2c_bus: The I2C bus the LSM6DSO32 is connected to.
:param address: The I2C slave address of the sensor
:param address: The I2C address of the sensor
"""

CHIP_ID = LSM6DS_CHIP_ID
Expand Down
3 changes: 1 addition & 2 deletions adafruit_lsm6ds/lsm6dsox.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,7 @@ class LSM6DSOX(LSM6DS): # pylint: disable=too-many-instance-attributes
"""Driver for the LSM6DSOX 6-axis accelerometer and gyroscope.
:param ~busio.I2C i2c_bus: The I2C bus the LSM6DSOX is connected to.
:param address: The I2C slave address of the sensor
:param address: The I2C address of the sensor
"""

CHIP_ID = LSM6DS_CHIP_ID
Expand Down

0 comments on commit 3c0bf24

Please sign in to comment.