Simple test
Ensure your device works with this simple test.
examples/lsm9ds0_simpletest.py
1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
2# SPDX-License-Identifier: MIT
3
4# Simple demo of the LSM9DS0 accelerometer, magnetometer, gyroscope.
5# Will print the acceleration, magnetometer, and gyroscope values every second.
6import time
7
8import board
9import busio
10
11# import digitalio # Used with SPI
12import adafruit_lsm9ds0
13
14# I2C connection:
15i2c = busio.I2C(board.SCL, board.SDA)
16sensor = adafruit_lsm9ds0.LSM9DS0_I2C(i2c)
17
18# SPI connection:
19# from digitalio import DigitalInOut, Direction
20# spi = busio.SPI(board.SCK, board.MOSI, board.MISO)
21# gcs = DigitalInOut(board.D5)
22# xmcs = DigitalInOut(board.D6)
23# sensor = adafruit_lsm9ds0.LSM9DS0_SPI(spi, xmcs, gcs)
24
25# Main loop will read the acceleration, magnetometer, gyroscope, Temperature
26# values every second and print them out.
27while True:
28 # Read acceleration, magnetometer, gyroscope, temperature.
29 accel_x, accel_y, accel_z = sensor.acceleration
30 mag_x, mag_y, mag_z = sensor.magnetic
31 gyro_x, gyro_y, gyro_z = sensor.gyro
32 temp = sensor.temperature
33 # Print values.
34 print(f"Acceleration (m/s^2): ({accel_x:0.3f},{accel_y:0.3f},{accel_z:0.3f})")
35 print(f"Magnetometer (gauss): ({mag_x:0.3f},{mag_y:0.3f},{mag_z:0.3f})")
36 print(f"Gyroscope (degrees/sec): ({gyro_x:0.3f},{gyro_y:0.3f},{gyro_z:0.3f})")
37 print(f"Temperature: {temp:0.3f}C")
38 # Delay for a second.
39 time.sleep(1.0)