Skip to content

Commit f225ec4

Browse files
committed
docs: Rewrite apds9960 README addressing all review comments.
1 parent cce1f4a commit f225ec4

1 file changed

Lines changed: 94 additions & 218 deletions

File tree

lib/apds9960/README.md

Lines changed: 94 additions & 218 deletions
Original file line numberDiff line numberDiff line change
@@ -1,171 +1,112 @@
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-
## Features
6-
7-
The APDS-9960 is a multifunction sensor providing:
5+
This library is a port of [python-apds9960](https://github.com/liske/python-apds9960/).
86

9-
* **Ambient light sensing (ALS)** — clear + RGB channels
10-
* **RGB color sensing** — red, green, blue intensity
11-
* **Proximity detection** — object distance estimation
12-
* **Gesture detection** — directional gestures (up, down, left, right, near, far)
7+
## Supported Sensor
138

14-
## I2C Address
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 |
1518

16-
Default I2C address:
19+
## Features
1720

18-
```python
19-
0x39
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
2128

2229
## Basic Usage
2330

2431
```python
25-
from machine import I2C, Pin
32+
from machine import I2C
2633
from apds9960 import uAPDS9960
2734

28-
i2c = I2C(0, scl=Pin(22), sda=Pin(21))
35+
i2c = I2C(1)
2936
sensor = uAPDS9960(i2c)
3037

3138
# Read ambient light
3239
ambient = sensor.ambient_light()
3340
print("Ambient light:", ambient)
34-
```
35-
36-
Parfait — voici une version **alignée sur le style ism330dl / wsen-hids**, avec wording homogène, phrases courtes et impératives, et structure cohérente.
37-
38-
---
39-
40-
## API
41-
42-
### General
43-
44-
* `device_id()`
45-
Get the device ID
46-
47-
* `power_on()`
48-
Enable the sensor
49-
50-
* `power_off()`
51-
Disable the sensor
52-
53-
* `get_mode()`
54-
Get the current mode register value
55-
56-
* `set_mode(mode, enable=True)`
57-
Enable or disable a sensor mode
58-
59-
* `data_ready()`
60-
Check if light and proximity data are ready
61-
62-
## API
63-
64-
### Ambient Light & Color
6541

66-
#### Reading measurements
67-
68-
```python
69-
ambient = sensor.ambient_light()
70-
red = sensor.red_light()
71-
green = sensor.green_light()
72-
blue = sensor.blue_light()
42+
# Read proximity
43+
prox = sensor.proximity()
44+
print("Proximity:", prox)
7345
```
7446

75-
* `ambient_light()`
76-
Read ambient (clear) light value
47+
## API Reference
7748

78-
* `red_light()`
79-
Read red channel value
49+
### General
8050

81-
* `green_light()`
82-
Read green channel value
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
8357

84-
* `blue_light()`
85-
Read blue channel value
58+
### Ambient Light and Color
8659

87-
* `light_ready()`
88-
Check if light data is ready
60+
#### Measurements
8961

90-
#### Sensor control
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
9167

92-
* `enable_light_sensor(interrupts=True)`
93-
Enable ambient light sensing
68+
#### Control
9469

95-
* `disable_light_sensor()`
96-
Disable ambient light sensing
70+
* `sensor.enable_light_sensor(interrupts=True)` — enable ALS
71+
* `sensor.disable_light_sensor()` — disable ALS
9772

9873
#### Configuration
9974

100-
* `get_ambient_light_gain()` / `set_ambient_light_gain(value)`
101-
Get or set ambient light gain
102-
103-
* `get_light_int_low_threshold()` / `set_light_int_low_threshold(value)`
104-
Get or set low interrupt threshold
105-
106-
* `get_light_int_high_threshold()` / `set_light_int_high_threshold(value)`
107-
Get or set high interrupt threshold
108-
109-
* `get_ambient_light_int_enable()` / `set_ambient_light_int_enable(enable)`
110-
Enable or disable light interrupts
111-
112-
* `clear_ambient_light_int()`
113-
Clear ambient light interrupt
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
11480

11581
### Proximity
11682

117-
#### Reading measurements
118-
119-
```python
120-
proximity = sensor.proximity()
121-
```
122-
123-
* `proximity()`
124-
Read proximity value
83+
#### Measurements
12584

126-
* `proximity_ready()`
127-
Check if proximity data is ready
85+
* `sensor.proximity()` — read proximity value (0–255)
86+
* `sensor.proximity_ready()``True` when proximity data is available
12887

129-
#### Sensor control
88+
#### Control
13089

131-
* `enable_proximity_sensor(interrupts=True)`
132-
Enable proximity sensing
133-
134-
* `disable_proximity_sensor()`
135-
Disable proximity sensing
90+
* `sensor.enable_proximity_sensor(interrupts=True)` — enable proximity
91+
* `sensor.disable_proximity_sensor()` — disable proximity
13692

13793
#### Configuration
13894

139-
* `get_proximity_gain()` / `set_proximity_gain(value)`
140-
Get or set proximity gain
141-
142-
* `get_led_drive()` / `set_led_drive(value)`
143-
Get or set LED drive strength
144-
145-
* `get_led_boost()` / `set_led_boost(value)`
146-
Get or set LED boost
147-
148-
* `get_prox_int_low_thresh()` / `set_prox_int_low_thresh(value)`
149-
Get or set low proximity threshold
150-
151-
* `get_prox_int_high_thresh()` / `set_prox_int_high_thresh(value)`
152-
Get or set high proximity threshold
153-
154-
* `get_proximity_int_enable()` / `set_proximity_int_enable(enable)`
155-
Enable or disable proximity interrupts
156-
157-
* `clear_proximity_int()`
158-
Clear proximity interrupt
159-
160-
* `get_prox_photo_mask()` / `set_prox_photo_mask(mask)`
161-
Get or set proximity photodiode mask
162-
163-
* `get_prox_gain_comp_enable()` / `set_prox_gain_comp_enable(enable)`
164-
Enable or disable gain compensation
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
165106

166107
### Gesture
167108

168-
#### Reading measurements
109+
#### Measurements
169110

170111
```python
171112
sensor.enable_gesture_sensor()
@@ -174,116 +115,51 @@ if sensor.is_gesture_available():
174115
gesture = sensor.gesture()
175116
```
176117

177-
* `gesture()`
178-
Read detected gesture
118+
* `sensor.gesture()` — read detected gesture
119+
* `sensor.is_gesture_available()``True` when a gesture is pending
179120

180-
* `is_gesture_available()`
181-
Check if a gesture is available
121+
**Note:** Gesture detection is not auto-enabled. Call `enable_gesture_sensor()` before polling `gesture()`.
182122

183-
#### Sensor control
123+
#### Control
184124

185-
* `enable_gesture_sensor(interrupts=True)`
186-
Enable gesture detection
187-
188-
* `disable_gesture_sensor()`
189-
Disable gesture detection
125+
* `sensor.enable_gesture_sensor(interrupts=True)` — enable gesture detection
126+
* `sensor.disable_gesture_sensor()` — disable gesture detection
190127

191128
#### Configuration
192129

193-
* `get_gesture_enter_thresh()` / `set_gesture_enter_thresh(value)`
194-
Get or set gesture entry threshold
195-
196-
* `get_gesture_exit_thresh()` / `set_gesture_exit_thresh(value)`
197-
Get or set gesture exit threshold
198-
199-
* `get_gesture_gain()` / `set_gesture_gain(value)`
200-
Get or set gesture gain
201-
202-
* `get_gesture_led_drive()` / `set_gesture_led_drive(value)`
203-
Get or set gesture LED drive
204-
205-
* `get_gesture_wait_time()` / `set_gesture_wait_time(value)`
206-
Get or set gesture wait time
207-
208-
* `get_gesture_int_enable()` / `set_gesture_int_enable(enable)`
209-
Enable or disable gesture interrupts
210-
211-
* `get_gesture_mode()` / `set_gesture_mode(enable)`
212-
Enable or disable gesture mode
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
213137

214138
#### Advanced
215139

216-
* `reset_gesture_parameters()`
217-
Reset internal gesture state
218-
219-
* `process_gesture_data()`
220-
Process raw gesture data
221-
222-
* `decode_gesture()`
223-
Decode gesture direction from data
224-
225-
## Sensor Control
226-
227-
### Enable sensors
228-
229-
```python
230-
sensor.enable_light_sensor()
231-
sensor.enable_proximity_sensor()
232-
sensor.enable_gesture_sensor()
233-
```
234-
235-
### Disable sensors
236-
237-
```python
238-
sensor.disable_light_sensor()
239-
sensor.disable_proximity_sensor()
240-
sensor.disable_gesture_sensor()
241-
```
242-
243-
## Configuration Examples
244-
245-
### Set ambient light gain
246-
247-
```python
248-
sensor.set_ambient_light_gain(1) # 1x, 4x, 16x, 64x
249-
```
250-
251-
### Set proximity gain
252-
253-
```python
254-
sensor.set_proximity_gain(2) # 1x, 2x, 4x, 8x
255-
```
256-
257-
### Set LED drive strength
258-
259-
```python
260-
sensor.set_led_drive(0) # 100mA, 50mA, 25mA, 12.5mA
261-
```
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
262143

263144
### Exceptions
264145

265-
* `APDS9960InvalidDevId`invalid device ID detected
266-
* `APDS9960InvalidMode` — invalid mode selection
146+
* `APDS9960InvalidDevId`raised when device ID does not match `0xAB`
147+
* `APDS9960InvalidMode`raised for invalid mode selection
267148

268149
## Examples
269150

270-
| Example | Description |
271-
| --------------------------- | ------------------------- |
272-
| `examples/ambient_light.py` | Read ambient light values |
273-
| `examples/proximity.py` | Detect object proximity |
274-
| `examples/gesture.py` | Detect gestures |
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 |
275156

276-
Run example:
277-
278-
```sh
157+
```bash
279158
mpremote mount lib/apds9960 run lib/apds9960/examples/ambient_light.py
280159
```
281160

282161
## Notes
283162

284-
* The driver automatically enables sensors when needed (lazy activation).
285-
* Gesture detection requires continuous polling via `gesture()`.
286-
* Works with both:
287-
288-
* `APDS9960` (generic Python)
289-
* `uAPDS9960` (MicroPython optimized)
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)