Skip to content

Commit ea2f129

Browse files
committed
Merge branch 'master' of github.com:liske/python-apds9960
2 parents b297399 + 7468cb7 commit ea2f129

10 files changed

Lines changed: 106 additions & 8 deletions

File tree

README.md

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
# Python APDS-9960 Library
1+
# Python (and MicroPython) APDS-9960 Library
22

33
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_.
44

@@ -17,7 +17,6 @@ Features:
1717
Documentation:
1818
- [RPi](RPi.md) - connect and configure the APDS-9960 on Raspberry Pi
1919
- Example scripts:
20-
- [test-ambient.py](test-ambient.py) - simple ambient light level demo
21-
- [test-gesture.py](test-gesture.py) - simple gesture detection demo
22-
- [test-prox.py](test-prox.py) - simple proximity level demo
23-
20+
- simple ambient light level demo: [rpi](rpi/test_ambient.py), [micropython](micropython/test_ambient.py)
21+
- simple gesture detection demo: [rpi](rpi/test_gesture.py), [micropython](micropython/test_gesture.py)
22+
- simple proximity level demo: [rpi](rpi/test_prox.py), [micropython](micropython/test_prox.py)

apds9960/__init__.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
from apds9960.device import APDS9960
1+
from apds9960.device import APDS9960, uAPDS9960
22

3-
__all__ = [ 'APDS9960' ]
3+
__all__ = [ 'APDS9960', 'uAPDS9960', ]

apds9960/const.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
APDS9960_GESTURE_SENSITIVITY_2 = 20
88

99
# APDS9960 device IDs
10-
APDS9960_DEV_ID = [0xab, 0x9c]
10+
APDS9960_DEV_ID = [0xab, 0x9c, 0xa8]
1111

1212
# APDS9960 times
1313
APDS9960_TIME_FIFO_PAUSE = 0.03

apds9960/device.py

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1083,3 +1083,21 @@ def _read_i2c_block_data(self, cmd, num):
10831083
# *******************************************************************************
10841084

10851085
# resets all the parameters in the gesture data member
1086+
1087+
1088+
1089+
class uAPDS9960(APDS9960):
1090+
"""
1091+
APDS9960 for MicroPython
1092+
1093+
sensor = uAPDS9960(bus=I2C_instance,
1094+
address=APDS9960_I2C_ADDR, valid_id=APDS9960_DEV_ID)
1095+
"""
1096+
def _read_byte_data(self, cmd):
1097+
return self.bus.readfrom_mem(self.address, cmd, 1)[0]
1098+
1099+
def _write_byte_data(self, cmd, val):
1100+
self.bus.writeto_mem(self.address, cmd, bytes([val]))
1101+
1102+
def _read_i2c_block_data(self, cmd, num):
1103+
return self.bus.readfrom_mem(self.address, cmd, num)

micropython/test_ambient.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
from time import sleep
2+
3+
from machine import Pin, I2C
4+
5+
from apds9960.const import *
6+
from apds9960 import uAPDS9960 as APDS9960
7+
8+
bus = I2C(sda=Pin(13), scl=Pin(14))
9+
10+
apds = APDS9960(bus)
11+
12+
print("Light Sensor Test")
13+
print("=================")
14+
apds.enableLightSensor()
15+
16+
oval = -1
17+
while True:
18+
sleep(0.25)
19+
val = apds.readAmbientLight()
20+
if val != oval:
21+
print("AmbientLight={}".format(val))
22+
oval = val
23+

micropython/test_gesture.py

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,33 @@
1+
from time import sleep
2+
3+
from machine import Pin, I2C
4+
5+
from apds9960.const import *
6+
from apds9960 import uAPDS9960 as APDS9960
7+
8+
bus = I2C(sda=Pin(13), scl=Pin(14))
9+
10+
apds = APDS9960(bus)
11+
12+
dirs = {
13+
APDS9960_DIR_NONE: "none",
14+
APDS9960_DIR_LEFT: "left",
15+
APDS9960_DIR_RIGHT: "right",
16+
APDS9960_DIR_UP: "up",
17+
APDS9960_DIR_DOWN: "down",
18+
APDS9960_DIR_NEAR: "near",
19+
APDS9960_DIR_FAR: "far",
20+
}
21+
22+
apds.setProximityIntLowThreshold(50)
23+
24+
print("Gesture Test")
25+
print("============")
26+
apds.enableGestureSensor()
27+
28+
while True:
29+
sleep(0.5)
30+
if apds.isGestureAvailable():
31+
motion = apds.readGesture()
32+
print("Gesture={}".format(dirs.get(motion, "unknown")))
33+

micropython/test_prox.py

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
from time import sleep
2+
3+
from machine import Pin, I2C
4+
5+
from apds9960.const import *
6+
from apds9960 import uAPDS9960 as APDS9960
7+
8+
bus = I2C(sda=Pin(13), scl=Pin(14))
9+
10+
apds = APDS9960(bus)
11+
12+
apds.setProximityIntLowThreshold(50)
13+
14+
print("Proximity Sensor Test")
15+
print("=====================")
16+
apds.enableProximitySensor()
17+
18+
oval = -1
19+
while True:
20+
sleep(0.25)
21+
val = apds.readProximity()
22+
if val != oval:
23+
print("proximity={}".format(val))
24+
oval = val
25+
File renamed without changes.
File renamed without changes.
File renamed without changes.

0 commit comments

Comments
 (0)