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
13sensor = adafruit_fxas21002c.FXAS21002C(i2c)
14# Optionally create the sensor with a different gyroscope range (the
15# default is 250 DPS, but you can use 500, 1000, or 2000 DPS values):
16# sensor = adafruit_fxas21002c.FXAS21002C(i2c, gyro_range=adafruit_fxas21002c.GYRO_RANGE_500DPS)
17# sensor = adafruit_fxas21002c.FXAS21002C(i2c, gyro_range=adafruit_fxas21002c.GYRO_RANGE_1000DPS)
18# sensor = adafruit_fxas21002c.FXAS21002C(i2c, gyro_range=adafruit_fxas21002c.GYRO_RANGE_2000DPS)
19
20# Main loop will read the gyroscope values every second and print them out.
21while True:
22    # Read gyroscope.
23    gyro_x, gyro_y, gyro_z = sensor.gyroscope
24    # Print values.
25    print(
26        "Gyroscope (radians/s): ({0:0.3f},  {1:0.3f},  {2:0.3f})".format(
27            gyro_x, gyro_y, gyro_z
28        )
29    )
30    # Delay for a second.
31    time.sleep(1.0)