diff --git a/README.rst b/README.rst index b82c420..f4a898f 100644 --- a/README.rst +++ b/README.rst @@ -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: diff --git a/adafruit_fxos8700.py b/adafruit_fxos8700.py index b663e67..9f4a269 100644 --- a/adafruit_fxos8700.py +++ b/adafruit_fxos8700.py @@ -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 """ @@ -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 @@ -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 @@ -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 diff --git a/docs/index.rst b/docs/index.rst index 73492a0..ff6886a 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -23,6 +23,8 @@ Table of Contents .. toctree:: :caption: Tutorials + Adafruit Precision NXP 9-DOF Breakout Board - FXOS8700 + FXAS21002 Learning Guide + .. toctree:: :caption: Related Products diff --git a/examples/fxos8700_simpletest.py b/examples/fxos8700_simpletest.py index 7f904f0..25ee1f9 100644 --- a/examples/fxos8700_simpletest.py +++ b/examples/fxos8700_simpletest.py @@ -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):