Datasheet
Run the following code to import the necessary modules and initialize the I2C connection with the sensor:
If you're connected using SPI, run the following code to initialise the SPI connection with the sensor:
Now you're ready to read values from the sensor using any of these properties:
acceleromter - A 3-tuple of X, Y, Z axis accelerometer values in meters/second squared.
magnetometer - A 3-tuple of X, Y, Z axis magnetometer values in gauss.
gyroscope - A 3-tuple of X, Y, Z axis gyroscope values in degrees/second.
temperature - The sensor temperature in degrees Celsius.
In addition you can adjust some properties by getting and setting their values:
accel_range - The range of the accelerometer, should be a value of ACCELRANGE_2G, ACCELRANGE_4G,
ACCELRANGE_8G, or ACCELRANGE_16G from the adafruit_lsm9ds1 module. The default is 2G.
mag_gain - The gain of the magnetometer, should be a value of MAGGAIN_4GAUSS, MAGGAIN_8GAUSS,
MAGGAIN_12GAUSS, or MAGGAIN_16GAUSS from the adafruit_lsm9ds1 module. The default is 4 gauss.
gyro_scale - The scale of the gyroscope, should be a value of GYROSCALE_245DPS, GYROSCALE_500DPS, or
GYROSCALE_2000DPS from the adafruit_lsm9ds1 module. The default is 245 DPS.
import board
import busio
import adafruit_lsm9ds1
i2c = busio.I2C(board.SCL, board.SDA)
sensor = adafruit_lsm9ds1.LSM9DS1_I2C(i2c)
import board
import busio
from digitalio import DigitalInOut, Direction
spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
csag = DigitalInOut(board.D5)
csag.direction = Direction.OUTPUT
csag.value = True
csm = DigitalInOut(board.D6)
csm.direction = Direction.OUTPUT
csm.value = True
sensor = adafruit_lsm9ds1.LSM9DS1_SPI(spi, csag, csm)
print('Acceleration (m/s^2): ({0:0.3f},{1:0.3f},{2:0.3f})'.format(*sensor.accelerometer))
print('Magnetometer (gauss): ({0:0.3f},{1:0.3f},{2:0.3f})'.format(*sensor.magnetometer))
print('Gyroscope (degrees/sec): ({0:0.3f},{1:0.3f},{2:0.3f})'.format(*sensor.gyroscope))
print('Temperature: {0:0.3f}C'.format(sensor.temperature))
© Adafruit Industries
https://learn.adafruit.com/adafruit-lsm9ds1-accelerometer-plus-gyro-plus-
magnetometer-9-dof-breakout
Page 18 of 23










