|
2 | 2 |
|
3 | 3 | This library is a port of the [Python (and MicroPython) APDS-9960 Library](https://github.com/liske/python-apds9960/). |
4 | 4 |
|
5 | | -The examples could be easily tested with [mpremote](https://docs.micropython.org/en/latest/reference/mpremote.html) with the following command : |
| 5 | +## Features |
| 6 | + |
| 7 | +The APDS-9960 is a multifunction sensor providing: |
| 8 | + |
| 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) |
| 13 | + |
| 14 | +## I2C Address |
| 15 | + |
| 16 | +Default I2C address: |
| 17 | + |
| 18 | +```python |
| 19 | +0x39 |
| 20 | +``` |
| 21 | + |
| 22 | +## Basic Usage |
| 23 | + |
| 24 | +```python |
| 25 | +from machine import I2C, Pin |
| 26 | +from apds9960 import uAPDS9960 |
| 27 | + |
| 28 | +i2c = I2C(0, scl=Pin(22), sda=Pin(21)) |
| 29 | +sensor = uAPDS9960(i2c) |
| 30 | + |
| 31 | +# Read ambient light |
| 32 | +ambient = sensor.ambient_light() |
| 33 | +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 |
| 65 | + |
| 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() |
| 73 | +``` |
| 74 | + |
| 75 | +* `ambient_light()` |
| 76 | + Read ambient (clear) light value |
| 77 | + |
| 78 | +* `red_light()` |
| 79 | + Read red channel value |
| 80 | + |
| 81 | +* `green_light()` |
| 82 | + Read green channel value |
| 83 | + |
| 84 | +* `blue_light()` |
| 85 | + Read blue channel value |
| 86 | + |
| 87 | +* `light_ready()` |
| 88 | + Check if light data is ready |
| 89 | + |
| 90 | +#### Sensor control |
| 91 | + |
| 92 | +* `enable_light_sensor(interrupts=True)` |
| 93 | + Enable ambient light sensing |
| 94 | + |
| 95 | +* `disable_light_sensor()` |
| 96 | + Disable ambient light sensing |
| 97 | + |
| 98 | +#### Configuration |
| 99 | + |
| 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 |
| 114 | + |
| 115 | +### Proximity |
| 116 | + |
| 117 | +#### Reading measurements |
| 118 | + |
| 119 | +```python |
| 120 | +proximity = sensor.proximity() |
| 121 | +``` |
| 122 | + |
| 123 | +* `proximity()` |
| 124 | + Read proximity value |
| 125 | + |
| 126 | +* `proximity_ready()` |
| 127 | + Check if proximity data is ready |
| 128 | + |
| 129 | +#### Sensor control |
| 130 | + |
| 131 | +* `enable_proximity_sensor(interrupts=True)` |
| 132 | + Enable proximity sensing |
| 133 | + |
| 134 | +* `disable_proximity_sensor()` |
| 135 | + Disable proximity sensing |
| 136 | + |
| 137 | +#### Configuration |
| 138 | + |
| 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 |
| 165 | + |
| 166 | +### Gesture |
| 167 | + |
| 168 | +#### Reading measurements |
| 169 | + |
| 170 | +```python |
| 171 | +sensor.enable_gesture_sensor() |
| 172 | + |
| 173 | +if sensor.is_gesture_available(): |
| 174 | + gesture = sensor.gesture() |
| 175 | +``` |
| 176 | + |
| 177 | +* `gesture()` |
| 178 | + Read detected gesture |
| 179 | + |
| 180 | +* `is_gesture_available()` |
| 181 | + Check if a gesture is available |
| 182 | + |
| 183 | +#### Sensor control |
| 184 | + |
| 185 | +* `enable_gesture_sensor(interrupts=True)` |
| 186 | + Enable gesture detection |
| 187 | + |
| 188 | +* `disable_gesture_sensor()` |
| 189 | + Disable gesture detection |
| 190 | + |
| 191 | +#### Configuration |
| 192 | + |
| 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 |
| 213 | + |
| 214 | +#### Advanced |
| 215 | + |
| 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 | +``` |
| 262 | + |
| 263 | +### Exceptions |
| 264 | + |
| 265 | +* `APDS9960InvalidDevId` — invalid device ID detected |
| 266 | +* `APDS9960InvalidMode` — invalid mode selection |
| 267 | + |
| 268 | +## Examples |
| 269 | + |
| 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 | |
| 275 | + |
| 276 | +Run example: |
6 | 277 |
|
7 | 278 | ```sh |
8 | | - mpremote mount . run examples/ambient_light.py |
| 279 | +mpremote mount lib/apds9960 run lib/apds9960/examples/ambient_light.py |
9 | 280 | ``` |
| 281 | + |
| 282 | +## Notes |
| 283 | + |
| 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) |
0 commit comments