adafruit_lsm9ds1
¶
CircuitPython module for the LSM9DS1 accelerometer, magnetometer, gyroscope. Based on the driver from: https://github.com/adafruit/Adafruit_LSM9DS1
See examples/simpletest.py for a demo of the usage.
Author(s): Tony DiCola
Implementation Notes¶
Hardware:
Adafruit 9-DOF Accel/Mag/Gyro+Temp Breakout Board - LSM9DS1 (Product ID: 3387)
Software and Dependencies:
Adafruit CircuitPython firmware for the supported boards: https://circuitpython.org/downloads
Adafruit’s Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
- class adafruit_lsm9ds1.LSM9DS1[source]¶
Driver for the LSM9DS1 accelerometer, magnetometer, gyroscope.
- property accel_range: int¶
The accelerometer range. Must be a value of:
ACCELRANGE_2G
ACCELRANGE_4G
ACCELRANGE_8G
ACCELRANGE_16G
- property acceleration: Tuple[float, float, float]¶
The accelerometer X, Y, Z axis values as a 3-tuple of \(m/s^2\) values.
- property gyro: Tuple[float, float, float]¶
The gyroscope X, Y, Z axis values as a 3-tuple of rad/s values.
- property gyro_scale: int¶
The gyroscope scale. Must be a value of:
GYROSCALE_245DPS
GYROSCALE_500DPS
GYROSCALE_2000DPS
- property mag_gain: int¶
The magnetometer gain. Must be a value of:
MAGGAIN_4GAUSS
MAGGAIN_8GAUSS
MAGGAIN_12GAUSS
MAGGAIN_16GAUSS
- property magnetic: Tuple[float, float, float]¶
The magnetometer X, Y, Z axis values as a 3-tuple of gauss values.
- read_accel_raw() Tuple[int, int, int] [source]¶
Read the raw accelerometer sensor values and return it as a 3-tuple of X, Y, Z axis values that are 16-bit unsigned values. If you want the acceleration in nice units you probably want to use the acceleration property!
- read_gyro_raw() Tuple[int, int, int] [source]¶
Read the raw gyroscope sensor values and return it as a 3-tuple of X, Y, Z axis values that are 16-bit unsigned values. If you want the gyroscope in nice units you probably want to use the gyro property!
- read_mag_raw() Tuple[int, int, int] [source]¶
Read the raw magnetometer sensor values and return it as a 3-tuple of X, Y, Z axis values that are 16-bit unsigned values. If you want the magnetometer in nice units you probably want to use the magnetic property!
- class adafruit_lsm9ds1.LSM9DS1_I2C(i2c: I2C, mag_address: int = 30, xg_address: int = 107)[source]¶
Driver for the LSM9DS1 connect over I2C.
- Parameters:
i2c (I2C) – The I2C bus the device is connected to
mag_address (int) – A 8-bit integer that represents the i2c address of the LSM9DS1’s magnetometer. Options are limited to
0x1C
or0x1E
Defaults to0x1E
.xg_address (int) – A 8-bit integer that represents the i2c address of the LSM9DS1’s accelerometer and gyroscope. Options are limited to
0x6A
or0x6B
. Defaults to0x6B
.
Quickstart: Importing and using the device
Here is an example of using the
LSM9DS1
class. First you will need to import the libraries to use the sensorimport board import adafruit_lsm9ds1
Once this is done you can define your
board.I2C
object and define your sensor objecti2c = board.I2C() # uses board.SCL and board.SDA sensor = adafruit_lsm9ds1.LSM9DS1_I2C(i2c)
Now you have access to the
acceleration
,magnetic
gyro
andtemperature
attributesacc_x, acc_y, acc_z = sensor.acceleration mag_x, mag_y, mag_z = sensor.magnetic gyro_x, gyro_y, gyro_z = sensor.gyro temp = sensor.temperature
- class adafruit_lsm9ds1.LSM9DS1_SPI(spi: SPI, xgcs: DigitalInOut, mcs: DigitalInOut)[source]¶
Driver for the LSM9DS1 connect over SPI.
- Parameters:
spi (SPI) – The SPI bus the device is connected to
mcs (DigitalInOut) – The digital output pin connected to the LSM9DS1’s CSM (Chip Select Magnetometer) pin.
xgcs (DigitalInOut) – The digital output pin connected to the LSM9DS1’s CSAG (Chip Select Accelerometer/Gyroscope) pin.
Quickstart: Importing and using the device
Here is an example of using the
LSM9DS1
class. First you will need to import the libraries to use the sensorimport board import adafruit_lsm9ds1
Once this is done you can define your
board.SPI
object and define your sensor objectspi = board.SPI() sensor = adafruit_lsm9ds1.LSM9DS1_SPI(spi)
Now you have access to the
acceleration
,magnetic
gyro
andtemperature
attributesacc_x, acc_y, acc_z = sensor.acceleration mag_x, mag_y, mag_z = sensor.magnetic gyro_x, gyro_y, gyro_z = sensor.gyro temp = sensor.temperature