# Motion Crouton

{% tabs %}
{% tab title="Front" %}

<figure><img src="https://2808519483-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FI2jtNl20mw4WYRE8MWgw%2Fuploads%2FnwvEpLCcRtQn1SJQUy80%2F24-04-20%2009-24-44%20oroo.jpg?alt=media&#x26;token=9dce3680-eaa8-486f-8998-91b1f31c21e1" alt=""><figcaption></figcaption></figure>
{% endtab %}

{% tab title="Back" %}

<figure><img src="https://2808519483-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FI2jtNl20mw4WYRE8MWgw%2Fuploads%2FEUXl5jfGeTLSESD7TDaY%2F24-04-20%2009-25-07%20oroo.jpg?alt=media&#x26;token=9a4dc00e-b769-4d67-80fe-a549cd7bfd9e" alt=""><figcaption></figcaption></figure>
{% endtab %}
{% endtabs %}

## 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

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

```
