Skip to content

improving_docs #16

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
87 changes: 84 additions & 3 deletions adafruit_as726x.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,22 @@
Driver for the AS726x spectral sensors

* Author(s): Dean Miller

Implementation Notes
--------------------

**Hardware:**

* Adafruit `AS7262 6-Channel Visible Light / Color Sensor Breakout
<https://www.adafruit.com/product/3779>`_ (Product ID: 3779)

**Software and Dependencies:**

* Adafruit CircuitPython firmware for the supported boards:
https://circuitpython.org/downloads

* Adafruit's Bus Device library: https://github.com/adafruit/Adafruit_CircuitPython_BusDevice

"""

import time
Expand Down Expand Up @@ -281,8 +297,10 @@ def integration_time(self, val):
def start_measurement(self):
"""Begin a measurement.

This will set the device to One Shot mode and values will not change after `data_ready`
until `start_measurement` is called again or the `conversion_mode` is changed."""
This will set the device to One Shot mode and values will
not change after `data_ready` until :meth:`start_measurement`
is called again or the :meth:`conversion_mode` is changed.
"""
state = self._virtual_read(_AS726X_CONTROL_SETUP)
state &= ~(0x02)
self._virtual_write(_AS726X_CONTROL_SETUP, state)
Expand Down Expand Up @@ -382,7 +400,39 @@ def _virtual_write(self, addr, value):
class AS726x_I2C(AS726x):
"""AS726x spectral sensor via I2C.

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


**Quickstart: Importing and using the AS726x**

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

.. code-block:: python

import board
from adafruit_as726x import AS726x_I2C

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

Now you have access to the different color attributes

.. code-block:: python

violet = sensor.violet
blue = sensor.blue
green = sensor.green
yellow = sensor.yellow
orange = sensor.orange
red = sensor.red


"""

def __init__(self, i2c_bus, address=_AS726X_ADDRESS):
Expand Down Expand Up @@ -449,6 +499,37 @@ class AS726x_UART(AS726x):
"""AS726x spectral sensor via UART.

:param ~busio.UART uart: The UART connected to the sensor


**Quickstart: Importing and using the AS726x**

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

.. code-block:: python

import board
from adafruit_as726x import AS726x_UART

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

.. code-block:: python

uart = board.UART() # uses board.SCL and board.SDA
sensor = AS726x_UART(uart)

Now you have access to the different color attributes

.. code-block:: python

violet = sensor.violet
blue = sensor.blue
green = sensor.green
yellow = sensor.yellow
orange = sensor.orange
red = sensor.red


"""

def __init__(self, uart):
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 AS7262 6-Channel Visible Light / Color Sensor Breakout Learning Guide <https://learn.adafruit.com/adafruit-as7262-6-channel-visible-light-sensor>

.. toctree::
:caption: Related Products

Adafruit AS7262 6-Channel Visible Light / Color Sensor Breakout <https://www.adafruit.com/product/3779>

.. toctree::
:caption: Other Links

Expand Down
6 changes: 2 additions & 4 deletions examples/as726x_simpletest.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,7 @@
# SPDX-License-Identifier: MIT

import time

import board
import busio

# for I2C use:
from adafruit_as726x import AS726x_I2C
Expand All @@ -24,11 +22,11 @@ def graph_map(x):


# for I2C use:
i2c = busio.I2C(board.SCL, board.SDA)
i2c = board.I2C()
sensor = AS726x_I2C(i2c)

# for UART use:
# uart = busio.UART(board.TX, board.RX)
# uart = board.UART()
# sensor = AS726x_UART(uart)

sensor.conversion_mode = sensor.MODE_2
Expand Down