Skip to content

improving_docs #15

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 2 commits 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 @@ -62,14 +62,13 @@ To install in a virtual environment in your current project:
Usage Example
=============

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

from time import sleep
import board
import busio
from adafruit_as7341 import AS7341

i2c = busio.I2C(board.SCL, board.SDA)
i2c = board.I2C() # uses board.SCL and board.SDA
sensor = AS7341(i2c)


Expand Down
38 changes: 34 additions & 4 deletions adafruit_as7341.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,39 @@ class Gain(CV):
class AS7341: # pylint:disable=too-many-instance-attributes
"""Library for the AS7341 Sensor

:param ~busio.I2C i2c_bus: The I2C bus the device is connected to
:param int address: The I2C device address. Defaults to :const:`0x39`

:param ~busio.I2C i2c_bus: The I2C bus the AS7341 is connected to.
:param address: The I2C address of the sensor

**Quickstart: Importing and using the device**

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

.. code-block:: python

import board
from adafruit_as7341 import AS7341

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 = AS7341(i2c)

Now you have access to the different channels

.. code-block:: python

channel_415nm = channel_415nm
channel_445nm = channel_445nm
channel_480nm = channel_480nm
channel_515nm = channel_515nm
channel_555nm = channel_555nm
channel_590nm = channel_590nm
channel_630nm = channel_630nm
channel_680nm = channel_680nm

"""

Expand Down Expand Up @@ -331,7 +361,7 @@ def _wait_for_data(self, timeout=1.0):
start = monotonic()
while not self._data_ready_bit:
if monotonic() - start > timeout:
raise RuntimeError("Timeout occoured waiting for sensor data")
raise RuntimeError("Timeout occurred waiting for sensor data")
sleep(0.001)

def _write_register(self, addr, data):
Expand Down Expand Up @@ -579,7 +609,7 @@ def _set_smux(self, smux_addr, smux_out1, smux_out2):

@property
def gain(self):
"""The ADC gain multiplier. Must be a valid `adafruit_as7341.Gain`"""
"""The ADC gain multiplier. Must be a valid :meth:`adafruit_as7341.Gain`"""
return self._gain

@gain.setter
Expand Down
1 change: 1 addition & 0 deletions docs/api.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@

.. automodule:: adafruit_as7341
:members:
:exclude-members: CV, Gain
27 changes: 27 additions & 0 deletions docs/examples.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,30 @@ Ensure your device works with this simple test.
.. literalinclude:: ../examples/as7341_simpletest.py
:caption: examples/as7341_simpletest.py
:linenos:

LED test
--------

Testing the LED

.. literalinclude:: ../examples/as7341_led_test.py
:caption: examples/as7341_led_test.py
:linenos:

Flicker Detection
-----------------

Showing how to use flicker detection

.. literalinclude:: ../examples/as7341_flicker_detection.py
:caption: examples/as7341_flicker_detection.py
:linenos:

Batched Readings Example
------------------------

Example in how to get all the channel readings at the same time

.. literalinclude:: ../examples/as7341_batched_readings.py
:caption: examples/as7341_batched_readings.py
:linenos:
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 AS7341 10-Channel Light / Color Sensor Breakout Learning Guide <https://learn.adafruit.com/adafruit-as7341-10-channel-light-color-sensor-breakout/overview>

.. toctree::
:caption: Related Products

Adafruit AS7341 10-Channel Light / Color Sensor Breakout <https://www.adafruit.com/product/4698>

.. toctree::
:caption: Other Links

Expand Down
3 changes: 1 addition & 2 deletions examples/as7341_batched_readings.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
# SPDX-License-Identifier: MIT
from time import sleep
import board
import busio
from adafruit_as7341 import AS7341

i2c = busio.I2C(board.SCL, board.SDA)
i2c = board.I2C() # uses board.SCL and board.SDA
sensor = AS7341(i2c)


Expand Down
3 changes: 1 addition & 2 deletions examples/as7341_flicker_detection.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
# SPDX-License-Identifier: MIT
from time import sleep
import board
import busio
from adafruit_as7341 import AS7341

i2c = busio.I2C(board.SCL, board.SDA)
i2c = board.I2C() # uses board.SCL and board.SDA
sensor = AS7341(i2c)
sensor.flicker_detection_enabled = True

Expand Down
1 change: 1 addition & 0 deletions examples/as7341_led_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

i2c = board.I2C()
sensor = adafruit_as7341.AS7341(i2c)

print("out of init!")
print("Current current is")
print(sensor.led_current)
Expand Down
3 changes: 1 addition & 2 deletions examples/as7341_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,9 @@
# SPDX-License-Identifier: MIT
from time import sleep
import board
import busio
from adafruit_as7341 import AS7341

i2c = busio.I2C(board.SCL, board.SDA)
i2c = board.I2C() # uses board.SCL and board.SDA
sensor = AS7341(i2c)


Expand Down