Simple test

Ensure your device works with this simple test.

examples/fxas21002c_simpletest.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4# Simple demo of the FXAS21002C gyroscope.
 5# Will print the gyroscope values every second.
 6import time
 7import board
 8import adafruit_fxas21002c
 9
10
11# Create sensor object, communicating over the board's default I2C bus
12i2c = board.I2C()  # uses board.SCL and board.SDA
13# i2c = board.STEMMA_I2C()  # For using the built-in STEMMA QT connector on a microcontroller
14sensor = adafruit_fxas21002c.FXAS21002C(i2c)
15# Optionally create the sensor with a different gyroscope range (the
16# default is 250 DPS, but you can use 500, 1000, or 2000 DPS values):
17# sensor = adafruit_fxas21002c.FXAS21002C(i2c, gyro_range=adafruit_fxas21002c.GYRO_RANGE_500DPS)
18# sensor = adafruit_fxas21002c.FXAS21002C(i2c, gyro_range=adafruit_fxas21002c.GYRO_RANGE_1000DPS)
19# sensor = adafruit_fxas21002c.FXAS21002C(i2c, gyro_range=adafruit_fxas21002c.GYRO_RANGE_2000DPS)
20
21# Main loop will read the gyroscope values every second and print them out.
22while True:
23    # Read gyroscope.
24    gyro_x, gyro_y, gyro_z = sensor.gyroscope
25    # Print values.
26    print(
27        "Gyroscope (radians/s): ({0:0.3f},  {1:0.3f},  {2:0.3f})".format(
28            gyro_x, gyro_y, gyro_z
29        )
30    )
31    # Delay for a second.
32    time.sleep(1.0)