Skip to content

Commit 3d1aab0

Browse files
authored
Merge pull request #56 from Edrig/main
Create lsm6ds3.py
2 parents 56e024b + e9206e3 commit 3d1aab0

File tree

2 files changed

+60
-0
lines changed

2 files changed

+60
-0
lines changed

adafruit_lsm6ds/lsm6ds3.py

+45
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2022 Edrig
2+
#
3+
# SPDX-License-Identifier: MIT
4+
"""
5+
This module provides the `adafruit_lsm6ds.lsm6ds33` subclass of LSM6DS sensors
6+
===============================================================================
7+
"""
8+
from . import LSM6DS
9+
10+
11+
class LSM6DS3(LSM6DS): # pylint: disable=too-many-instance-attributes
12+
13+
"""Driver for the LSM6DS3 6-axis accelerometer and gyroscope.
14+
15+
:param ~busio.I2C i2c_bus: The I2C bus the LSM6DS3 is connected to.
16+
:param int address: The I2C device address. Defaults to :const:`0x6A`
17+
18+
19+
**Quickstart: Importing and using the device**
20+
21+
Here is an example of using the :class:`LSM6DS3` class.
22+
First you will need to import the libraries to use the sensor
23+
24+
.. code-block:: python
25+
26+
import board
27+
from adafruit_lsm6ds.lsm6ds3 import LSM6DS3
28+
29+
Once this is done you can define your `board.I2C` object and define your sensor object
30+
31+
.. code-block:: python
32+
33+
i2c = board.I2C() # uses board.SCL and board.SDA
34+
sensor = LSM6DS3(i2c)
35+
36+
Now you have access to the :attr:`acceleration` and :attr:`gyro`: attributes
37+
38+
.. code-block:: python
39+
40+
acc_x, acc_y, acc_z = sensor.acceleration
41+
gyro_x, gyro_z, gyro_z = sensor.gyro
42+
43+
"""
44+
45+
CHIP_ID = 0x6A

examples/lsm6ds_lsm6ds3_simpletest.py

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
# SPDX-FileCopyrightText: Copyright (c) 2022 Edrig
2+
#
3+
# SPDX-License-Identifier: MIT
4+
import time
5+
import board
6+
from adafruit_lsm6ds.lsm6ds3 import LSM6DS3
7+
8+
i2c = board.I2C() # uses board.SCL and board.SDA
9+
sensor = LSM6DS3(i2c)
10+
11+
while True:
12+
print("Acceleration: X:%.2f, Y: %.2f, Z: %.2f m/s^2" % (sensor.acceleration))
13+
print("Gyro X:%.2f, Y: %.2f, Z: %.2f radians/s" % (sensor.gyro))
14+
print("")
15+
time.sleep(0.5)

0 commit comments

Comments
 (0)