Skip to content

Add temperature support #36

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 7 commits into from
Apr 25, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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