Skip to content

9-Axis LSM9DS1 Sensor Wireling Tutorial

TinyCircuits 9-Axis Sensor Wireling product photo

If you are looking to do a project with an inertial motion sensor, look no further than this 9-Axis sensor! The LSM9DS1 features 3 acceleration channels, 3 angular rate channels, and 3 magnetic field channels. This array of channels allows users to create very sophisticated motion applications. 9-Axis sensors are popular in virtual reality experiences for their excellent tracking of motion. This tutorial will teach you the basics on how to read values from this sensor.

The LSM9DS1 has a linear acceleration full scale of ±2g/±4g/±8/±16 g, a magnetic field full scale of ±4/±8/±12/±16 gauss and an angular rate of ±245/±500/±2000 dps.

Technical Details ST LSM9DS1 9-Axis DOF Specs
  • 3 acceleration channels, 3 angular rate channels, 3 magnetic field channels
  • ±2/±4/±8/±16 g linear acceleration full scale
  • ±4/±8/±12/±16 gauss magnetic full scale
  • ±245/±500/±2000 dps angular rate full scale
  • 16-bit data output
  • “Always-on” eco power mode down to 1.9 mA
  • Embedded temperature sensor
  • Embedded FIFO
  • Position and motion detection functions
  • Click/double-click recognition
Power Requirements
  • Voltage: 3.0V - 5.5V 
  • Current: 4.6mA (Normal Mode).  Due to the low current, this board can be run using the TinyDuino coin cell option
Pins Used
  • A5/SCL - I²C Serial Clock line
  • A4/SDA - I²C Serial Data line
Dimensions
  • 10mm x 10mm (.394 inches x .394 inches)
  • Max Height (from lower bottom of Wireling to upper top Wireling Connector): 3.70mm (0.15 inches)
  • Weight: 1 gram (.04 ounces)

Materials

Hardware

Required Software


Hardware Assembly

Plug your Wireling into the port you plan on using! The default in the included program is port 0.

If you want to use a different port, you just need to change the port value in the program mentioned later.


Programming

The necessary Python module needs an address change to be compatible with the TinyCircuits 9-Axis Wireling. After downloading it above under Software, you can take note of these two modifications:

_LSM9DS1_ADDRESS_ACCELGYRO       = const(0x6A) # Changed from 0x6B
_LSM9DS1_ADDRESS_MAG             = const(0x1C) # Changed from 0x1E

Then you will just need to include the LSM9DS1 module in the same directory as the example program:

lsm9ds1_example.py
# Simple demo of the LSM9DS1 accelerometer, magnetometer, gyroscope.
# Will print the acceleration, magnetometer, and gyroscope values every second.
# Modified for TinyCircuits compatibility by: Laverena Wienclaw 
import time
import board
import busio
import adafruit_lsm9ds1
import tinycircuits_wireling

# Enable power to pi hat and wirelings
wireling = tinycircuits_wireling.Wireling()
wireling.selectPort(0) # Select port (0-3) labeled on the Pi Hat

# 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.value = True
# csm = DigitalInOut(board.D6)
# csm.direction = Direction.OUTPUT
# csm.value = True
# sensor = adafruit_lsm9ds1.LSM9DS1_SPI(spi, csag, csm)

# Main loop will read the acceleration, magnetometer, gyroscope, Temperature
# values every second and print them out.
while True:
    # Read acceleration, magnetometer, gyroscope, temperature.
    accel_x, accel_y, accel_z = sensor.acceleration
    mag_x, mag_y, mag_z = sensor.magnetic
    gyro_x, gyro_y, gyro_z = sensor.gyro
    temp = sensor.temperature
    # Print values.
    print('Acceleration (m/s^2): ({0:0.3f},{1:0.3f},{2:0.3f})'.format(accel_x, accel_y, accel_z))
    print('Magnetometer (gauss): ({0:0.3f},{1:0.3f},{2:0.3f})'.format(mag_x, mag_y, mag_z))
    print('Gyroscope (degrees/sec): ({0:0.3f},{1:0.3f},{2:0.3f})'.format(gyro_x, gyro_y, gyro_z))
    print('Temperature: {0:0.3f}C'.format(temp))
    # Delay for a second.
    time.sleep(1.0)

Run Program

Navigate in the terminal to the directory with the file parent to the examples folder.

python3 lsm9ds1_example.py

Once the program is running, you should see the sensor values print out:

Acceleration (m/s^2): (3.641,8.867,2.547)
Magnetometer (gauss): (0.317,-0.113,-0.300)
Gyroscope (degrees/sec): (11.086,9.844,3.028)
Temperature: 21.500C

Contact Us

If you have any questions or feedback, feel free to email us at info@tinycircuits.com or make a post on the forum.

Show us what you make by tagging @TinyCircuits on Instagram, Twitter, or Facebook so we can feature it!

Thanks for making with us!


Downloads