Skip to content

improving_docs #23

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Apr 26, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -54,14 +54,13 @@ To install in a virtual environment in your current project:
Usage Example
=============

.. code-block:: python
.. code-block:: python3

import time
import board
import busio
import adafruit_fxos8700

i2c = busio.I2C(board.SCL, board.SDA)
i2c = board.I2C()
sensor = adafruit_fxos8700.FXOS8700(i2c)

while True:
Expand Down
41 changes: 36 additions & 5 deletions adafruit_fxos8700.py
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@

**Software and Dependencies:**

* Adafruit CircuitPython firmware (2.2.0+) for the ESP8622 and M0-based boards:
https://github.com/adafruit/circuitpython/releases
* Adafruit CircuitPython firmware for the supported boards:
https://circuitpython.org/downloads

* Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice
"""
Expand Down Expand Up @@ -87,7 +87,38 @@ def _twos_comp(val, bits):


class FXOS8700:
"""Driver for the NXP FXOS8700 accelerometer and magnetometer."""
"""Driver for the NXP FXOS8700 accelerometer and magnetometer.

:param ~busio.I2C i2c: The I2C bus the device is connected to
:param int address: The I2C device address. Defaults to :const:`0x1F`
:param int accel_range: Device range. Defaults to :const:`0x00`.


**Quickstart: Importing and using the device**

Here is an example of using the :class:`FXOS8700` class.
First you will need to import the libraries to use the sensor

.. code-block:: python

import board
import adafruit_fxos8700

Once this is done you can define your `board.I2C` object and define your sensor object

.. code-block:: python

i2c = board.I2C() # uses board.SCL and board.SDA
sensor = adafruit_fxos8700.FXOS8700(i2c)

Now you have access to the :attr:`accelerometer` and :attr:`magnetometer` attributes

.. code-block:: python

accel_x, accel_y, accel_z = sensor.accelerometer
mag_x, mag_y, mag_z = sensor.magnetometer

"""

# Class-level buffer for reading and writing data with the sensor.
# This reduces memory allocations but means the code is not re-entrant or
Expand Down Expand Up @@ -171,7 +202,7 @@ def read_raw_accel_mag(self):
@property
def accelerometer(self):
"""Read the acceleration from the accelerometer and return its X, Y, Z axis values as a
3-tuple in m/s^2.
3-tuple in :math:`m/s^2`.
"""
accel_raw, _ = self.read_raw_accel_mag()
# Convert accel values to m/s^2
Expand All @@ -187,7 +218,7 @@ def accelerometer(self):
@property
def magnetometer(self):
"""
Read the magnetometer values and return its X, Y, Z axis values as a 3-tuple in uTeslas.
Read the magnetometer values and return its X, Y, Z axis values as a 3-tuple in μTeslas.
"""
_, mag_raw = self.read_raw_accel_mag()
# Convert mag values to uTesla
Expand Down
2 changes: 2 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,8 @@ Table of Contents
.. toctree::
:caption: Tutorials

Adafruit Precision NXP 9-DOF Breakout Board - FXOS8700 + FXAS21002 Learning Guide <https://learn.adafruit.com/nxp-precision-9dof-breakout/overview>

.. toctree::
:caption: Related Products

Expand Down
7 changes: 2 additions & 5 deletions examples/fxos8700_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,12 @@
# Simple demo of the FXOS8700 accelerometer and magnetometer.
# Will print the acceleration and magnetometer values every second.
import time

import board
import busio

import adafruit_fxos8700


# Initialize I2C bus and device.
i2c = busio.I2C(board.SCL, board.SDA)
# Create sensor object, communicating over the board's default I2C bus
i2c = board.I2C()
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):
Expand Down