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
 7
 8import board
 9
10import adafruit_fxas21002c
11
12# Create sensor object, communicating over the board's default I2C bus
13i2c = board.I2C()  # uses board.SCL and board.SDA
14# i2c = board.STEMMA_I2C()  # For using the built-in STEMMA QT connector on a microcontroller
15sensor = adafruit_fxas21002c.FXAS21002C(i2c)
16# Optionally create the sensor with a different gyroscope range (the
17# default is 250 DPS, but you can use 500, 1000, or 2000 DPS values):
18# sensor = adafruit_fxas21002c.FXAS21002C(i2c, gyro_range=adafruit_fxas21002c.GYRO_RANGE_500DPS)
19# sensor = adafruit_fxas21002c.FXAS21002C(i2c, gyro_range=adafruit_fxas21002c.GYRO_RANGE_1000DPS)
20# sensor = adafruit_fxas21002c.FXAS21002C(i2c, gyro_range=adafruit_fxas21002c.GYRO_RANGE_2000DPS)
21
22# Main loop will read the gyroscope values every second and print them out.
23while True:
24    # Read gyroscope.
25    gyro_x, gyro_y, gyro_z = sensor.gyroscope
26    # Print values.
27    print(f"Gyroscope (radians/s): ({gyro_x:0.3f},  {gyro_y:0.3f},  {gyro_z:0.3f})")
28    # Delay for a second.
29    time.sleep(1.0)