Simple test

Ensure your device works with this simple test.

examples/fxos8700_simpletest.py
 1# SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
 2# SPDX-License-Identifier: MIT
 3
 4# Simple demo of the FXOS8700 accelerometer and magnetometer.
 5# Will print the acceleration and magnetometer values every second.
 6import time
 7import board
 8import adafruit_fxos8700
 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_fxos8700.FXOS8700(i2c)
14# Optionally create the sensor with a different accelerometer range (the
15# default is 2G, but you can use 4G or 8G values):
16# sensor = adafruit_fxos8700.FXOS8700(i2c, accel_range=adafruit_fxos8700.ACCEL_RANGE_4G)
17# sensor = adafruit_fxos8700.FXOS8700(i2c, accel_range=adafruit_fxos8700.ACCEL_RANGE_8G)
18
19# Main loop will read the acceleration and magnetometer values every second
20# and print them out.
21while True:
22    # Read acceleration & magnetometer.
23    accel_x, accel_y, accel_z = sensor.accelerometer
24    mag_x, mag_y, mag_z = sensor.magnetometer
25    # Print values.
26    print(
27        "Acceleration (m/s^2): ({0:0.3f}, {1:0.3f}, {2:0.3f})".format(
28            accel_x, accel_y, accel_z
29        )
30    )
31    print(
32        "Magnetometer (uTesla): ({0:0.3f}, {1:0.3f}, {2:0.3f})".format(
33            mag_x, mag_y, mag_z
34        )
35    )
36    # Delay for a second.
37    time.sleep(1.0)