# 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:

Software and Dependencies:

class adafruit_lsm9ds1.LSM9DS1[source]

Driver for the LSM9DS1 accelerometer, magnetometer, gyroscope.

accel_range

The accelerometer range. Must be a value of:

• ACCELRANGE_2G
• ACCELRANGE_4G
• ACCELRANGE_8G
• ACCELRANGE_16G
acceleration

The accelerometer X, Y, Z axis values as a 3-tuple of $$m/s^2$$ values.

gyro

The gyroscope X, Y, Z axis values as a 3-tuple of rad/s values.

gyro_scale

The gyroscope scale. Must be a value of:

• GYROSCALE_245DPS
• GYROSCALE_500DPS
• GYROSCALE_2000DPS
mag_gain

The magnetometer gain. Must be a value of:

• MAGGAIN_4GAUSS
• MAGGAIN_8GAUSS
• MAGGAIN_12GAUSS
• MAGGAIN_16GAUSS
magnetic

The magnetometer X, Y, Z axis values as a 3-tuple of gauss values.

read_accel_raw()[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 accelerometer property!

read_gyro_raw()[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 gyroscope property!

read_mag_raw()[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 magnetometer property!

read_temp_raw()[source]

Read the raw temperature sensor value and return it as a 12-bit signed value. If you want the temperature in nice units you probably want to use the temperature property!

temperature

The temperature of the sensor in degrees Celsius.

class adafruit_lsm9ds1.LSM9DS1_I2C(i2c, mag_address=30, xg_address=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 or 0x1E Defaults to 0x1E. xg_address (int) – A 8-bit integer that represents the i2c address of the LSM9DS1’s accelerometer and gyroscope. Options are limited to 0x6A or 0x6B. Defaults to 0x6B.

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 sensor

import board


Once this is done you can define your board.I2C object and define your sensor object

i2c = board.I2C()  # uses board.SCL and board.SDA


Now you have access to the acceleration, magnetic gyro and temperature attributes

acc_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, xgcs, mcs)[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 sensor

import board


Once this is done you can define your board.SPI object and define your sensor object

spi = board.SPI()

Now you have access to the acceleration, magnetic gyro and temperature attributes
acc_x, acc_y, acc_z = sensor.acceleration