Adafruit LSM9DS1 Accelerometer + Gyro + Magnetometer 9-DOF Breakout Created by lady ada Last updated on 2018-12-07 09:03:21 PM UTC
Guide Contents Guide Contents Overview Pinouts 2 3 5 Power Pins I2C Pins SPI Pins Interrupt & Misc Pins 5 5 5 5 Assembly 7 Prepare the header strip: Add the breakout board: And Solder! 7 8 9 Arduino Code Wiring for Arduino Download Adafruit_LSM9DS1 Download Adafruit_Sensor Load Demo Sketch Library Reference Begin! Set Ranges Read data Python & CircuitPython CircuitPython Microcontroller Wiring Python Computer Wiring CircuitPython Installation of LSM9DS1 Library CircuitPython & Python Usage Full Exam
Overview 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.
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.
Pinouts 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.
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.
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 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 © Adafruit Industries https://learn.adafruit.
Add the breakout board: Place the breakout board over the pins so that the short pins poke through the breakout pads © Adafruit Industries https://learn.adafruit.
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 (https://adafru.it/aTk)). © Adafruit Industries https://learn.adafruit.
If you plan to use the interrupts and/or you want the board to sit flatter in a breadboard, solder up the other strip! You're done! Check your solder joints visually and continue onto the next steps © Adafruit Industries https://learn.adafruit.
Arduino Code Wiring for Arduino You can easily wire this breakout to any microcontroller, we'll be using an Arduino. 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 # of wires: Connect Vin to the power supply, 3-5V is fine. Use the same voltage that the microcontroller logic is based off of.
Adafruit_LSM9DS1.cpp and Adafruit_LSM9DS1.h Place the Adafruit_LSM9DS1 library folder your arduinosketchfolder/libraries/ folder. You may need to create the libraries subfolder if its your first library. Restart the IDE. We also have a great tutorial on Arduino library installation at: http://learn.adafruit.com/adafruit-all-about-arduino-libraries-install-use (https://adafru.
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.
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 ...
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.
Python & CircuitPython It's easy to use the LSM9DS1 sensor with Python or CircuitPython, and the Adafruit CircuitPython LSM9DS1 (https://adafru.it/C5b) module. This module allows you to easily write Python code that reads the accelerometer, magnetometer, and gyroscope 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://adafru.it/BSN).
Pi 3V3 to sensor VIN Pi GND to sensor GND Pi SCL to sensor SCL Pi SDA to sensor SDA Here's the Raspberry Pi wired with SPI: Pi 3V3 to sensor VIN Pi GND to sensor GND Pi SCLK to sensor SCL Pi MOSI to sensor SDA Pi MISO to sensor SDOAG AND sensor SDOM Pi GPIO5 to sensor CSAG Pi GPIO6 to sensor CSM CircuitPython Installation of LSM9DS1 Library You'll need to install the Adafruit CircuitPython LSM9DS1 (https://adafru.it/C5b) library on your CircuitPython board.
Run the following code to import the necessary modules and initialize the I2C connection with the sensor: import board import busio import adafruit_lsm9ds1 i2c = busio.I2C(board.SCL, board.SDA) sensor = adafruit_lsm9ds1.LSM9DS1_I2C(i2c) If you're connected using SPI, run the following code to initialise the SPI connection with the sensor: import board import busio from digitalio import DigitalInOut, Direction spi = busio.SPI(board.SCK, board.MOSI, board.MISO) csag = DigitalInOut(board.D5) csag.
sensor.accel_range = adafruit_lsm9ds1.ACCELRANGE_4G sensor.mag_gain = adafruit_lsm9ds1.MAGGAIN_8GAUSS sensor.gyro_scale = adafruit_lsm9ds1.GYROSCALE_500DPS See the simpletest.py example (https://adafru.it/C5d) for a complete demo of printing the accelerometer, magnetometer, gyroscope every second. Save this as code.py on the board and examine the REPL output to see the range printed every second.
# Simple demo of the LSM9DS1 accelerometer, magnetometer, gyroscope. # Will print the acceleration, magnetometer, and gyroscope values every second. import time import board import busio import adafruit_lsm9ds1 # I2C connection: i2c = busio.I2C(board.SCL, board.SDA) sensor = adafruit_lsm9ds1.LSM9DS1_I2C(i2c) #SPI connection: # from digitalio import DigitalInOut, Direction # spi = busio.SPI(board.SCK, board.MOSI, board.MISO) # csag = DigitalInOut(board.D5) # csag.direction = Direction.OUTPUT # csag.
Python Docs Python Docs (https://adafru.it/C5e) © Adafruit Industries https://learn.adafruit.
Downloads Files EagleCAD PCB files on GitHub (https://adafru.it/ub2) Fritzing object available in Adafruit Fritzing library (https://adafru.it/aP3) https://adafru.it/ub3 https://adafru.it/ub3 Schematic and Fabrication Print © Adafruit Industries https://learn.adafruit.
© Adafruit Industries Last Updated: 2018-12-07 09:03:21 PM UTC Page 23 of 23