-
Notifications
You must be signed in to change notification settings - Fork 21
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #56 from Edrig/main
Create lsm6ds3.py
- Loading branch information
Showing
2 changed files
with
60 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
# SPDX-FileCopyrightText: Copyright (c) 2022 Edrig | ||
# | ||
# SPDX-License-Identifier: MIT | ||
""" | ||
This module provides the `adafruit_lsm6ds.lsm6ds33` subclass of LSM6DS sensors | ||
=============================================================================== | ||
""" | ||
from . import LSM6DS | ||
|
||
|
||
class LSM6DS3(LSM6DS): # pylint: disable=too-many-instance-attributes | ||
|
||
"""Driver for the LSM6DS3 6-axis accelerometer and gyroscope. | ||
:param ~busio.I2C i2c_bus: The I2C bus the LSM6DS3 is connected to. | ||
:param int address: The I2C device address. Defaults to :const:`0x6A` | ||
**Quickstart: Importing and using the device** | ||
Here is an example of using the :class:`LSM6DS3` class. | ||
First you will need to import the libraries to use the sensor | ||
.. code-block:: python | ||
import board | ||
from adafruit_lsm6ds.lsm6ds3 import LSM6DS3 | ||
Once this is done you can define your `board.I2C` object and define your sensor object | ||
.. code-block:: python | ||
i2c = board.I2C() # uses board.SCL and board.SDA | ||
sensor = LSM6DS3(i2c) | ||
Now you have access to the :attr:`acceleration` and :attr:`gyro`: attributes | ||
.. code-block:: python | ||
acc_x, acc_y, acc_z = sensor.acceleration | ||
gyro_x, gyro_z, gyro_z = sensor.gyro | ||
""" | ||
|
||
CHIP_ID = 0x6A |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
# SPDX-FileCopyrightText: Copyright (c) 2022 Edrig | ||
# | ||
# SPDX-License-Identifier: MIT | ||
import time | ||
import board | ||
from adafruit_lsm6ds.lsm6ds3 import LSM6DS3 | ||
|
||
i2c = board.I2C() # uses board.SCL and board.SDA | ||
sensor = LSM6DS3(i2c) | ||
|
||
while True: | ||
print("Acceleration: X:%.2f, Y: %.2f, Z: %.2f m/s^2" % (sensor.acceleration)) | ||
print("Gyro X:%.2f, Y: %.2f, Z: %.2f radians/s" % (sensor.gyro)) | ||
print("") | ||
time.sleep(0.5) |