adafruit-circuitpython-apds9960


Nameadafruit-circuitpython-apds9960 JSON
Version 3.1.12 PyPI version JSON
download
home_pageNone
SummaryCircuitPython driver for APSD9960 Gesture breakout board
upload_time2024-10-07 21:37:48
maintainerNone
docs_urlNone
authorNone
requires_pythonNone
licenseMIT
keywords adafruit apsd9960 gesture color proximity light sensor hardware micropython circuitpython
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            
Introduction
============

.. image:: https://readthedocs.org/projects/adafruit-circuitpython-apds9960/badge/?version=latest
    :target: https://docs.circuitpython.org/projects/apds9960/en/latest/
    :alt: Documentation Status

.. image:: https://raw.githubusercontent.com/adafruit/Adafruit_CircuitPython_Bundle/main/badges/adafruit_discord.svg
    :target: https://adafru.it/discord
    :alt: Discord

.. image:: https://github.com/adafruit/Adafruit_CircuitPython_APDS9960/workflows/Build%20CI/badge.svg
    :target: https://github.com/adafruit/Adafruit_CircuitPython_APDS9960/actions/
    :alt: Build Status

.. image:: https://img.shields.io/badge/code%20style-black-000000.svg
    :target: https://github.com/psf/black
    :alt: Code Style: Black

The APDS-9960 is a specialized chip that detects hand gestures, proximity
and ambient light color over I2C. Its available from
`Adafruit as a breakout <https://www.adafruit.com/product/3595>`_ and as a built-in sensor on
several Adafruit development boards.

* `Adafruit CLUE <https://www.adafruit.com/product/4500>`_
* `Adafruit Feather nRF52840 Sense <https://www.adafruit.com/product/4516>`_
* `Adafruit Proximity Trinkey <https://www.adafruit.com/product/5022>`_

This driver provides easy access to proximity, gesture and color data from the APDS-9960 sensor
with a minimal footprint to allow it to work on all CircuitPython platforms.

Installation and Dependencies
=============================
This driver depends on:

* `Adafruit CircuitPython <https://github.com/adafruit/circuitpython>`_

Please ensure all dependencies are available on the CircuitPython filesystem.

This is easily achieved by downloading
`the Adafruit library and driver bundle <https://github.com/adafruit/Adafruit_CircuitPython_Bundle>`_.

Installing from PyPI
--------------------

On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally `from PyPI <https://pypi.org/project/adafruit-circuitpython-apds9960/>`_.

To install for current user:

.. code-block:: shell

    pip3 install adafruit-circuitpython-apds9960

To install system-wide (this may be required in some cases):

.. code-block:: shell

    sudo pip3 install adafruit-circuitpython-apds9960

To install in a virtual environment in your current project:

.. code-block:: shell

    mkdir project-name && cd project-name
    python3 -m venv .venv
    source .venv/bin/activate
    pip3 install adafruit-circuitpython-apds9960

Usage Example
=============

.. code-block:: python3

    import board
    import digitalio
    from adafruit_apds9960.apds9960 import APDS9960

    i2c = board.I2C()
    int_pin = digitalio.DigitalInOut(board.D5)
    int_pin.switch_to_input(pull=digitalio.Pull.UP)
    apds = APDS9960(i2c)

    apds.enable_proximity_interrupt = True
    apds.proximity_interrupt_threshold = (0, 175)
    apds.enable_proximity = True

    while True:
        if not int_pin.value:
            print(apds.proximity)
            apds.clear_interrupt()

Hardware Set-up
---------------

If you're using a board with a built-in APDS-9960, no hardware setup will be required.

If you're using a breakout board via the pin header, connect ``Vin`` to a 3.3 V or 5 V power source,
connect ``GND`` to ground, then connect ``SCL`` and ``SDA`` to the appropriate pins.

Optionally, if you'd like to use the sensor's interrupt pin connect ``INT`` to any available
digital I/O pin.

Basics
------

To get started, import ``board`` and, and this library:

.. code:: python3


    import board
    from adafruit_apds9960.apds9960 import APDS9960

To set up the sensor to gather data, initialize the I2C bus via ``board.I2C()``
then initialize the APDS-9960 library.

.. code:: python3

    i2c = board.I2C()
    apds = APDS9960(i2c)

Proximity
---------

To get a proximity result, enable the proximity engine then read the `proximity` value.

This will return a value between 0 and 255, with higher values indicating that something is close
to the sensor.

.. code:: python3

    apds.enable_proximity = True

    while True:
      print(apds.proximity)

Gestures
--------

First, enable both the proximity and gesture engines. The gesture engine relies on the proximity
engine to determine when to start itself up and, as a result, proximity readings won't be reliable
while the gesture engine is enabled.

To get a gesture, use the `gesture()` function to see if a gesture has been detected. If a value
greater than 0 is returned, a gesture has been detected.

.. code:: python3

    # Uncomment and set the rotation if depending on how your sensor is mounted.
    # apds.rotation = 270 # 270 for CLUE

    apds.enable_proximity = True
    apds.enable_gesture = True

    while True:
      gesture = apds.gesture()
      if gesture == 1:
        print("up")
      if gesture == 2:
        print("down")
      if gesture == 3:
        print("left")
      if gesture == 4:
        print("right")

Color/Light Measurement
-----------------------

To get a color measurement, first enable the color/light engine, wait for color data to arrive,
then read the `color_data` values.

.. code:: python3

    apds.enable_color = True

    while True:
        while not apds.color_data_ready:
            time.sleep(0.005)

        r, g, b, c = apds.color_data
        print("r: {}, g: {}, b: {}, c: {}".format(r, g, b, c))

Interrupt Pin
-------------

This sensor has an interrupt pin can be asserted (pulled low) if proximity is detected outside of a
specified window of values.

For boards with a built-in APDS-9960 this interupt pin will already be defined. For example, on the
Clue and Feather nRF52840 Sense boards this pin is mapped to ``board.PROXIMITY_LIGHT_INTERRUPT``
and on the Proximity Trinkey it is mapped to ``board.INTERRUPT``.

.. code:: python3

    int_pin = digitalio.DigitalInOut(board.D5)
    int_pin.switch_to_input(pull=digitalio.Pull.UP)

Proximity Detection
-------------------

With the interrupt pin set up we can define a threshold and enable the assertion of the sensor's
interrupt pin by the proximity engine before enabling the proximity engine itself.

In this configuration, the sensor's interrupt pin will be asserted when an object is close to the
sensor. After checking on the interrupt it can be cleared using `clear_interrupt()`

.. code:: python3

    apds.enable_proximity = True

    # set the interrupt threshold to fire when proximity reading goes above 175
    apds.proximity_interrupt_threshold = (0, 175)

    # assert interrupt pin on internal proximity interrupt
    apds.enable_proximity_interrupt = True

    # enable the sensor's proximity engine
    apds.enable_proximity = True

    while True:
      if not interrupt_pin.value:
        print(apds.proximity)

        # clear the interrupt
        apds.clear_interrupt()

Initiaization Options
----------------------

By default, when the driver is initialized, the APDS-9960 sensor's internal settings are reset and
sensible defaults are applied to several low-level settings that should work well for most use cases.

If either the "reset" or "set defaults" behaviors (or both) aren't desired, they can be individually
disabled via init kwargs.

.. code:: python3

    apds = APDS9960(i2c, reset=False, set_defaults=False)

Documentation
=============

API documentation for this library can be found on `Read the Docs <https://docs.circuitpython.org/projects/apds9960/en/latest/>`_.

For information on building library documentation, please check out `this guide <https://learn.adafruit.com/creating-and-sharing-a-circuitpython-library/sharing-our-docs-on-readthedocs#sphinx-5-1>`_.

Contributing
============

Contributions are welcome! Please read our `Code of Conduct
<https://github.com/adafruit/Adafruit_CircuitPython_APDS9960/blob/main/CODE_OF_CONDUCT.md>`_
before contributing to help this project stay welcoming.

Building locally
================

To build this library locally you'll need to install the
`circuitpython-travis-build-tools <https://github.com/adafruit/circuitpython-build-tools>`_ package.

.. code-block::shell

    python3 -m venv .venv
    source .venv/bin/activate
    pip install -r requirements.txt

Once installed, make sure you are in the virtual environment:

.. code-block::shell

    source .venv/bin/activate

Then run the build:

.. code-block::shell

    circuitpython-build-bundles --filename_prefix adafruit-circuitpython-apds --library_location .

Sphinx documentation
-----------------------

Sphinx is used to build the documentation based on rST files and comments in the code. First,
install dependencies (feel free to reuse the virtual environment from above):

.. code-block:: shell

    python3 -m venv .venv
    source .venv/bin/activate
    pip install Sphinx sphinx-rtd-theme

Now, once you have the virtual environment activated:

.. code-block:: shell

    cd docs
    sphinx-build -E -W -b html . _build/html

This will output the documentation to ``docs/_build/html``. Open the index.html in your browser to
view them. It will also (due to -W) error out on any warning like Travis will. This is a good way to
locally verify it will pass.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "adafruit-circuitpython-apds9960",
    "maintainer": null,
    "docs_url": null,
    "requires_python": null,
    "maintainer_email": null,
    "keywords": "adafruit, apsd9960, gesture, color, proximity, light, sensor, hardware, micropython, circuitpython",
    "author": null,
    "author_email": "Adafruit Industries <circuitpython@adafruit.com>",
    "download_url": "https://files.pythonhosted.org/packages/05/36/69219af42fe6a8c6e69b71a198ea92eefefc0bb338c58d34a1fa9123d4df/adafruit_circuitpython_apds9960-3.1.12.tar.gz",
    "platform": null,
    "description": "\nIntroduction\n============\n\n.. image:: https://readthedocs.org/projects/adafruit-circuitpython-apds9960/badge/?version=latest\n    :target: https://docs.circuitpython.org/projects/apds9960/en/latest/\n    :alt: Documentation Status\n\n.. image:: https://raw.githubusercontent.com/adafruit/Adafruit_CircuitPython_Bundle/main/badges/adafruit_discord.svg\n    :target: https://adafru.it/discord\n    :alt: Discord\n\n.. image:: https://github.com/adafruit/Adafruit_CircuitPython_APDS9960/workflows/Build%20CI/badge.svg\n    :target: https://github.com/adafruit/Adafruit_CircuitPython_APDS9960/actions/\n    :alt: Build Status\n\n.. image:: https://img.shields.io/badge/code%20style-black-000000.svg\n    :target: https://github.com/psf/black\n    :alt: Code Style: Black\n\nThe APDS-9960 is a specialized chip that detects hand gestures, proximity\nand ambient light color over I2C. Its available from\n`Adafruit as a breakout <https://www.adafruit.com/product/3595>`_ and as a built-in sensor on\nseveral Adafruit development boards.\n\n* `Adafruit CLUE <https://www.adafruit.com/product/4500>`_\n* `Adafruit Feather nRF52840 Sense <https://www.adafruit.com/product/4516>`_\n* `Adafruit Proximity Trinkey <https://www.adafruit.com/product/5022>`_\n\nThis driver provides easy access to proximity, gesture and color data from the APDS-9960 sensor\nwith a minimal footprint to allow it to work on all CircuitPython platforms.\n\nInstallation and Dependencies\n=============================\nThis driver depends on:\n\n* `Adafruit CircuitPython <https://github.com/adafruit/circuitpython>`_\n\nPlease ensure all dependencies are available on the CircuitPython filesystem.\n\nThis is easily achieved by downloading\n`the Adafruit library and driver bundle <https://github.com/adafruit/Adafruit_CircuitPython_Bundle>`_.\n\nInstalling from PyPI\n--------------------\n\nOn supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally `from PyPI <https://pypi.org/project/adafruit-circuitpython-apds9960/>`_.\n\nTo install for current user:\n\n.. code-block:: shell\n\n    pip3 install adafruit-circuitpython-apds9960\n\nTo install system-wide (this may be required in some cases):\n\n.. code-block:: shell\n\n    sudo pip3 install adafruit-circuitpython-apds9960\n\nTo install in a virtual environment in your current project:\n\n.. code-block:: shell\n\n    mkdir project-name && cd project-name\n    python3 -m venv .venv\n    source .venv/bin/activate\n    pip3 install adafruit-circuitpython-apds9960\n\nUsage Example\n=============\n\n.. code-block:: python3\n\n    import board\n    import digitalio\n    from adafruit_apds9960.apds9960 import APDS9960\n\n    i2c = board.I2C()\n    int_pin = digitalio.DigitalInOut(board.D5)\n    int_pin.switch_to_input(pull=digitalio.Pull.UP)\n    apds = APDS9960(i2c)\n\n    apds.enable_proximity_interrupt = True\n    apds.proximity_interrupt_threshold = (0, 175)\n    apds.enable_proximity = True\n\n    while True:\n        if not int_pin.value:\n            print(apds.proximity)\n            apds.clear_interrupt()\n\nHardware Set-up\n---------------\n\nIf you're using a board with a built-in APDS-9960, no hardware setup will be required.\n\nIf you're using a breakout board via the pin header, connect ``Vin`` to a 3.3 V or 5 V power source,\nconnect ``GND`` to ground, then connect ``SCL`` and ``SDA`` to the appropriate pins.\n\nOptionally, if you'd like to use the sensor's interrupt pin connect ``INT`` to any available\ndigital I/O pin.\n\nBasics\n------\n\nTo get started, import ``board`` and, and this library:\n\n.. code:: python3\n\n\n    import board\n    from adafruit_apds9960.apds9960 import APDS9960\n\nTo set up the sensor to gather data, initialize the I2C bus via ``board.I2C()``\nthen initialize the APDS-9960 library.\n\n.. code:: python3\n\n    i2c = board.I2C()\n    apds = APDS9960(i2c)\n\nProximity\n---------\n\nTo get a proximity result, enable the proximity engine then read the `proximity` value.\n\nThis will return a value between 0 and 255, with higher values indicating that something is close\nto the sensor.\n\n.. code:: python3\n\n    apds.enable_proximity = True\n\n    while True:\n      print(apds.proximity)\n\nGestures\n--------\n\nFirst, enable both the proximity and gesture engines. The gesture engine relies on the proximity\nengine to determine when to start itself up and, as a result, proximity readings won't be reliable\nwhile the gesture engine is enabled.\n\nTo get a gesture, use the `gesture()` function to see if a gesture has been detected. If a value\ngreater than 0 is returned, a gesture has been detected.\n\n.. code:: python3\n\n    # Uncomment and set the rotation if depending on how your sensor is mounted.\n    # apds.rotation = 270 # 270 for CLUE\n\n    apds.enable_proximity = True\n    apds.enable_gesture = True\n\n    while True:\n      gesture = apds.gesture()\n      if gesture == 1:\n        print(\"up\")\n      if gesture == 2:\n        print(\"down\")\n      if gesture == 3:\n        print(\"left\")\n      if gesture == 4:\n        print(\"right\")\n\nColor/Light Measurement\n-----------------------\n\nTo get a color measurement, first enable the color/light engine, wait for color data to arrive,\nthen read the `color_data` values.\n\n.. code:: python3\n\n    apds.enable_color = True\n\n    while True:\n        while not apds.color_data_ready:\n            time.sleep(0.005)\n\n        r, g, b, c = apds.color_data\n        print(\"r: {}, g: {}, b: {}, c: {}\".format(r, g, b, c))\n\nInterrupt Pin\n-------------\n\nThis sensor has an interrupt pin can be asserted (pulled low) if proximity is detected outside of a\nspecified window of values.\n\nFor boards with a built-in APDS-9960 this interupt pin will already be defined. For example, on the\nClue and Feather nRF52840 Sense boards this pin is mapped to ``board.PROXIMITY_LIGHT_INTERRUPT``\nand on the Proximity Trinkey it is mapped to ``board.INTERRUPT``.\n\n.. code:: python3\n\n    int_pin = digitalio.DigitalInOut(board.D5)\n    int_pin.switch_to_input(pull=digitalio.Pull.UP)\n\nProximity Detection\n-------------------\n\nWith the interrupt pin set up we can define a threshold and enable the assertion of the sensor's\ninterrupt pin by the proximity engine before enabling the proximity engine itself.\n\nIn this configuration, the sensor's interrupt pin will be asserted when an object is close to the\nsensor. After checking on the interrupt it can be cleared using `clear_interrupt()`\n\n.. code:: python3\n\n    apds.enable_proximity = True\n\n    # set the interrupt threshold to fire when proximity reading goes above 175\n    apds.proximity_interrupt_threshold = (0, 175)\n\n    # assert interrupt pin on internal proximity interrupt\n    apds.enable_proximity_interrupt = True\n\n    # enable the sensor's proximity engine\n    apds.enable_proximity = True\n\n    while True:\n      if not interrupt_pin.value:\n        print(apds.proximity)\n\n        # clear the interrupt\n        apds.clear_interrupt()\n\nInitiaization Options\n----------------------\n\nBy default, when the driver is initialized, the APDS-9960 sensor's internal settings are reset and\nsensible defaults are applied to several low-level settings that should work well for most use cases.\n\nIf either the \"reset\" or \"set defaults\" behaviors (or both) aren't desired, they can be individually\ndisabled via init kwargs.\n\n.. code:: python3\n\n    apds = APDS9960(i2c, reset=False, set_defaults=False)\n\nDocumentation\n=============\n\nAPI documentation for this library can be found on `Read the Docs <https://docs.circuitpython.org/projects/apds9960/en/latest/>`_.\n\nFor information on building library documentation, please check out `this guide <https://learn.adafruit.com/creating-and-sharing-a-circuitpython-library/sharing-our-docs-on-readthedocs#sphinx-5-1>`_.\n\nContributing\n============\n\nContributions are welcome! Please read our `Code of Conduct\n<https://github.com/adafruit/Adafruit_CircuitPython_APDS9960/blob/main/CODE_OF_CONDUCT.md>`_\nbefore contributing to help this project stay welcoming.\n\nBuilding locally\n================\n\nTo build this library locally you'll need to install the\n`circuitpython-travis-build-tools <https://github.com/adafruit/circuitpython-build-tools>`_ package.\n\n.. code-block::shell\n\n    python3 -m venv .venv\n    source .venv/bin/activate\n    pip install -r requirements.txt\n\nOnce installed, make sure you are in the virtual environment:\n\n.. code-block::shell\n\n    source .venv/bin/activate\n\nThen run the build:\n\n.. code-block::shell\n\n    circuitpython-build-bundles --filename_prefix adafruit-circuitpython-apds --library_location .\n\nSphinx documentation\n-----------------------\n\nSphinx is used to build the documentation based on rST files and comments in the code. First,\ninstall dependencies (feel free to reuse the virtual environment from above):\n\n.. code-block:: shell\n\n    python3 -m venv .venv\n    source .venv/bin/activate\n    pip install Sphinx sphinx-rtd-theme\n\nNow, once you have the virtual environment activated:\n\n.. code-block:: shell\n\n    cd docs\n    sphinx-build -E -W -b html . _build/html\n\nThis will output the documentation to ``docs/_build/html``. Open the index.html in your browser to\nview them. It will also (due to -W) error out on any warning like Travis will. This is a good way to\nlocally verify it will pass.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "CircuitPython driver for APSD9960 Gesture breakout board",
    "version": "3.1.12",
    "project_urls": {
        "Homepage": "https://github.com/adafruit/Adafruit_CircuitPython_APDS9960"
    },
    "split_keywords": [
        "adafruit",
        " apsd9960",
        " gesture",
        " color",
        " proximity",
        " light",
        " sensor",
        " hardware",
        " micropython",
        " circuitpython"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "f723a920542fa7cbde1a8308a9a6efe88b735d8160f804da8da2b13b42478acb",
                "md5": "5399a05807d09d47b2d4752bd6d95af6",
                "sha256": "48a90919668a5b3e175092b5654abb43dada1f6614f39052fbe6fe9052dd0781"
            },
            "downloads": -1,
            "filename": "adafruit_circuitpython_apds9960-3.1.12-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "5399a05807d09d47b2d4752bd6d95af6",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": null,
            "size": 16243,
            "upload_time": "2024-10-07T21:37:46",
            "upload_time_iso_8601": "2024-10-07T21:37:46.640827Z",
            "url": "https://files.pythonhosted.org/packages/f7/23/a920542fa7cbde1a8308a9a6efe88b735d8160f804da8da2b13b42478acb/adafruit_circuitpython_apds9960-3.1.12-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "053669219af42fe6a8c6e69b71a198ea92eefefc0bb338c58d34a1fa9123d4df",
                "md5": "59313efdd13cd159d8e5a86ab6bf5637",
                "sha256": "e5cf629ded252616b3ebb3afa6155e8cfe35d87d2c959fce11b7217827f13a47"
            },
            "downloads": -1,
            "filename": "adafruit_circuitpython_apds9960-3.1.12.tar.gz",
            "has_sig": false,
            "md5_digest": "59313efdd13cd159d8e5a86ab6bf5637",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 40169,
            "upload_time": "2024-10-07T21:37:48",
            "upload_time_iso_8601": "2024-10-07T21:37:48.335738Z",
            "url": "https://files.pythonhosted.org/packages/05/36/69219af42fe6a8c6e69b71a198ea92eefefc0bb338c58d34a1fa9123d4df/adafruit_circuitpython_apds9960-3.1.12.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-10-07 21:37:48",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "adafruit",
    "github_project": "Adafruit_CircuitPython_APDS9960",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "requirements": [],
    "lcname": "adafruit-circuitpython-apds9960"
}
        
Elapsed time: 0.30740s