# Adafruit LSM9DS1 Accelerometer + Gyro + Magnetometer 9-DOF Breakout

## Overview

![](https://cdn-learn.adafruit.com/assets/assets/000/092/390/medium800/sensors_Rev_A_iso_short.jpg?1592501310)

![](https://cdn-learn.adafruit.com/assets/assets/000/092/391/medium800/sensors_qt_short_P4636Front.jpg?1592501321)

Add motion, direction and orientation sensing to your Arduino project with this all-in-one 9-DOF sensor. Inside the chip are three sensors, one is a classic 3-axis accelerometer, which can tell you which direction is down towards the Earth (by measuring gravity) or how fast the board is accelerating in 3D space. The other is a 3-axis magnetometer that can sense where the strongest magnetic force is coming from, generally used to detect magnetic north. The third is a 3-axis gyroscope that can measure spin and twist. By combining this data you can REALLY orient yourself.

![](https://cdn-learn.adafruit.com/assets/assets/000/038/874/medium800/sensors_3387_kit_ORIG.jpg?1485985212)

We've carried the LSM9DS0 from ST for a while, and the LSM9DS1 is their latest offering. We thought this could really make for a great breakout, at a very nice price! Design your own activity or motion tracker with all the data... We spun up a breakout board that has all the extra circuitry you'll want, for use with an Arduino (or other microcontroller)

The LSM9DS1 is not the same set of sensors as the LSM9DS0. Here are some of the differences

- LSM9DS0 accelerometer has ±2/±4/±6/±8/±16 _g_ ranges. The LSM9DS1 has ±2/±4/±8/±16 _g_ (no ±6 _g_ range)
- LSM9DS0 magnetometer has ±2/±4/±8/±12 gauss ranges. The LSM9DS1 has ±4/±8/±12/±16 gauss ranges. So the LSM9DS0 has ±2 gauss low range where-as the LSM9DS1 has ±16 gauss high range
- LSM9DS0 and LSM9DS1 gyros&nbsp;_both_ have the same ±245/±500/±2000 dps ranges.

There are other differences, for example we noticed the LSM9DS1 has slightly worse accuracy. The gyro angular zero-rate (±25 for the LSM9DS0 and ±30 for the LSM9DS1 at the highest sensing range). The accelerometer offset accuracy is ±90 m_g_ for the LSM9DS1 and ±60 m_g_ for the LSM9DS0.

However, these offsets may not matter for most projects and the pricing of the LSM9DS1 is lower than the LSM9DS0

![](https://cdn-learn.adafruit.com/assets/assets/000/092/392/medium800/sensors_rev_a_short_quarter_back.jpg?1592501923)

![](https://cdn-learn.adafruit.com/assets/assets/000/092/393/medium800/sensors_short_P4636Back.jpg?1592501943)

The breakout board version of this sensor has both I2C and SPI interfaces. Attaching it to the Arduino is simple, power Vin and GND with 3-5VDC, and wire up I2C data on SCL and SDA, and you're ready to go! More advanced users can use SPI, our library has support for both. The breakout comes fully assembled and tested, with some extra header so you can use it on a breadboard. Four mounting holes make for a secure connection, and we put the popular power+data pins on one side, and the interrupt pins on the other side for a nice & compact breakout.

# **New New NEW for 2020!**

The Classic Blue revision of the popular LSM9DS1 breakout has a new baby sister in Adafruit Black! Fabbed at 1 x 0.7 inches and weighing just a few grams, she's everything you like about the Classic Blue LSM9DS1 in a smaller package, and somehow we managed to _add&nbsp;_the new&nbsp;[SparkFun qwiic](https://www.sparkfun.com/qwiic) compatible[STEMMA QT](https://learn.adafruit.com/introducing-adafruit-stemma-qt) connectors for the I2C bus so you don't even need to solder! Just wire one up to your favorite micro with a [plug-and-play cable](https://www.adafruit.com/?q=stemma%20qt%20cable) and use our example code and libraries to measure those DoF's!

# Adafruit LSM9DS1 Accelerometer + Gyro + Magnetometer 9-DOF Breakout

## Pinouts

![](https://cdn-learn.adafruit.com/assets/assets/000/092/387/medium800/sensors_P4636Front_edit_pinouts.jpg?1592499447)

![](https://cdn-learn.adafruit.com/assets/assets/000/092/388/medium800/sensors_P4636Back_edit_pinouts.jpg?1592499481)

![](https://cdn-learn.adafruit.com/assets/assets/000/038/877/medium800/sensors_pinouts.jpg?1485985263)

## Power Pins
The sensor on the breakout requires 3V power. Since many customers have 5V microcontrollers like Arduino, we tossed a 3.3V regulator on the board. Its ultra-low dropout so you can power it from 3.3V-5V just fine.  

- **Vin** - this is the power pin. Since the chip uses 3 VDC, we have included a voltage regulator on board that will take 3-5VDC and safely convert it down. To power the board, give it the same power as the logic level of your microcontroller - e.g. for a 5V micro like Arduino, use 5V
- **3V3** - this is the 3.3V output from the voltage regulator, you can grab up to 100mA from this if you like  
- **GND** - common ground for power and logic

## I2C Pins

- **SCL** - I2C clock pin, connect to your microcontrollers I2C clock line. This pin is level shifted so you can use 3-5V logic, and there's a 10K pullup on this pin.  
- **SDA** - I2C data pin, connect to your microcontrollers I2C data line. This pin is level shifted so you can use 3-5V logic, and there's a 10K pullup on this pin.

Primary: 

## SPI Pins

If you're interested in using SPI to interface with the LSM9DS1, you can!

- **SCL** - this is also the SPI clock pin, it's level shifted so you can use 3-5V logic input
- **SDA** - this is also the SPI MOSI pin, it's level shifted so you can use 3-5V logic input
- **CSAG** - this is the Accelerometer+Gyro subchip Chip Select, it's level shifted so you can use 3-5V logic input
- **CSM** - this is the Magnetometer subchip Select, it's level shifted so you can use 3-5V logic input
- **SDOAG** - this is the Accelerometer+Gyro subchip MISO pin - it's 3V logic out, but can be read properly by 5V logic chips.
- **SDOM/DOM** - this is the Magnetometer subchip MISO pin - it's 3V logic out, but can be read properly by 5V logic chips.

## Interrupt & Misc Pins

Since there's so many sensors in the LSM9DS1, there's quite a number of interrupt outputs.

- **DEN** - this is a pin that supposedly could be used to dynamically enable/disable the Gyro. There's actually no documentation on it but we break it out for you anyways.
- **INT1** & **INT2** - These are interrupts from the accelerometer/gyro subchip. We don't have specific library support for these so check the datasheet for what you can make these indicate. They are 3V-logic outputs
- **DRDY** - this is the accelerometer/gyro subchip data ready output. We don't have specific library support for these so check the datasheet for how you can set the registers to enable this pin. It is a 3V-logic output.
- **INTM** - This is the interrupt from the magnetometer subchip. We don't have specific library support for it so check the datasheet for what you can make it indicate. It is a 3V-logic output.

Info: 

### Black/Stemma QT Version only

- **[STEMMA QT Connectors](https://learn.adafruit.com/introducing-adafruit-stemma-qt)&nbsp;****-** These connectors allow you to make solderless connections to dev boards and [various other QT accessories](https://www.adafruit.com/?q=JST%20SH%204) using [Stemma QT cables](https://www.adafruit.com/?q=stemma%20qt%20cable)

# Adafruit LSM9DS1 Accelerometer + Gyro + Magnetometer 9-DOF Breakout

## Assembly

If you have the breadboard version of this sensor, you'll want to solder some header onto the sensor so it can be used in a breadboard. The Flora version does not require any extra assembly

![](https://cdn-learn.adafruit.com/assets/assets/000/018/590/medium800/sensors_2021kit_ORIG.jpg?1407180576)

 
## Prepare the header strip:
Cut the strip to length if necessary. It will be easier to solder if you insert it into a breadboard - **long pins down** ![sensors_header.jpg](https://cdn-learn.adafruit.com/assets/assets/000/018/592/medium640/sensors_header.jpg?1407180618)

## Add the breakout board:
Place the breakout board over the pins so that the short pins poke through the breakout pads![sensors_place.jpg](https://cdn-learn.adafruit.com/assets/assets/000/018/593/medium640/sensors_place.jpg?1407180631)

 
## And Solder!
 Be sure to solder all pins for reliable electrical contact.  
  
Solder the longer power/data strip first  
  
_(For tips on soldering, be sure to check out our_ [_Guide to Excellent Soldering_](http://learn.adafruit.com/adafruit-guide-excellent-soldering)_)._![sensors_solder1.jpg](https://cdn-learn.adafruit.com/assets/assets/000/018/594/medium640/sensors_solder1.jpg?1407180653)

![sensors_solder2.jpg](https://cdn-learn.adafruit.com/assets/assets/000/018/595/medium640/sensors_solder2.jpg?1407180668)

![sensors_solder3.jpg](https://cdn-learn.adafruit.com/assets/assets/000/018/596/medium640/sensors_solder3.jpg?1407180678)

If you plan to use the interrupts and/or you want the board to sit flatter in a breadboard, solder up the other strip!

![sensors_solder4.jpg](https://cdn-learn.adafruit.com/assets/assets/000/018/597/medium640/sensors_solder4.jpg?1407180686)

You're done! Check your solder joints visually and continue onto the next steps

![sensors_done.jpg](https://cdn-learn.adafruit.com/assets/assets/000/018/598/medium640/sensors_done.jpg?1407180744)

# Adafruit LSM9DS1 Accelerometer + Gyro + Magnetometer 9-DOF Breakout

## Arduino Code

# Wiring for Arduino

&nbsp;

Info: 

You can easily wire this breakout to any microcontroller, we'll be using a Metro, Adafruit's Arduino compatible board. For another kind of microcontroller, just make sure it has I2C or SPI, then port the code - its pretty simple stuff!  
  
Let's start with just I2C interfacing since it requires the fewest number of wires. Here is how you would wire up one of the newer revision boards with the black PCB by using the new Stemma QT connectors:

- &nbsp;Connect&nbsp;**board VIN (red wire)&nbsp;**to&nbsp; **Arduino&nbsp;**** 5V **&nbsp;if you are running a&nbsp;** 5V**&nbsp;board Arduino (Uno, etc.).&nbsp;If your board is**&nbsp;3V,&nbsp;**connect to that instead.
- Connect **&nbsp;board&nbsp;**** GND (black wire)&nbsp; **to&nbsp;** Arduino **&nbsp;** GND**
- Connect **&nbsp;board&nbsp;**** SCL (yellow wire)&nbsp; **to&nbsp;** Arduino **&nbsp;** SCL**
- Connect **&nbsp;board&nbsp;**** SDA (blue wire)&nbsp; **to&nbsp;** Arduino **&nbsp;** SDA**

![sensors_c_arduino_wiring_qt_left.png](https://cdn-learn.adafruit.com/assets/assets/000/092/397/medium640/sensors_c_arduino_wiring_qt_left.png?1592520491)

If you prefer to use a breadboard wire up the sensor like this:

- &nbsp;Connect&nbsp;**board VIN (red wire)&nbsp;**to&nbsp; **Arduino&nbsp;**** 5V **&nbsp;if you are running a&nbsp;** 5V**&nbsp;board Arduino (Uno, etc.).&nbsp;If your board is**&nbsp;3V,&nbsp;**connect to that instead.
- Connect **&nbsp;board&nbsp;**** GND (black wire)&nbsp; **to&nbsp;** Arduino **&nbsp;** GND**
- Connect **&nbsp;board&nbsp;**** SCL (yellow wire)&nbsp; **to&nbsp;** Arduino **&nbsp;** SCL**
- Connect **&nbsp;board&nbsp;**** SDA (blue wire)&nbsp; **to&nbsp;** Arduino **&nbsp;** SDA**

![sensors_c_arduino_wiring_bb.png](https://cdn-learn.adafruit.com/assets/assets/000/092/398/medium640/sensors_c_arduino_wiring_bb.png?1592521286)

If you have one of the classic blue versions of&nbsp; the LSM9DS1, you'll wire it up like so:

![](https://cdn-learn.adafruit.com/assets/assets/000/049/701/medium800/sensors_LSM9DS1_test_bb.png?1514413051)

- Connect **Vin** to the power supply, 3-5V is fine. Use the same voltage that the microcontroller logic is based off of. For most Arduinos, that is 5V  
- Connect **GND** to common power/data ground
- Connect the **SCL** pin to the I2C clock **SCL** pin on your Arduino. On an UNO & '328 based Arduino, this is also known as **A5** , on a Mega it is also known as **digital 21** and on a Leonardo/Micro, **digital 3**
- Connect the **SDA** pin to the I2C data **SDA** pin on your Arduino. On an UNO & '328 based Arduino, this is also known as **A4** , on a Mega it is also known as **digital 20** and on a Leonardo/Micro, **digital 2**

# Download Arduino libraries

To begin reading sensor data, you will need to download the&nbsp; **Adafruit\_LSM9DS1&nbsp;** library and the **Adafruit\_Sensor** library from the Arduino library manager.

Open up the Arduino library manager:

![](https://cdn-learn.adafruit.com/assets/assets/000/084/458/medium800/sensors_1library_manager_menu.png?1574046079)

Search for the&nbsp; **Adafruit LSM9DS1&nbsp;** library and install it

![](https://cdn-learn.adafruit.com/assets/assets/000/084/460/medium800/sensors_lsm9ds1.png?1574046265)

Search for the&nbsp; **Adafruit Unified Sensor&nbsp;** library and install it (You may have to scroll down pretty far to find it)

![](https://cdn-learn.adafruit.com/assets/assets/000/084/461/medium800/sensors_unified.png?1574046298)

We also have a great tutorial on Arduino library installation at:  
[http://learn.adafruit.com/adafruit-all-about-arduino-libraries-install-use](http://learn.adafruit.com/adafruit-all-about-arduino-libraries-install-use "Link: http://learn.adafruit.com/adafruit-all-about-arduino-libraries-install-use")

# Load Demo Sketch

Now you can open up **File-\>Examples-\>Adafruit\_LSM9DS1**** -\>lsm9ds1** and upload to your Arduino wired up to the sensor

![](https://cdn-learn.adafruit.com/assets/assets/000/038/879/medium800/sensors_test.png?1485986943)

Then open up the Serial console at 115200 baud to read the sensor output! You'll get 9 distinct data points, accelerometer x/y/z in meters/s<sup>2</sup>, magetometer x/y/z in gauss and gyroscope in x/y/x degrees/second

![](https://cdn-learn.adafruit.com/assets/assets/000/038/880/medium800/sensors_outptus.png?1485987038)

We suggest using this **Adafruit\_Sensor** interface as shown in this demo, since it will let you swap sensors without having to worry about units compatibility. Try twisting and moving the board around to see the sensors change value.

# Library Reference

The library we have is simple and easy to use  
  
You can create the **Adafruit\_LSM9DS1** object with:

```
Adafruit_LSM9DS1 lsm = Adafruit_LSM9DS1();  // i2c sensor
```

I2C does not have pins, as they are fixed in hardware.  
  
If you're using "hardware" SPI, you will have to wire up the pins as follows:

- **SCL** -\> **SPI CLK**
- **SDA** -\> **SPI MOSI**
- **SDO\_AG** & **SDO\_M** -\> **SPI MISO** (both together)

[You can determine the hardware SPI pins for your Arduino here](http://arduino.cc/en/Reference/SPI "Link: http://arduino.cc/en/Reference/SPI") Then pick two pins for the CS lines

```
Adafruit_LSM9DS1 lsm = Adafruit_LSM9DS1(LSM9DS1_XGCS, LSM9DS1_MCS);
```

If you don't want to use the hardware SPI, you can also try the soft SPI capability, which is bitbanged. You can basically use any pins you like!

```
Adafruit_LSM9DS1 lsm = Adafruit_LSM9DS1(LSM9DS1_SCK, LSM9DS1_MISO, LSM9DS1_MOSI, LSM9DS1_XGCS, LSM9DS1_MCS);
```

# Begin!
To initialize the sensor, call **lsm.begin()** which will check the sensor can be found. It returns true/false depending on these checks. We suggest you wrap begin() in a statement that will check if the sensor was located:  
```
if(!lsm.begin())
  {
    /* There was a problem detecting the LSM9DS1 ... check your connections */
    Serial.print(F("Ooops, no LSM9DS1 detected ... Check your wiring!"));
    while(1);
  }
```

# Set Ranges
These chips have tons of registers, we basically provide interface code for the most useful stuff, such as setting the range. Each subsensor has it's own range. Higher ranges have less precision but can measure larger movements!  
Set up the ranges with the **setup** functions:  
```
// 1.) Set the accelerometer range
  lsm.setupAccel(lsm.LSM9DS1_ACCELRANGE_2G);
  //lsm.setupAccel(lsm.LSM9DS1_ACCELRANGE_4G);
  //lsm.setupAccel(lsm.LSM9DS1_ACCELRANGE_8G);
  //lsm.setupAccel(lsm.LSM9DS1_ACCELRANGE_16G);
  
  // 2.) Set the magnetometer sensitivity
  lsm.setupMag(lsm.LSM9DS1_MAGGAIN_4GAUSS);
  //lsm.setupMag(lsm.LSM9DS1_MAGGAIN_8GAUSS);
  //lsm.setupMag(lsm.LSM9DS1_MAGGAIN_12GAUSS);
  //lsm.setupMag(lsm.LSM9DS1_MAGGAIN_16GAUSS);

  // 3.) Setup the gyroscope
  lsm.setupGyro(lsm.LSM9DS1_GYROSCALE_245DPS);
  //lsm.setupGyro(lsm.LSM9DS1_GYROSCALE_500DPS);
  //lsm.setupGyro(lsm.LSM9DS1_GYROSCALE_2000DPS);
```

Choose whichever range you like, after you begin() the sensor!

# Read data
Read data using the Adafruit\_Sensor API by first creating four events, one for each sub-sensor:  
```
sensors_event_t accel, mag, gyro, temp;
```

Then pass these into the **getEvent** function

```
lsm.getEvent(&amp;accel, &amp;mag, &amp;gyro, &amp;temp);
```

The data is snapshotted at once, so you can read and manage the data later.   
  
For the Accelerometer event you can read **accel.acceleration.x** , **accel.acceleration.y** or **accel.acceleration.z** which are in meters/second\*second.  
  
For the Magnetometer event you can read **mag.magnetic.x** , **mag.magnetic.y** or **mag.magnetic.z** which are in gauss.  
  
For the Gyro event you can read **gyro.gyro.x, gyro.gyro.y** or **gyro.gyro.z** , which are in degrees-per-second (dps)  
  
The temperature event data is in **temp.temperature** , but we don't guarantee that the temperature data is in degrees C

![](https://cdn-learn.adafruit.com/assets/assets/000/084/461/medium800/sensors_unified.png?1574046298)

# Adafruit LSM9DS1 Accelerometer + Gyro + Magnetometer 9-DOF Breakout

## Python & CircuitPython

Info: 

# CircuitPython Microcontroller Wiring

First wire up a LSM9DS1&nbsp;to your board exactly as shown on the previous pages for Arduino. You can use either I2C or SPI wiring, although it's recommended to use I2C for simplicity.

## I2C

Here's an example of wiring a Feather M0 to the sensor with an I2C connection, either the new classic blue form factor, or the newer revisions either on a breadboard or using the Stemma QT connectors:

It's easy to use the LSM9DS1&nbsp;sensor with Python or CircuitPython, and the&nbsp;[Adafruit CircuitPython LSM9DS1](https://github.com/adafruit/Adafruit_CircuitPython_LSM9DS1)&nbsp;module.&nbsp; This module allows you to easily write Python code that reads the accelerometer, magnetometer, and gyroscope&nbsp;from the sensor.

You can use this sensor with any CircuitPython microcontroller board or with a computer that has GPIO and Python [thanks to Adafruit\_Blinka, our CircuitPython-for-Python compatibility library](https://learn.adafruit.com/circuitpython-on-raspberrypi-linux).

- **Board 3V** &nbsp;to&nbsp; **sensor VIN**
- **Board GND** &nbsp;to&nbsp; **sensor GND**
- **Board SCL** &nbsp;to&nbsp; **sensor&nbsp;SCL**
- **Board SDA** &nbsp;to&nbsp; **sensor SDA**

![sensors_d_cp_feather_wiring_qt_other_side.png](https://cdn-learn.adafruit.com/assets/assets/000/092/400/medium640/sensors_d_cp_feather_wiring_qt_other_side.png?1592521739)

![sensors_d_cp_feather_wiring_bb.png](https://cdn-learn.adafruit.com/assets/assets/000/092/401/medium640/sensors_d_cp_feather_wiring_bb.png?1592521815)

![sensors_d_cp_rev_a_i2cbb.png](https://cdn-learn.adafruit.com/assets/assets/000/092/402/medium640/sensors_d_cp_rev_a_i2cbb.png?1592521901)

## SPI

Wiring up the LSM9DS1 to a Feather M0 using SPI is a bit more complicated due to the addition of two sets of Sensor Out and CS pins. Wiring for the newer or older versions of the board are pretty similar

- **Board 3V** &nbsp;to&nbsp;**sensor VIN (Red)**
- **Board GND** &nbsp;to&nbsp;**sensor GND (Black)**
- **Board SCK** &nbsp;to&nbsp;**sensor SCL (Purple)**
- **Board MOSI** &nbsp;to&nbsp;**sensor SDA (Green)**
- **Board MISO&nbsp;** to **&nbsp;sensor SDOAG&nbsp;** AND**&nbsp;sensor DOM (Orange)**
- **Board D5&nbsp;** to**&nbsp;sensor CSAG (Yellow)**
- **Board D6&nbsp;** to**&nbsp;sensor CSM (Blue)**

![sensors_d_cp_feather_wiring_z_spi.png](https://cdn-learn.adafruit.com/assets/assets/000/092/403/medium640/sensors_d_cp_feather_wiring_z_spi.png?1592522255)

To use the classic blue board with SPI

- **Board 3V** &nbsp;to&nbsp;**sensor VIN (Red)**
- **Board GND** &nbsp;to&nbsp;**sensor GND (Black)**
- **Board SCK** &nbsp;to&nbsp;**sensor SCL (Purple)**
- **Board MOSI** &nbsp;to&nbsp;**sensor SDA (Green)**
- **Board MISO&nbsp;** to **&nbsp;sensor SDOAG&nbsp;** AND**&nbsp;sensor SDOM (Orange)**
- **Board D5&nbsp;** to**&nbsp;sensor CSAG (Yellow)**
- **Board D6&nbsp;** to**&nbsp;sensor CSM (Blue)**

![sensors_FeatherM0_LSM9DS1_SPI_bb.jpg](https://cdn-learn.adafruit.com/assets/assets/000/067/331/medium640/sensors_FeatherM0_LSM9DS1_SPI_bb.jpg?1544215742)

# Python Computer Wiring

Since there's _dozens_ of Linux computers/boards you can use we will show wiring for Raspberry Pi. For other platforms, [please visit the guide for CircuitPython on Linux to see whether your platform is supported](https://learn.adafruit.com/circuitpython-on-raspberrypi-linux).&nbsp;

## I2C
- **Pi 3V3** to **sensor VIN**
- **Pi GND** to **sensor GND**
- **Pi SCL** to **sensor SCL**
- **Pi SDA** to **sensor SDA**

![sensors_d_rpi_wiring_a_qt.png](https://cdn-learn.adafruit.com/assets/assets/000/092/404/medium640/sensors_d_rpi_wiring_a_qt.png?1592522768)

![sensors_d_rpi_wiring_bb.png](https://cdn-learn.adafruit.com/assets/assets/000/092/405/medium640/sensors_d_rpi_wiring_bb.png?1592522822)

![sensors_d_cp_rev_a_pi_i2cbb.jpg](https://cdn-learn.adafruit.com/assets/assets/000/092/406/medium640/sensors_d_cp_rev_a_pi_i2cbb.jpg?1592522858)

## SPI

Here's the Raspberry Pi wired with SPI:

- **Pi 3V3** to&nbsp; **sensor VIN**
- **Pi GND** &nbsp;to&nbsp; **sensor GND**
- **Pi SCLK** to&nbsp; **sensor&nbsp;SCL**
- **Pi MOSI** to&nbsp; **sensor SDA**
- **Pi MISO** to **sensor SDOAG** AND **sensor SDOM**
- **Pi GPIO5** to **sensor CSAG**
- **Pi GPIO6** to **sensor CSM**

![sensors_d_cp_rpi_wiring_z_spi.png](https://cdn-learn.adafruit.com/assets/assets/000/092/407/medium640/sensors_d_cp_rpi_wiring_z_spi.png?1592523007)

![sensors_d_cp_rev_a_pi_spi.jpg](https://cdn-learn.adafruit.com/assets/assets/000/092/408/medium640/sensors_d_cp_rev_a_pi_spi.jpg?1592523049)

# CircuitPython Installation of LSM9DS1 Library

You'll need to install the&nbsp;[Adafruit CircuitPython LSM9DS1](https://github.com/adafruit/Adafruit_CircuitPython_LSM9DS1)&nbsp;library on your CircuitPython board.&nbsp;&nbsp;

First make sure you are running the&nbsp;[latest version of Adafruit CircuitPython](../../../../welcome-to-circuitpython/installing-circuitpython)&nbsp;for your board.

Next you'll need to install the necessary libraries&nbsp;to use the hardware--carefully follow the steps to find and install these libraries from&nbsp;[Adafruit's CircuitPython library bundle](https://github.com/adafruit/Adafruit_CircuitPython_Bundle).&nbsp; Our introduction guide has&nbsp;[a great page on how to install the library bundle](../../../../welcome-to-circuitpython/circuitpython-libraries)&nbsp;for both express and non-express boards.

Remember for non-express boards like the, you'll need to manually install the necessary libraries from the bundle:

- **adafruit\_lsm9ds1.mpy**
- **adafruit\_bus\_device**

Before continuing make sure your board's lib folder or root filesystem has the&nbsp; **adafruit\_lsm9ds1.mpy,&nbsp;** and **&nbsp;adafruit\_bus\_device**** &nbsp; **files and folders** &nbsp;**copied over.

Next[&nbsp;connect to the board's serial REPL](https://learn.adafruit.com/welcome-to-circuitpython/the-repl) so you are at the CircuitPython&nbsp; **\>\>\>** &nbsp;prompt.

# CircuitPython & Python Usage

To demonstrate the usage of the sensor we'll initialize it and read the accelerometer, magnetometer,&nbsp;and&nbsp;more from the board's Python REPL.

Run the following code to import the necessary modules and initialize the I2C connection with the sensor:

```python
import board
import adafruit_lsm9ds1
i2c = board.I2C()
sensor = adafruit_lsm9ds1.LSM9DS1_I2C(i2c)
```

If you're connected using SPI, run the following code to initialise the SPI connection with the sensor:

```python
import board
from digitalio import DigitalInOut, Direction
spi = board.SPI()
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)
```

Now you're ready to read values from the sensor using any of these properties:

- **acceleromter** &nbsp;-&nbsp;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.

```
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))
```

![](https://cdn-learn.adafruit.com/assets/assets/000/048/915/medium800/sensors_Screen_Shot_2017-12-05_at_7.20.49_PM.png?1512530468)

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&nbsp;ACCELRANGE\_2G, ACCELRANGE\_4G, ACCELRANGE\_8G, or ACCELRANGE\_16G from the adafruit\_lsm9ds1 module. &nbsp;The default is 2G.
- **mag\_gain** - The gain of the magnetometer, should be a value of&nbsp;MAGGAIN\_4GAUSS, MAGGAIN\_8GAUSS, MAGGAIN\_12GAUSS, or MAGGAIN\_16GAUSS from the adafruit\_lsm9ds1 module. &nbsp;The default is 4 gauss.
- **gyro\_scale** - The scale of the gyroscope, should be a value of&nbsp;GYROSCALE\_245DPS, GYROSCALE\_500DPS, or GYROSCALE\_2000DPS from the adafruit\_lsm9ds1 module. &nbsp;The default is 245 DPS.

```
sensor.accel_range = adafruit_lsm9ds1.ACCELRANGE_4G
sensor.mag_gain = adafruit_lsm9ds1.MAGGAIN_8GAUSS
sensor.gyro_scale = adafruit_lsm9ds1.GYROSCALE_500DPS
```

![](https://cdn-learn.adafruit.com/assets/assets/000/048/916/medium800/sensors_Screen_Shot_2017-12-05_at_7.21.34_PM.png?1512530513)

See the [simpletest.py example](https://github.com/adafruit/Adafruit_CircuitPython_LSM9DS1/blob/master/examples/lsm9ds1_simpletest.py) for a complete demo of printing the accelerometer, magnetometer, gyroscope&nbsp;every second. &nbsp;Save this as **code.py** on the board and examine the REPL output to see the range printed every second.

That's all there is to using the LSM9DS1&nbsp;with CircuitPython!

# Full Example Code
https://github.com/adafruit/Adafruit_CircuitPython_LSM9DS1/blob/main/examples/lsm9ds1_simpletest.py

# Adafruit LSM9DS1 Accelerometer + Gyro + Magnetometer 9-DOF Breakout

## Python Docs

# Adafruit LSM9DS1 Accelerometer + Gyro + Magnetometer 9-DOF Breakout

## Downloads

# Files

- [EagleCAD PCB files on GitHub](https://github.com/adafruit/Adafruit-LSM9DS1-Breakout-PCB)
- [Classic/Blue Fritzing object available in Adafruit Fritzing library](https://github.com/adafruit/Fritzing-Library/blob/master/parts/Adafruit%20LSM9DS1%209DoF%20Breakout.fzpz)
- [Stemma QT/Black Fritzing object available in Adafruit Fritzing library](https://github.com/adafruit/Fritzing-Library/blob/master/parts/Adafruit%20LSM9DS1%209DoF%20Breakout%20Stemma%20QT.fzpz)

[LSM9DS1.pdf Datasheet](https://cdn-learn.adafruit.com/assets/assets/000/038/883/original/LSM9DS1.pdf?1485999363)
# Schematic
## **Classic/Blue**
![](https://cdn-learn.adafruit.com/assets/assets/000/038/881/medium800/sensors_schem.png?1485991695)

## **Stemma QT/Black**
![](https://cdn-learn.adafruit.com/assets/assets/000/092/533/medium800/sensors_qt_schenatic.png?1593101676)

# Fabrication Print
## **Classic/Blue**
![](https://cdn-learn.adafruit.com/assets/assets/000/038/882/medium800/sensors_fabprint.png?1485991705)

## **Stemma QT/Black**
![](https://cdn-learn.adafruit.com/assets/assets/000/092/532/medium800/sensors_qt_fab.png?1593101649)


## Primary Products

### Adafruit 9-DOF LSM9DS1 Breakout Board - STEMMA QT / Qwiic

[Adafruit 9-DOF LSM9DS1 Breakout Board - STEMMA QT / Qwiic](https://www.adafruit.com/product/4634)
Add motion, direction, and orientation sensing to your project with this all-in-one 9-DOF sensor that is STEMMA QT ready for easy plug-n-play usage. Inside the chip are three sensors, one is a classic 3-axis accelerometer, which can tell you which direction is down towards the Earth (by...

Out of Stock
[Buy Now](https://www.adafruit.com/product/4634)
[Related Guides to the Product](https://learn.adafruit.com/products/4634/guides)

## Featured Products

### Adafruit 9-DOF Accel/Mag/Gyro+Temp Breakout Board - LSM9DS1

[Adafruit 9-DOF Accel/Mag/Gyro+Temp Breakout Board - LSM9DS1](https://www.adafruit.com/product/3387)
Add motion, direction and orientation sensing to your Arduino project with this all-in-one 9-DOF sensor. Inside the chip are three sensors, one is a classic 3-axis accelerometer, which can tell you which direction is down towards the Earth (by measuring gravity) or how fast the board is...

Out of Stock
[Buy Now](https://www.adafruit.com/product/3387)
[Related Guides to the Product](https://learn.adafruit.com/products/3387/guides)
### STEMMA QT / Qwiic JST SH 4-pin to Premium Male Headers Cable

[STEMMA QT / Qwiic JST SH 4-pin to Premium Male Headers Cable](https://www.adafruit.com/product/4209)
This 4-wire cable is a little over 150mm / 6" long and fitted with JST-SH female 4-pin connectors on one end and premium Dupont male headers on the other. Compared with the chunkier JST-PH these are 1mm pitch instead of 2mm, but still have a nice latching feel, while being easy to insert...

Out of Stock
[Buy Now](https://www.adafruit.com/product/4209)
[Related Guides to the Product](https://learn.adafruit.com/products/4209/guides)
### JST SH 4-pin Cable with Alligator Clips - STEMMA QT / Qwiic

[JST SH 4-pin Cable with Alligator Clips - STEMMA QT / Qwiic](https://www.adafruit.com/product/4398)
This cable will make it super easy to use our plug-and-play STEMMA QT boards with boards like Circuit Playground. On one end you get a Qwiic / STEMMA QT connector (technically known as a JST SH 4-pin plug)&nbsp; into 4 individual wires with grippy alligator clips. We're carrying these to...

Out of Stock
[Buy Now](https://www.adafruit.com/product/4398)
[Related Guides to the Product](https://learn.adafruit.com/products/4398/guides)
### 4-pin JST PH to JST SH Cable - STEMMA to QT / Qwiic

[4-pin JST PH to JST SH Cable - STEMMA to QT / Qwiic](https://www.adafruit.com/product/4424)
Are you a maker in the midst of&nbsp;a [**STEMMA**](https://learn.adafruit.com/introducing-adafruit-stemma-qt/what-is-stemma) dilemma? This 200mm long 4-wire cable is a fantastic chimera-cable fitted with **STEMMA QT / Sparkfun Qwiic JST SH** on one end,...

In Stock
[Buy Now](https://www.adafruit.com/product/4424)
[Related Guides to the Product](https://learn.adafruit.com/products/4424/guides)
### STEMMA QT / Qwiic JST SH 4-pin Cable with Premium Female Sockets

[STEMMA QT / Qwiic JST SH 4-pin Cable with Premium Female Sockets](https://www.adafruit.com/product/4397)
This 4-wire cable is a little over 150mm / 6" long and fitted with JST-SH female 4-pin connectors on one end and premium female headers on the other. Compared with the chunkier JST-PH these are 1mm pitch instead of 2mm, but still have a nice latching feel, while being easy to insert and...

Out of Stock
[Buy Now](https://www.adafruit.com/product/4397)
[Related Guides to the Product](https://learn.adafruit.com/products/4397/guides)
### STEMMA QT / Qwiic JST SH 4-pin Cable - 100mm Long

[STEMMA QT / Qwiic JST SH 4-pin Cable - 100mm Long](https://www.adafruit.com/product/4210)
This 4-wire cable is a little over 100mm / 4" long and fitted with JST-SH female 4-pin connectors on both ends. Compared with the chunkier JST-PH these are 1mm pitch instead of 2mm, but still have a nice latching feel, while being easy to insert and remove.

<a...></a...>

Out of Stock
[Buy Now](https://www.adafruit.com/product/4210)
[Related Guides to the Product](https://learn.adafruit.com/products/4210/guides)

## Related Guides

- [Glitter Positioning System](https://learn.adafruit.com/glitter-positioning-system.md)
- [Comparing Gyroscope Datasheets](https://learn.adafruit.com/comparing-gyroscope-datasheets.md)
- [How to Fuse Motion Sensor Data into AHRS Orientation (Euler/Quaternions)](https://learn.adafruit.com/how-to-fuse-motion-sensor-data-into-ahrs-orientation-euler-quaternions.md)
- [I2C Addresses and Troublesome Chips](https://learn.adafruit.com/i2c-addresses.md)
- [Adafruit SensorLab - Magnetometer Calibration](https://learn.adafruit.com/adafruit-sensorlab-magnetometer-calibration.md)
- [Adafruit SensorLab - Gyroscope Calibration](https://learn.adafruit.com/adafruit-sensorlab-gyroscope-calibration.md)
- [Adafruit DPS310 Precision Barometric Pressure and Altitude Sensor](https://learn.adafruit.com/adafruit-dps310-precision-barometric-pressure-sensor.md)
- [Adafruit NeoSlider](https://learn.adafruit.com/adafruit-neoslider.md)
- [Adafruit Music Maker FeatherWing](https://learn.adafruit.com/adafruit-music-maker-featherwing.md)
- [Adafruit pIRkey](https://learn.adafruit.com/adafruit-pirkey-python-programmable-infrared-usb-adapter.md)
- [NES Emulator for Arcada](https://learn.adafruit.com/nes-emulator-for-arcada.md)
- [Integrating Home Assistant with Adafruit IO](https://learn.adafruit.com/integrating-adafruit-io-with-home-assistant.md)
- [Adafruit TMP119 High-Precision Temperature Sensor](https://learn.adafruit.com/adafruit-tmp119-high-precision-temperature-sensor.md)
- [Adafruit 15x7 CharliePlex FeatherWing](https://learn.adafruit.com/adafruit-15x7-7x15-charlieplex-led-matrix-charliewing-featherwing.md)
- [Adafruit Terminal PiCowbell for Pico](https://learn.adafruit.com/adafruit-terminal-picowbell-for-pico.md)
