# Motion Crouton

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

<figure><img src="/files/my7Xowc7A5ksaRlDckLT" alt=""><figcaption></figcaption></figure>
{% endtab %}

{% tab title="Back" %}

<figure><img src="/files/5BhRkJUzuqiCCeml3vWa" 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)

```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://learn.breadstick.ca/breadstick/breadsticks/support-boards/i2c-devices/motion-crouton.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
