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
13# i2c = board.STEMMA_I2C()  # For using the built-in STEMMA QT connector on a microcontroller
14sensor = adafruit_fxos8700.FXOS8700(i2c)
15# Optionally create the sensor with a different accelerometer range (the
16# default is 2G, but you can use 4G or 8G values):
17# sensor = adafruit_fxos8700.FXOS8700(i2c, accel_range=adafruit_fxos8700.ACCEL_RANGE_4G)
18# sensor = adafruit_fxos8700.FXOS8700(i2c, accel_range=adafruit_fxos8700.ACCEL_RANGE_8G)
19
20# Main loop will read the acceleration and magnetometer values every second
21# and print them out.
22while True:
23    # Read acceleration & magnetometer.
24    accel_x, accel_y, accel_z = sensor.accelerometer
25    mag_x, mag_y, mag_z = sensor.magnetometer
26    # Print values.
27    print(
28        "Acceleration (m/s^2): ({0:0.3f}, {1:0.3f}, {2:0.3f})".format(
29            accel_x, accel_y, accel_z
30        )
31    )
32    print(
33        "Magnetometer (uTesla): ({0:0.3f}, {1:0.3f}, {2:0.3f})".format(
34            mag_x, mag_y, mag_z
35        )
36    )
37    # Delay for a second.
38    time.sleep(1.0)