🍞
Breadstick
Ctrlk
  • Breadstick Innovations Website
  • Breadsticks
    • πŸ₯–Raspberry Breadstick
    • πŸ₯–Raspberry Breadstick Lite
    • 🍞Support Boards
      • I2C Devices
        • 🚌I2C Bus Rail Adapter
        • 🌦️Weather Crouton
        • 😎Brightness Crouton
        • πŸ“Distance Crouton
        • 🫨Motion Crouton
      • I2S Devices
      • SPI Devices
      • πŸ•ΉοΈButtons/Switches
    • Learning Resources
    • Troubleshooting
  • Nougat
    • Nougat C3
    • Nougat Quad
    • Installing WLED
  • Pico Slices
    • πŸ”΄Slice 1 - LED Mixer
    • ⏱️Slice 2 - Stopwatch
    • ⬜Slice 3 - 8x8 Dot Matrix
    • Circuit Python Setup
    • Reset Bricked Pico
  • Christmas
    • Christmas Tree DIY kit
  • Protoboards
    • ❀️Proto-Heart
    • πŸ₯ͺProto-Toast
  • SHOP
Powered by GitBook
On this page
  1. Breadsticks
  2. 🍞Support Boards
  3. I2C Devices

🫨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

PreviousDistance CroutonNextI2S Devices

Last updated 1 year ago

Was this helpful?

  • Product Page
  • Circuit Python Library
  • LSM6DS Datasheet
  • Code

Was this helpful?

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