Skip to content
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

improving_docs #28

Merged
merged 1 commit into from
Apr 27, 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
6 changes: 2 additions & 4 deletions README.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
48 changes: 38 additions & 10 deletions adafruit_mlx90393.py
Original file line number Diff line number Diff line change
Expand Up @@ -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

"""

Expand Down Expand Up @@ -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__(
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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
Expand Down
4 changes: 4 additions & 0 deletions docs/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,13 @@ Table of Contents
.. toctree::
:caption: Tutorials

Adafruit Wide-Range Triple-axis Magnetometer - MLX90393 Learning Guide <https://learn.adafruit.com/mlx90393-wide-range-3-axis-magnetometer>

.. toctree::
:caption: Related Products

Adafruit Wide-Range Triple-axis Magnetometer - MLX90393 <https://www.adafruit.com/product/4022>

.. toctree::
:caption: Other Links

Expand Down
6 changes: 2 additions & 4 deletions examples/mlx90393_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down