Skip to content

Commit 23c7f82

Browse files
docs: Expand README for apds9960 driver. (#222)
* docs: Expand README for apds9960 driver. * docs: Rewrite apds9960 README addressing all review comments. --------- Co-authored-by: Sébastien NEDJAR <sebastien@nedjar.com>
1 parent fff0977 commit 23c7f82

1 file changed

Lines changed: 161 additions & 5 deletions

File tree

lib/apds9960/README.md

Lines changed: 161 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,165 @@
1-
# MicroPython APDS-9960 Library
1+
# APDS-9960 MicroPython Driver
22

3-
This library is a port of the [Python (and MicroPython) APDS-9960 Library](https://github.com/liske/python-apds9960/).
3+
MicroPython driver for the **Broadcom APDS-9960** proximity, gesture, color, and ambient light sensor.
44

5-
The examples could be easily tested with [mpremote](https://docs.micropython.org/en/latest/reference/mpremote.html) with the following command :
5+
This library is a port of [python-apds9960](https://github.com/liske/python-apds9960/).
66

7-
```sh
8-
mpremote mount . run examples/ambient_light.py
7+
## Supported Sensor
8+
9+
| Parameter | Value |
10+
| ------------------- | --------------------------------- |
11+
| Device | APDS-9960 |
12+
| Interface | I²C |
13+
| Default I²C address | `0x39` |
14+
| Device ID | `0xAB` |
15+
| Functions | ALS, RGB, proximity, gesture |
16+
| Proximity range | 0–255 (relative) |
17+
| ALS resolution | 16-bit per channel |
18+
19+
## Features
20+
21+
* Ambient light sensing (ALS) — clear channel
22+
* RGB color sensing — red, green, blue channels
23+
* Proximity detection — object distance estimation
24+
* Gesture detection — directional gestures (up, down, left, right, near, far)
25+
* Power management (on/off)
26+
* Configurable gains, LED drive, and thresholds
27+
* Interrupt support for light, proximity, and gesture
28+
29+
## Basic Usage
30+
31+
```python
32+
from machine import I2C
33+
from apds9960 import uAPDS9960
34+
35+
i2c = I2C(1)
36+
sensor = uAPDS9960(i2c)
37+
38+
# Read ambient light
39+
ambient = sensor.ambient_light()
40+
print("Ambient light:", ambient)
41+
42+
# Read proximity
43+
prox = sensor.proximity()
44+
print("Proximity:", prox)
45+
```
46+
47+
## API Reference
48+
49+
### General
50+
51+
* `sensor.device_id()` — read device ID (expected `0xAB`)
52+
* `sensor.power_on()` — enable the sensor
53+
* `sensor.power_off()` — disable the sensor
54+
* `sensor.data_ready()``True` when light and proximity data are ready
55+
* `sensor.get_mode()` — read current mode register
56+
* `sensor.set_mode(mode, enable=True)` — enable or disable a sensor mode
57+
58+
### Ambient Light and Color
59+
60+
#### Measurements
61+
62+
* `sensor.ambient_light()` — read ambient (clear) light value
63+
* `sensor.red_light()` — read red channel
64+
* `sensor.green_light()` — read green channel
65+
* `sensor.blue_light()` — read blue channel
66+
* `sensor.light_ready()``True` when light data is available
67+
68+
#### Control
69+
70+
* `sensor.enable_light_sensor(interrupts=True)` — enable ALS
71+
* `sensor.disable_light_sensor()` — disable ALS
72+
73+
#### Configuration
74+
75+
* `sensor.get_ambient_light_gain()` / `sensor.set_ambient_light_gain(value)` — ALS gain (0=1x, 1=4x, 2=16x, 3=64x)
76+
* `sensor.get_light_int_low_threshold()` / `sensor.set_light_int_low_threshold(value)` — low interrupt threshold
77+
* `sensor.get_light_int_high_threshold()` / `sensor.set_light_int_high_threshold(value)` — high interrupt threshold
78+
* `sensor.get_ambient_light_int_enable()` / `sensor.set_ambient_light_int_enable(enable)` — interrupt enable
79+
* `sensor.clear_ambient_light_int()` — clear light interrupt
80+
81+
### Proximity
82+
83+
#### Measurements
84+
85+
* `sensor.proximity()` — read proximity value (0–255)
86+
* `sensor.proximity_ready()``True` when proximity data is available
87+
88+
#### Control
89+
90+
* `sensor.enable_proximity_sensor(interrupts=True)` — enable proximity
91+
* `sensor.disable_proximity_sensor()` — disable proximity
92+
93+
#### Configuration
94+
95+
* `sensor.get_proximity_gain()` / `sensor.set_proximity_gain(gain)` — proximity gain (0=1x, 1=2x, 2=4x, 3=8x)
96+
* `sensor.get_led_drive()` / `sensor.set_led_drive(drive)` — LED drive strength (0=100mA, 1=50mA, 2=25mA, 3=12.5mA)
97+
* `sensor.get_led_boost()` / `sensor.set_led_boost(boost)` — LED boost
98+
* `sensor.get_prox_int_low_thresh()` / `sensor.set_prox_int_low_thresh(value)` — low proximity threshold
99+
* `sensor.get_prox_int_high_thresh()` / `sensor.set_prox_int_high_thresh(value)` — high proximity threshold
100+
* `sensor.get_proximity_int_low_threshold()` / `sensor.set_proximity_int_low_threshold(value)` — low threshold (alternative)
101+
* `sensor.get_proximity_int_high_threshold()` / `sensor.set_proximity_int_high_threshold(value)` — high threshold (alternative)
102+
* `sensor.get_proximity_int_enable()` / `sensor.set_proximity_int_enable(enable)` — interrupt enable
103+
* `sensor.clear_proximity_int()` — clear proximity interrupt
104+
* `sensor.get_prox_photo_mask()` / `sensor.set_prox_photo_mask(mask)` — photodiode mask
105+
* `sensor.get_prox_gain_comp_enable()` / `sensor.set_prox_gain_comp_enable(enable)` — gain compensation
106+
107+
### Gesture
108+
109+
#### Measurements
110+
111+
```python
112+
sensor.enable_gesture_sensor()
113+
114+
if sensor.is_gesture_available():
115+
gesture = sensor.gesture()
9116
```
117+
118+
* `sensor.gesture()` — read detected gesture
119+
* `sensor.is_gesture_available()``True` when a gesture is pending
120+
121+
**Note:** Gesture detection is not auto-enabled. Call `enable_gesture_sensor()` before polling `gesture()`.
122+
123+
#### Control
124+
125+
* `sensor.enable_gesture_sensor(interrupts=True)` — enable gesture detection
126+
* `sensor.disable_gesture_sensor()` — disable gesture detection
127+
128+
#### Configuration
129+
130+
* `sensor.get_gesture_enter_thresh()` / `sensor.set_gesture_enter_thresh(value)` — entry threshold
131+
* `sensor.get_gesture_exit_thresh()` / `sensor.set_gesture_exit_thresh(value)` — exit threshold
132+
* `sensor.get_gesture_gain()` / `sensor.set_gesture_gain(value)` — gesture gain
133+
* `sensor.get_gesture_led_drive()` / `sensor.set_gesture_led_drive(value)` — gesture LED drive
134+
* `sensor.get_gesture_wait_time()` / `sensor.set_gesture_wait_time(value)` — wait time between gesture cycles
135+
* `sensor.get_gesture_int_enable()` / `sensor.set_gesture_int_enable(enable)` — gesture interrupt enable
136+
* `sensor.get_gesture_mode()` / `sensor.set_gesture_mode(enable)` — gesture mode
137+
138+
#### Advanced
139+
140+
* `sensor.reset_gesture_parameters()` — reset internal gesture state
141+
* `sensor.process_gesture_data()` — process raw gesture FIFO data
142+
* `sensor.decode_gesture()` — decode gesture direction from processed data
143+
144+
### Exceptions
145+
146+
* `APDS9960InvalidDevId` — raised when device ID does not match `0xAB`
147+
* `APDS9960InvalidMode` — raised for invalid mode selection
148+
149+
## Examples
150+
151+
| File | Description |
152+
| ------------------ | -------------------------------- |
153+
| `ambient_light.py` | Read ambient light and RGB values |
154+
| `proximity.py` | Detect nearby objects |
155+
| `gesture.py` | Detect directional gestures |
156+
157+
```bash
158+
mpremote mount lib/apds9960 run lib/apds9960/examples/ambient_light.py
159+
```
160+
161+
## Notes
162+
163+
* Ambient light and proximity reads automatically enable their respective sensors when needed (lazy activation).
164+
* Gesture detection must be explicitly enabled before polling.
165+
* Both `APDS9960` and `uAPDS9960` (MicroPython-optimized) classes are exported.

0 commit comments

Comments
 (0)