đŸĢ¨Motion Crouton

LSM6DS 6-Axis IMU (3-Axis Accelerometer + 3-Axis Gyroscope)

Product Page

https://shop.breadstick.ca/products/motion-crouton

Circuit Python Library

https://github.com/adafruit/Adafruit_CircuitPython_LSM6DS

LSM6DS Datasheet

https://www.st.com/content/ccc/resource/technical/document/datasheet/76/27/cf/88/c5/03/42/6b/DM00218116.pdf/files/DM00218116.pdf/jcr:content/translations/en.DM00218116.pdf

Code

"""
Motion Crouton (LSM6DS) Demo Code
Breadstick Innovations
April 16, 2024
https://learn.breadstick.ca/breadstick/breadsticks/support-boards/i2c-devices/motion-crouton
"""

import board
import time
import busio
from adafruit_lsm6ds.lsm6ds3trc import LSM6DS3TRC as LSM6DS
from adafruit_lsm6ds import Rate, AccelRange, GyroRange

crouton_i2c = board.I2C()  # Default Breadstick I2C pins D11(SCL) & D12(SDA)


# Setup I2C Accelerometer and Gyroscope
IMU = LSM6DS(crouton_i2c)
IMU.accelerometer_range = AccelRange.RANGE_4G
print("Accelerometer range set to: %d G" % AccelRange.string[IMU.accelerometer_range])
IMU.gyro_range = GyroRange.RANGE_1000_DPS
print("Gyro range set to: %d DPS" % GyroRange.string[IMU.gyro_range])
IMU.accelerometer_data_rate = Rate.RATE_1_66K_HZ
print("Accelerometer rate set to: %d HZ" % Rate.string[IMU.accelerometer_data_rate])
IMU.gyro_data_rate = Rate.RATE_1_66K_HZ
print("Gyro rate set to: %d HZ" % Rate.string[IMU.gyro_data_rate])


while True:
    
    acc_x, acc_y,acc_z = IMU.acceleration
    gyro_x,gyro_y,gyro_z = IMU.gyro


    plotter_data = (acc_x, acc_y, acc_z, gyro_x, gyro_y, gyro_z)  # Mu's Plotter only displays tuples, this is a single object tuple
    print(plotter_data)
    
    print(f'Accelerations:\tX[{acc_x}]\tY[{acc_y}]\tZ[{acc_z}]')
    print(f'Rotations:\tX[{gyro_x}]\tY[{gyro_y}]\tZ[{gyro_z}]')
    print("")

    time.sleep(0.1)

Last updated