Skip to content
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
9 changes: 4 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Python APDS-9960 Library
# Python (and MicroPython) APDS-9960 Library

Python library for the APDS-9960 gesture sensor developed while I was looking to get the APDS-9960 to work with a _Raspberry Pi_ to build a user interface feeling like in _Minority Report_.

Expand All @@ -17,7 +17,6 @@ Features:
Documentation:
- [RPi](RPi.md) - connect and configure the APDS-9960 on Raspberry Pi
- Example scripts:
- [test-ambient.py](test-ambient.py) - simple ambient light level demo
- [test-gesture.py](test-gesture.py) - simple gesture detection demo
- [test-prox.py](test-prox.py) - simple proximity level demo

- simple ambient light level demo: [rpi](rpi/test_ambient.py), [micropython](micropython/test_ambient.py)
- simple gesture detection demo: [rpi](rpi/test_gesture.py), [micropython](micropython/test_gesture.py)
- simple proximity level demo: [rpi](rpi/test_prox.py), [micropython](micropython/test_prox.py)
4 changes: 2 additions & 2 deletions apds9960/__init__.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
from apds9960.device import APDS9960
from apds9960.device import APDS9960, uAPDS9960

__all__ = [ 'APDS9960' ]
__all__ = [ 'APDS9960', 'uAPDS9960', ]
18 changes: 18 additions & 0 deletions apds9960/device.py
Original file line number Diff line number Diff line change
Expand Up @@ -1083,3 +1083,21 @@ def _read_i2c_block_data(self, cmd, num):
# *******************************************************************************

# resets all the parameters in the gesture data member



class uAPDS9960(APDS9960):
"""
APDS9960 for MicroPython

sensor = uAPDS9960(bus=I2C_instance,
address=APDS9960_I2C_ADDR, valid_id=APDS9960_DEV_ID)
"""
def _read_byte_data(self, cmd):
return self.bus.readfrom_mem(self.address, cmd, 1)[0]

def _write_byte_data(self, cmd, val):
self.bus.writeto_mem(self.address, cmd, bytes([val]))
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

btw, I noticed that your write method returns something. what is that?

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It depends on the bus implementation but I hardly can remember. It might be completely useless ;-)


def _read_i2c_block_data(self, cmd, num):
return self.bus.readfrom_mem(self.address, cmd, num)
23 changes: 23 additions & 0 deletions micropython/test_ambient.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
from time import sleep

from machine import Pin, I2C

from apds9960.const import *
from apds9960 import uAPDS9960 as APDS9960

bus = I2C(sda=Pin(13), scl=Pin(14))

apds = APDS9960(bus)

print("Light Sensor Test")
print("=================")
apds.enableLightSensor()

oval = -1
while True:
sleep(0.25)
val = apds.readAmbientLight()
if val != oval:
print("AmbientLight={}".format(val))
oval = val

33 changes: 33 additions & 0 deletions micropython/test_gesture.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
from time import sleep

from machine import Pin, I2C

from apds9960.const import *
from apds9960 import uAPDS9960 as APDS9960

bus = I2C(sda=Pin(13), scl=Pin(14))

apds = APDS9960(bus)

dirs = {
APDS9960_DIR_NONE: "none",
APDS9960_DIR_LEFT: "left",
APDS9960_DIR_RIGHT: "right",
APDS9960_DIR_UP: "up",
APDS9960_DIR_DOWN: "down",
APDS9960_DIR_NEAR: "near",
APDS9960_DIR_FAR: "far",
}

apds.setProximityIntLowThreshold(50)

print("Gesture Test")
print("============")
apds.enableGestureSensor()

while True:
sleep(0.5)
if apds.isGestureAvailable():
motion = apds.readGesture()
print("Gesture={}".format(dirs.get(motion, "unknown")))

25 changes: 25 additions & 0 deletions micropython/test_prox.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
from time import sleep

from machine import Pin, I2C

from apds9960.const import *
from apds9960 import uAPDS9960 as APDS9960

bus = I2C(sda=Pin(13), scl=Pin(14))

apds = APDS9960(bus)

apds.setProximityIntLowThreshold(50)

print("Proximity Sensor Test")
print("=====================")
apds.enableProximitySensor()

oval = -1
while True:
sleep(0.25)
val = apds.readProximity()
if val != oval:
print("proximity={}".format(val))
oval = val

File renamed without changes.
File renamed without changes.
File renamed without changes.