diff --git a/README.rst b/README.rst index b1c907f..a43eb87 100644 --- a/README.rst +++ b/README.rst @@ -57,13 +57,11 @@ Usage Example .. code-block:: python3 import time - import busio import board - import adafruit_mlx90393 - I2C_BUS = busio.I2C(board.SCL, board.SDA) - SENSOR = adafruit_mlx90393.MLX90393(I2C_BUS, gain=adafruit_mlx90393.GAIN_1X) + i2c = board.I2C() # uses board.SCL and board.SDA + SENSOR = adafruit_mlx90393.MLX90393(i2c, gain=adafruit_mlx90393.GAIN_1X) while True: MX, MY, MZ = SENSOR.magnetic diff --git a/adafruit_mlx90393.py b/adafruit_mlx90393.py index 2740280..5cca071 100755 --- a/adafruit_mlx90393.py +++ b/adafruit_mlx90393.py @@ -21,10 +21,11 @@ **Software and Dependencies:** * Adafruit CircuitPython firmware for the supported boards: - https://github.com/adafruit/circuitpython/releases - + https://circuitpython.org/downloads * Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice +* Adafruit's Register library: + https://github.com/adafruit/Adafruit_CircuitPython_Register """ @@ -162,11 +163,36 @@ class MLX90393: # pylint: disable=too-many-instance-attributes """ Driver for the MLX90393 magnetometer. - :param i2c_bus: The `busio.I2C` object to use. This is the only - required parameter. - :param int address: (optional) The I2C address of the device. - :param int gain: (optional) The gain level to apply. - :param bool debug: (optional) Enable debug output. + + :param i2c_bus: The I2C bus the device is connected to + :param int address: The I2C device address. Defaults to :const:`0x0C` + :param int gain: The gain level to apply. Defaults to :const:`GAIN_1X` + :param bool debug: Enable debug output. Defaults to `False` + + + **Quickstart: Importing and using the device** + + Here is an example of using the :class:`MLX90393` class. + First you will need to import the libraries to use the sensor + + .. code-block:: python + + import board + import adafruit_mlx90393 + + 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_mlx90393.MLX90393(i2c) + + Now you have access to the :attr:`magnetic` attribute + + .. code-block:: python + + MX, MY, MZ = SENSOR.magnetic + """ def __init__( @@ -208,8 +234,10 @@ def _transceive(self, payload, rxlen=0): """ Writes the specified 'payload' to the sensor Returns the results of the write attempt. - :param bytearray payload: The byte array to write to the sensor - :param rxlen: (optional) The numbers of bytes to read back (default=0) + + :param bytes payload: The byte array to write to the sensor + :param int rxlen: numbers of bytes to read back. Defaults to :const:`0` + """ # Read the response (+1 to account for the mandatory status byte!) data = bytearray(rxlen + 1) @@ -351,7 +379,7 @@ def oversampling(self, level): def display_status(self): """ - Prints out the content of the last status byte in a human-readble + Prints out the content of the last status byte in a human-readable format. """ avail = 0 diff --git a/docs/index.rst b/docs/index.rst index 7341ccf..f44c90d 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -23,9 +23,13 @@ Table of Contents .. toctree:: :caption: Tutorials + Adafruit Wide-Range Triple-axis Magnetometer - MLX90393 Learning Guide + .. toctree:: :caption: Related Products + Adafruit Wide-Range Triple-axis Magnetometer - MLX90393 + .. toctree:: :caption: Other Links diff --git a/examples/mlx90393_simpletest.py b/examples/mlx90393_simpletest.py index c4a2b0e..47650a6 100755 --- a/examples/mlx90393_simpletest.py +++ b/examples/mlx90393_simpletest.py @@ -2,13 +2,11 @@ # SPDX-License-Identifier: MIT import time -import busio import board - import adafruit_mlx90393 -I2C_BUS = busio.I2C(board.SCL, board.SDA) -SENSOR = adafruit_mlx90393.MLX90393(I2C_BUS, gain=adafruit_mlx90393.GAIN_1X) +i2c = board.I2C() # uses board.SCL and board.SDA +SENSOR = adafruit_mlx90393.MLX90393(i2c, gain=adafruit_mlx90393.GAIN_1X) while True: MX, MY, MZ = SENSOR.magnetic