diff --git a/README.rst b/README.rst index c503664..9ec0c5b 100644 --- a/README.rst +++ b/README.rst @@ -56,14 +56,13 @@ To install in a virtual environment in your current project: Usage Example ============= -.. code-block:: python +.. code-block:: python3 import board - import busio import digitalio from adafruit_apds9960.apds9960 import APDS9960 - i2c = busio.I2C(board.SCL, board.SDA) + i2c = board.I2C() int_pin = digitalio.DigitalInOut(board.D5) apds = APDS9960(i2c, interrupt_pin=int_pin) @@ -85,22 +84,21 @@ Basics Of course, you must import i2c bus device, board pins, and the library: -.. code:: python +.. code:: python3 - from board import SCL, SDA, A1 + import board from adafruit_apds9960.apds9960 import APDS9960 - import busio import digitalio To set-up the device to gather data, initialize the I2CDevice using SCL and SDA pins. Then initialize the library. Optionally provide an interrupt pin for proximity detection. -.. code:: python +.. code:: python3 - int_pin = digitalio.DigitalInOut(A1) - i2c = busio.I2C(SCL, SDA) + int_pin = digitalio.DigitalInOut(board.A1) + i2c = board.I2C() apds = APDS9960(i2c, interrupt_pin=int_pin) Gestures @@ -108,7 +106,7 @@ Gestures To get a gesture, see if a gesture is available first, then get the gesture Code -.. code:: python +.. code:: python3 gesture = apds.gesture() if gesture == 1: @@ -126,7 +124,7 @@ Color Measurement To get a color measure, enable color measures, wait for color data, then get the color data. -.. code:: python +.. code:: python3 apds.enable_color = True @@ -141,7 +139,7 @@ Proximity Detection To check for a object in proximity, see if a gesture is available first, then get the gesture Code -.. code:: python +.. code:: python3 apds.enable_proximity = True diff --git a/adafruit_apds9960/apds9960.py b/adafruit_apds9960/apds9960.py index 4935548..42105a7 100644 --- a/adafruit_apds9960/apds9960.py +++ b/adafruit_apds9960/apds9960.py @@ -10,6 +10,21 @@ detection. * Author(s): Michael McWethy + +Implementation Notes +-------------------- + +**Hardware:** + +* Adafruit `APDS9960 Proximity, Light, RGB, and Gesture Sensor + `_ (Product ID: 3595) + +**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 import digitalio @@ -81,6 +96,38 @@ class APDS9960: """ APDS9900 provide basic driver services for the ASDS9960 breakout board + + :param ~busio.I2C i2c: The I2C bus the BME280 is connected to + :param ~microcontroller.Pin interrupt_pin: Interrupt pin. Defaults to `None` + :param int address: The I2C device address. Defaults to :const:`0x39` + :param int integration_time: integration time. Defaults to :const:`0x01` + :param int gain: Device gain. Defaults to :const:`0x01` + :param int rotation: rotation of the device. Defaults to :const:`0` + + + **Quickstart: Importing and using the APDS9960** + + Here is an example of using the :class:`APDS9960` class. + First you will need to import the libraries to use the sensor + + .. code-block:: python + + import board + from adafruit_apds9960.apds9960 import APDS9960 + + 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 + apds = APDS9960(i2c) + + Now you have access to the :attr:`sensor.proximity` attribute + + .. code-block:: python + + proximity = apds.proximity + """ _gesture_enable = RWBit(APDS9960_ENABLE, 6) diff --git a/docs/examples.rst b/docs/examples.rst index 51b323c..e3285ce 100644 --- a/docs/examples.rst +++ b/docs/examples.rst @@ -7,10 +7,32 @@ Ensure your device works with this simple test. :caption: examples/apds9960_color_simpletest.py :linenos: + +Gesture Example +--------------- + +Show how to use the device with simple gestures + .. literalinclude:: ../examples/apds9960_gesture_simpletest.py :caption: examples/apds9960_gesture_simpletest.py :linenos: + +Proximity Example +----------------- + +Example showing proximity feature + .. literalinclude:: ../examples/apds9960_proximity_simpletest.py :caption: examples/apds9960_proximity_simpletest.py :linenos: + + +Color Example +--------------- + +Example showing how to get RGB values + +.. literalinclude:: ../examples/apds9960_color_simpletest.py + :caption: examples/apds9960_color_simpletest.py + :linenos: diff --git a/docs/index.rst b/docs/index.rst index c76db4a..dfb0b4b 100644 --- a/docs/index.rst +++ b/docs/index.rst @@ -23,6 +23,8 @@ Table of Contents .. toctree:: :caption: Tutorials + Adafruit APDS9960 Proximity, Light, RGB, and Gesture Sensor Learning Guide + .. toctree:: :caption: Related Products diff --git a/examples/apds9960_color_simpletest.py b/examples/apds9960_color_simpletest.py index 9b8c224..1ecad2d 100644 --- a/examples/apds9960_color_simpletest.py +++ b/examples/apds9960_color_simpletest.py @@ -3,11 +3,10 @@ import time import board -import busio from adafruit_apds9960.apds9960 import APDS9960 from adafruit_apds9960 import colorutility -i2c = busio.I2C(board.SCL, board.SDA) +i2c = board.I2C() apds = APDS9960(i2c) apds.enable_color = True diff --git a/examples/apds9960_gesture_simpletest.py b/examples/apds9960_gesture_simpletest.py index b0c8c57..912d725 100644 --- a/examples/apds9960_gesture_simpletest.py +++ b/examples/apds9960_gesture_simpletest.py @@ -1,11 +1,10 @@ # SPDX-FileCopyrightText: 2021 ladyada for Adafruit Industries # SPDX-License-Identifier: MIT -from board import SCL, SDA -import busio +import board from adafruit_apds9960.apds9960 import APDS9960 -i2c = busio.I2C(SCL, SDA) +i2c = board.I2C() apds = APDS9960(i2c) apds.enable_proximity = True diff --git a/examples/apds9960_proximity_simpletest.py b/examples/apds9960_proximity_simpletest.py index c5ca3e8..bf55d7c 100644 --- a/examples/apds9960_proximity_simpletest.py +++ b/examples/apds9960_proximity_simpletest.py @@ -2,11 +2,10 @@ # SPDX-License-Identifier: MIT import board -import busio import digitalio from adafruit_apds9960.apds9960 import APDS9960 -i2c = busio.I2C(board.SCL, board.SDA) +i2c = board.I2C() int_pin = digitalio.DigitalInOut(board.D5) apds = APDS9960(i2c, interrupt_pin=int_pin) diff --git a/examples/apds9960_simpletest.py b/examples/apds9960_simpletest.py index 933a983..cbec714 100644 --- a/examples/apds9960_simpletest.py +++ b/examples/apds9960_simpletest.py @@ -3,10 +3,9 @@ import time import board -import busio from adafruit_apds9960.apds9960 import APDS9960 -i2c = busio.I2C(board.SCL, board.SDA) +i2c = board.I2C() apds = APDS9960(i2c) apds.enable_proximity = True