fxas21002c_simpletest.py
1 # Simple demo of the FXAS21002C gyroscope. 2 # Will print the gyroscope values every second. 3 import time 4 5 import board 6 import busio 7 8 import adafruit_fxas21002c 9 10 11 # Initialize I2C bus and device. 12 i2c = busio.I2C(board.SCL, board.SDA) 13 sensor = 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. 21 while 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)