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
 7
 8import board
 9
10import adafruit_fxos8700
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_fxos8700.FXOS8700(i2c)
16# Optionally create the sensor with a different accelerometer range (the
17# default is 2G, but you can use 4G or 8G values):
18# sensor = adafruit_fxos8700.FXOS8700(i2c, accel_range=adafruit_fxos8700.ACCEL_RANGE_4G)
19# sensor = adafruit_fxos8700.FXOS8700(i2c, accel_range=adafruit_fxos8700.ACCEL_RANGE_8G)
20
21# Main loop will read the acceleration and magnetometer values every second
22# and print them out.
23while True:
24    # Read acceleration & magnetometer.
25    accel_x, accel_y, accel_z = sensor.accelerometer
26    mag_x, mag_y, mag_z = sensor.magnetometer
27    # Print values.
28    print(f"Acceleration (m/s^2): ({accel_x:0.3f}, {accel_y:0.3f}, {accel_z:0.3f})")
29    print(f"Magnetometer (uTesla): ({mag_x:0.3f}, {mag_y:0.3f}, {mag_z:0.3f})")
30    # Delay for a second.
31    time.sleep(1.0)