You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Please ensure all dependencies are available on the CircuitPython filesystem.
36
+
29
37
This is easily achieved by downloading
30
38
`the Adafruit library and driver bundle <https://github.com/adafruit/Adafruit_CircuitPython_Bundle>`_.
31
39
32
40
Installing from PyPI
33
41
--------------------
34
42
35
-
On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally `from PyPI <https://pypi.org/project/adafruit-circuitpython-apds9960/>`_. To install for current user:
43
+
On supported GNU/Linux systems like the Raspberry Pi, you can install the driver locally `from PyPI <https://pypi.org/project/adafruit-circuitpython-apds9960/>`_.
44
+
45
+
To install for current user:
36
46
37
47
.. code-block:: shell
38
48
@@ -64,98 +74,165 @@ Usage Example
64
74
65
75
i2c = board.I2C()
66
76
int_pin = digitalio.DigitalInOut(board.D5)
77
+
int_pin.switch_to_input(pull=digitalio.Pull.UP)
67
78
apds = APDS9960(i2c)
68
79
69
-
apds.enable_proximity = True
70
-
apds.proximity_interrupt_threshold = (0, 175)
71
80
apds.enable_proximity_interrupt = True
81
+
apds.proximity_interrupt_threshold = (0, 175)
82
+
apds.enable_proximity = True
72
83
73
84
while True:
85
+
if not int_pin.value:
74
86
print(apds.proximity)
75
87
apds.clear_interrupt()
76
88
77
89
Hardware Set-up
78
90
---------------
79
91
80
-
Connect Vin to 3.3 V or 5 V power source, GND to ground, SCL and SDA to the appropriate pins.
92
+
If you're using a board with a built-in APDS-9960, no hardware setup will be required.
93
+
94
+
If you're using a breakout board via the pin header, connect ``Vin`` to a 3.3 V or 5 V power source,
95
+
connect ``GND`` to ground, then connect ``SCL`` and ``SDA`` to the appropriate pins.
96
+
97
+
Optionally, if you'd like to use the sensor's interrupt pin connect ``INT`` to any available
98
+
digital I/O pin.
81
99
82
100
Basics
83
101
------
84
102
85
-
Of course, you must import i2c bus device, board pins, and the library:
103
+
To get started, import ``board`` and, and this library:
86
104
87
105
.. code:: python3
88
106
89
107
90
-
import board
91
-
from adafruit_apds9960.apds9960 import APDS9960
92
-
import digitalio
108
+
import board
109
+
from adafruit_apds9960.apds9960 import APDS9960
93
110
94
-
To set-up the device to gather data, initialize the I2CDevice using SCL
95
-
and SDA pins. Then initialize the library. Optionally provide an interrupt
96
-
pin for proximity detection.
111
+
To set up the sensor to gather data, initialize the I2C bus via ``board.I2C()``
112
+
then initialize the APDS-9960 library.
97
113
98
114
.. code:: python3
99
115
100
-
int_pin = digitalio.DigitalInOut(board.A1)
101
-
i2c = board.I2C()
102
-
apds = APDS9960(i2c)
116
+
i2c = board.I2C()
117
+
apds = APDS9960(i2c)
118
+
119
+
Proximity
120
+
---------
121
+
122
+
To get a proximity result, enable the proximity engine then read the `proximity` value.
123
+
124
+
This will return a value between 0 and 255, with higher values indicating that something is close
125
+
to the sensor.
126
+
127
+
.. code:: python3
128
+
129
+
apds.enable_proximity = True
130
+
131
+
while True:
132
+
print(apds.proximity)
103
133
104
134
Gestures
105
135
--------
106
136
107
-
To get a gesture, see if a gesture is available first, then get the gesture Code
137
+
First, enable both the proximity and gesture engines. The gesture engine relies on the proximity
138
+
engine to determine when to start itself up and, as a result, proximity readings won't be reliable
139
+
while the gesture engine is enabled.
140
+
141
+
To get a gesture, use the `gesture()` function to see if a gesture has been detected. If a value
142
+
greater than 0 is returned, a gesture has been detected.
108
143
109
144
.. code:: python3
110
145
111
-
gesture = apds.gesture()
112
-
if gesture == 1:
113
-
print("up")
114
-
if gesture == 2:
115
-
print("down")
116
-
if gesture == 3:
117
-
print("left")
118
-
if gesture == 4:
119
-
print("right")
146
+
# Uncomment and set the rotation if depending on how your sensor is mounted.
147
+
# apds.rotation = 270 # 270 for CLUE
120
148
121
-
Color Measurement
122
-
-----------------
149
+
apds.enable_proximity = True
150
+
apds.enable_gesture = True
123
151
124
-
To get a color measure, enable color measures, wait for color data,
125
-
then get the color data.
152
+
while True:
153
+
gesture = apds.gesture()
154
+
if gesture == 1:
155
+
print("up")
156
+
if gesture == 2:
157
+
print("down")
158
+
if gesture == 3:
159
+
print("left")
160
+
if gesture == 4:
161
+
print("right")
162
+
163
+
Color/Light Measurement
164
+
-----------------------
165
+
166
+
To get a color measurement, first enable the color/light engine, wait for color data to arrive,
0 commit comments