Code Monkey home page Code Monkey logo

adafruit_circuitpython_apds9960's Introduction

Introduction

Discord

The APDS9960 is a specialize chip that detects hand gestures, proximity detection and ambient light color over I2C. Its available on Adafruit as a breakout.

Dependencies

This driver depends on:

Please ensure all dependencies are available on the CircuitPython filesystem. This is easily achieved by downloading the Adafruit library and driver bundle.

Usage Example

Hardware Set-up

Connect Vin to 3.3 V or 5 V power source, GND to ground, SCL and SDA to the appropriate pins.

Basics

Of course, you must import i2c bus device, board pins, and the library:

from board import SCL, SDA, A1
import adafruit_apds9960 as apds9960
import busio

To set-up the device to gather data, initialize the I2CDevice using SCL and SDA pins. Then initialize the libary. Optionally provide an interrupt pin for proximity detection.

int_pin = digitalio.DigitalInOutput(A1)
i2c = busio.I2C(SCL, SDA)
apds = apds9960.APDS9960(i2c, interrupt_pin=int_pin)

Gestures

To get a gesture, see if a gesture is available first, then get the gesture Code

gesture = apds.gesture()
if gesture == apds.UP:
  print("up")
if gesture == apds.DOWN:
  print("down")
if gesture == apds.RIGHT:
  print("right")
if gesture == apds.LEFT:
  print("left")

Color Measurement

To get a color measure, enable color measures, wait for color data, then get the color data.

apds.enable_color = 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))

Proximity Detection

To check for a object in proximity, see if a gesture is available first, then get the gesture Code

apds.enable_proximity = True

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

# enable the proximity interrupt
apds.enable_proximity_interrupt = True

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

  # clear the interrupt
  apds.clear_interrupt()

API Reference

.. toctree::
   :maxdepth: 2

   api

Contributing

Contributions are welcome! Please read our Code of Conduct 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 package.

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

Then run the build:

adafruit_circuitpython_apds9960's People

Contributors

mrmcwethy avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.