Dependencies¶
This driver depends on:
Please ensure all dependencies are available on the CircuitPython filesystem. This is easily achieved by downloading the Adafruit library and driver bundle.
Installing from PyPI¶
On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally from PyPI. To install for current user:
pip3 install adafruit-circuitpython-fxos8700
To install system-wide (this may be required in some cases):
sudo pip3 install adafruit-circuitpython-fxos8700
To install in a virtual environment in your current project:
mkdir project-name && cd project-name
python3 -m venv .env
source .env/bin/activate
pip3 install adafruit-circuitpython-fxos8700
Usage Example¶
import time
import board
import adafruit_fxos8700
i2c = board.I2C() # uses board.SCL and board.SDA
sensor = adafruit_fxos8700.FXOS8700(i2c)
while True:
accel_x, accel_y, accel_z = sensor.accelerometer
mag_x, mag_y, mag_z = sensor.magnetometer
print('Acceleration (m/s^2): ({0:0.3f}, {1:0.3f}, {2:0.3f})'.format(accel_x, accel_y, accel_z))
print('Magnetometer (uTesla): ({0:0.3f}, {1:0.3f}, {2:0.3f})'.format(mag_x, mag_y, mag_z))
time.sleep(1.0)
Contributing¶
Contributions are welcome! Please read our Code of Conduct before contributing to help this project stay welcoming.
Documentation¶
For information on building library documentation, please check out this guide.
Table of Contents¶
Simple test¶
Ensure your device works with this simple test.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 | # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries
# SPDX-License-Identifier: MIT
# Simple demo of the FXOS8700 accelerometer and magnetometer.
# Will print the acceleration and magnetometer values every second.
import time
import board
import adafruit_fxos8700
# Create sensor object, communicating over the board's default I2C bus
i2c = board.I2C() # uses board.SCL and board.SDA
sensor = adafruit_fxos8700.FXOS8700(i2c)
# Optionally create the sensor with a different accelerometer range (the
# default is 2G, but you can use 4G or 8G values):
# sensor = adafruit_fxos8700.FXOS8700(i2c, accel_range=adafruit_fxos8700.ACCEL_RANGE_4G)
# sensor = adafruit_fxos8700.FXOS8700(i2c, accel_range=adafruit_fxos8700.ACCEL_RANGE_8G)
# Main loop will read the acceleration and magnetometer values every second
# and print them out.
while True:
# Read acceleration & magnetometer.
accel_x, accel_y, accel_z = sensor.accelerometer
mag_x, mag_y, mag_z = sensor.magnetometer
# Print values.
print(
"Acceleration (m/s^2): ({0:0.3f}, {1:0.3f}, {2:0.3f})".format(
accel_x, accel_y, accel_z
)
)
print(
"Magnetometer (uTesla): ({0:0.3f}, {1:0.3f}, {2:0.3f})".format(
mag_x, mag_y, mag_z
)
)
# Delay for a second.
time.sleep(1.0)
|
adafruit_fxos8700
¶
CircuitPython module for the NXP FXOS8700 accelerometer and magnetometer. Based on the driver from: https://github.com/adafruit/Adafruit_FXOS8700
See examples/simpletest.py for a demo of the usage.
- Author(s): Tony DiCola
Implementation Notes¶
Hardware:
- Adafruit Precision NXP 9-DOF Breakout Board - FXOS8700 + FXAS21002 (Product ID: 3463)
Software and Dependencies:
- Adafruit CircuitPython firmware for the supported boards: https://circuitpython.org/downloads
- Adafruit’s Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
-
class
adafruit_fxos8700.
FXOS8700
(i2c, address=31, accel_range=0)[source]¶ Driver for the NXP FXOS8700 accelerometer and magnetometer.
Parameters: Quickstart: Importing and using the device
Here is an example of using the
FXOS8700
class. First you will need to import the libraries to use the sensorimport board import adafruit_fxos8700
Once this is done you can define your
board.I2C
object and define your sensor objecti2c = board.I2C() # uses board.SCL and board.SDA sensor = adafruit_fxos8700.FXOS8700(i2c)
Now you have access to the
accelerometer
andmagnetometer
attributesaccel_x, accel_y, accel_z = sensor.accelerometer mag_x, mag_y, mag_z = sensor.magnetometer
-
accelerometer
¶ Read the acceleration from the accelerometer and return its X, Y, Z axis values as a 3-tuple in \(m/s^2\).
-
magnetometer
¶ Read the magnetometer values and return its X, Y, Z axis values as a 3-tuple in μTeslas.
-
read_raw_accel_mag
()[source]¶ Read the raw accelerometer and magnetometer readings. Returns a 2-tuple of 3-tuples:
- Accelerometer X, Y, Z axis 14-bit signed raw values
- Magnetometer X, Y, Z axis 16-bit signed raw values
If you want the acceleration or magnetometer values in friendly units consider using the accelerometer and magnetometer properties!
-