Skip to content

Commit 7c8a5de

Browse files
Restructured
1 parent fd5b4cd commit 7c8a5de

File tree

12 files changed

+3214
-69
lines changed

12 files changed

+3214
-69
lines changed

Diff for: README.md

+46-12
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,39 @@
1-
SparkFun <PRODUCT NAME> Arduino Library
1+
SparkFun_APDS9960 RGB and Gesture Sensor Arduino Library
22
========================================
33

4-
![SparkFun Part Name](URL for picture of part)
4+
![Avago APDS-9960 Breakout Board - SEN-12787 ](https://cdn.sparkfun.com/r/92-92/assets/parts/9/6/0/3/12787-01.jpg)
55

6-
[*SparkFun Part Name (SKU)*](URL for product on Sparkfun.com)
6+
[*Avago APDS-9960 Breakout Board (SEN-12787)*](https://www.sparkfun.com/products/12787)
77

8-
<Basic description of the library.>
8+
Getting Started
9+
---------------
10+
11+
* Download the Git repository as a ZIP ("Download ZIP" button)
12+
* Unzip
13+
* Copy the entire library directory (APDS-9960_RGB_and_Gesture_Sensor_Arduino_Library
14+
) to \<Arduino installation directory\>/libraries
15+
* Open the Arduino program
16+
* Select File -> Examples -> SparkFun_APDS9960 -> GestureTest
17+
* Plug in your Arduino and APDS-9960 with the following connections
18+
19+
*-OR-*
20+
21+
* Use the library manager
22+
23+
| Arduino Pin | APDS-9960 Board | Function |
24+
|---|---|---|
25+
| 3.3V | VCC | Power |
26+
| GND | GND | Ground |
27+
| A4 | SDA | I2C Data |
28+
| A5 | SCL | I2C Clock |
29+
| 2 | INT | Interrupt |
30+
31+
* Go to Tools -> Board and select your Arduino board
32+
* Go to Tools -> Serial Port and select the COM port of your Arduino board
33+
* Click "Upload"
34+
* Go to Tools -> Serial Monitor
35+
* Ensure the baud rate is set at 9600 baud
36+
* Swipe your hand over the sensor in various directions!
937

1038
Repository Contents
1139
-------------------
@@ -20,21 +48,26 @@ Documentation
2048
--------------
2149

2250
* **[Installing an Arduino Library Guide](https://learn.sparkfun.com/tutorials/installing-an-arduino-library)** - Basic information on how to install an Arduino library.
23-
* **[Product Repository](GitHub Product URL)** - Main repository (including hardware files) for the <PRODUCT NAME>.
24-
* **[Hookup Guide](Learn.SparkFun URL)** - Basic hookup guide for the <PRODUCT NAME>.
51+
* **[Product Repository](https://github.com/sparkfun/APDS-9960_RGB_and_Gesture_Sensor)** - Main repository (including hardware files) for the SparkFun_APDS9960 RGB and Gesture Sensor.
52+
* **[Quickstart Guide](https://learn.sparkfun.com/tutorials/bmp180-barometric-pressure-sensor-hookup-)** - Basic hookup guide for the sensor.
2553

2654
Products that use this Library
2755
---------------------------------
2856

29-
* [Part SKU](SparkFun part URL)- Basic part and short description here
30-
* [Part SKU](SparkFun part URL)- Basic part and short description here
57+
* [SEN-12787](https://www.sparkfun.com/products/12787)- Avago APDS-9960
3158

3259
Version History
3360
---------------
34-
35-
* [vExxFxxZxxHxxLxxSxx](URL for tag specific to this version) - Description
36-
* [vEyyFyyZyyHyyLyySyy](URL for tag specific to this version) - Description
37-
61+
* [V_1.4.0](https://github.com/sparkfun/APDS-9960_RGB_and_Gesture_Sensor_Arduino_Library/tree/V_1.4.0) - Updated to new library structure
62+
* V_1.3.0 - Implemented disableProximitySensor(). Thanks to jmg5150 for catching that!
63+
* V_1.2.0 - Added pinMode line to GestureTest demo to fix interrupt bug with some Arduinos
64+
* V_1.1.0 - Updated GestureTest demo to not freeze with fast swipes
65+
* V_1.0.0: Initial release
66+
-- Ambient and RGB light sensing implemented
67+
-- Ambient light interrupts working
68+
-- Proximity sensing implemented
69+
-- Proximity interrupts working
70+
-- Gesture (UP, DOWN, LEFT, RIGHT, NEAR, FAR) sensing implemented
3871
License Information
3972
-------------------
4073

@@ -49,3 +82,4 @@ Distributed as-is; no warranty is given.
4982
- Your friends at SparkFun.
5083

5184
_<COLLABORATION CREDIT>_
85+
+161
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,161 @@
1+
/****************************************************************
2+
AmbientLightInterrupt.ino
3+
APDS-9960 RGB and Gesture Sensor
4+
Shawn Hymel @ SparkFun Electronics
5+
October 24, 2014
6+
https://github.com/sparkfun/APDS-9960_RGB_and_Gesture_Sensor
7+
8+
Tests the ambient light interrupt abilities of the APDS-9960.
9+
Configures the APDS-9960 over I2C and waits for an external
10+
interrupt based on high or low light conditions. Try covering
11+
the sensor with your hand or bringing the sensor close to a
12+
bright light source. You might need to adjust the LIGHT_INT_HIGH
13+
and LIGHT_INT_LOW values to get the interrupt to work correctly.
14+
15+
Hardware Connections:
16+
17+
IMPORTANT: The APDS-9960 can only accept 3.3V!
18+
19+
Arduino Pin APDS-9960 Board Function
20+
21+
3.3V VCC Power
22+
GND GND Ground
23+
A4 SDA I2C Data
24+
A5 SCL I2C Clock
25+
2 INT Interrupt
26+
13 - LED
27+
28+
Resources:
29+
Include Wire.h and SparkFun_APDS-9960.h
30+
31+
Development environment specifics:
32+
Written in Arduino 1.0.5
33+
Tested with SparkFun Arduino Pro Mini 3.3V
34+
35+
This code is beerware; if you see me (or any other SparkFun
36+
employee) at the local, and you've found our code helpful, please
37+
buy us a round!
38+
39+
Distributed as-is; no warranty is given.
40+
****************************************************************/
41+
42+
#include <Wire.h>
43+
#include <SparkFun_APDS9960.h>
44+
45+
// Pins
46+
#define APDS9960_INT 2 // Needs to be an interrupt pin
47+
#define LED_PIN 13 // LED for showing interrupt
48+
49+
// Constants
50+
#define LIGHT_INT_HIGH 1000 // High light level for interrupt
51+
#define LIGHT_INT_LOW 10 // Low light level for interrupt
52+
53+
// Global variables
54+
SparkFun_APDS9960 apds = SparkFun_APDS9960();
55+
uint16_t ambient_light = 0;
56+
uint16_t red_light = 0;
57+
uint16_t green_light = 0;
58+
uint16_t blue_light = 0;
59+
int isr_flag = 0;
60+
uint16_t threshold = 0;
61+
62+
void setup() {
63+
64+
// Set LED as output
65+
pinMode(LED_PIN, OUTPUT);
66+
pinMode(APDS9960_INT, INPUT);
67+
68+
// Initialize Serial port
69+
Serial.begin(9600);
70+
Serial.println();
71+
Serial.println(F("-------------------------------------"));
72+
Serial.println(F("SparkFun APDS-9960 - Light Interrupts"));
73+
Serial.println(F("-------------------------------------"));
74+
75+
// Initialize interrupt service routine
76+
attachInterrupt(0, interruptRoutine, FALLING);
77+
78+
// Initialize APDS-9960 (configure I2C and initial values)
79+
if ( apds.init() ) {
80+
Serial.println(F("APDS-9960 initialization complete"));
81+
} else {
82+
Serial.println(F("Something went wrong during APDS-9960 init!"));
83+
}
84+
85+
// Set high and low interrupt thresholds
86+
if ( !apds.setLightIntLowThreshold(LIGHT_INT_LOW) ) {
87+
Serial.println(F("Error writing low threshold"));
88+
}
89+
if ( !apds.setLightIntHighThreshold(LIGHT_INT_HIGH) ) {
90+
Serial.println(F("Error writing high threshold"));
91+
}
92+
93+
// Start running the APDS-9960 light sensor (no interrupts)
94+
if ( apds.enableLightSensor(false) ) {
95+
Serial.println(F("Light sensor is now running"));
96+
} else {
97+
Serial.println(F("Something went wrong during light sensor init!"));
98+
}
99+
100+
// Read high and low interrupt thresholds
101+
if ( !apds.getLightIntLowThreshold(threshold) ) {
102+
Serial.println(F("Error reading low threshold"));
103+
} else {
104+
Serial.print(F("Low Threshold: "));
105+
Serial.println(threshold);
106+
}
107+
if ( !apds.getLightIntHighThreshold(threshold) ) {
108+
Serial.println(F("Error reading high threshold"));
109+
} else {
110+
Serial.print(F("High Threshold: "));
111+
Serial.println(threshold);
112+
}
113+
114+
// Enable interrupts
115+
if ( !apds.setAmbientLightIntEnable(1) ) {
116+
Serial.println(F("Error enabling interrupts"));
117+
}
118+
119+
// Wait for initialization and calibration to finish
120+
delay(500);
121+
}
122+
123+
void loop() {
124+
125+
// If interrupt occurs, print out the light levels
126+
if ( isr_flag == 1 ) {
127+
128+
// Read the light levels (ambient, red, green, blue) and print
129+
if ( !apds.readAmbientLight(ambient_light) ||
130+
!apds.readRedLight(red_light) ||
131+
!apds.readGreenLight(green_light) ||
132+
!apds.readBlueLight(blue_light) ) {
133+
Serial.println("Error reading light values");
134+
} else {
135+
Serial.print("Interrupt! Ambient: ");
136+
Serial.print(ambient_light);
137+
Serial.print(" R: ");
138+
Serial.print(red_light);
139+
Serial.print(" G: ");
140+
Serial.print(green_light);
141+
Serial.print(" B: ");
142+
Serial.println(blue_light);
143+
}
144+
145+
// Turn on LED for a half a second
146+
digitalWrite(LED_PIN, HIGH);
147+
delay(500);
148+
digitalWrite(LED_PIN, LOW);
149+
150+
// Reset flag and clear APDS-9960 interrupt (IMPORTANT!)
151+
isr_flag = 0;
152+
if ( !apds.clearAmbientLightInt() ) {
153+
Serial.println("Error clearing interrupt");
154+
}
155+
156+
}
157+
}
158+
159+
void interruptRoutine() {
160+
isr_flag = 1;
161+
}

Diff for: examples/ColorSensor/ColorSensor.ino

+96
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,96 @@
1+
/****************************************************************
2+
ColorSensor.ino
3+
APDS-9960 RGB and Gesture Sensor
4+
Shawn Hymel @ SparkFun Electronics
5+
October 15, 2014
6+
https://github.com/sparkfun/APDS-9960_RGB_and_Gesture_Sensor
7+
8+
Tests the color and ambient light sensing abilities of the
9+
APDS-9960. Configures APDS-9960 over I2C and polls the sensor for
10+
ambient light and color levels, which are displayed over the
11+
serial console.
12+
13+
Hardware Connections:
14+
15+
IMPORTANT: The APDS-9960 can only accept 3.3V!
16+
17+
Arduino Pin APDS-9960 Board Function
18+
19+
3.3V VCC Power
20+
GND GND Ground
21+
A4 SDA I2C Data
22+
A5 SCL I2C Clock
23+
24+
Resources:
25+
Include Wire.h and SparkFun_APDS-9960.h
26+
27+
Development environment specifics:
28+
Written in Arduino 1.0.5
29+
Tested with SparkFun Arduino Pro Mini 3.3V
30+
31+
This code is beerware; if you see me (or any other SparkFun
32+
employee) at the local, and you've found our code helpful, please
33+
buy us a round!
34+
35+
Distributed as-is; no warranty is given.
36+
****************************************************************/
37+
38+
#include <Wire.h>
39+
#include <SparkFun_APDS9960.h>
40+
41+
// Global Variables
42+
SparkFun_APDS9960 apds = SparkFun_APDS9960();
43+
uint16_t ambient_light = 0;
44+
uint16_t red_light = 0;
45+
uint16_t green_light = 0;
46+
uint16_t blue_light = 0;
47+
48+
void setup() {
49+
50+
// Initialize Serial port
51+
Serial.begin(9600);
52+
Serial.println();
53+
Serial.println(F("--------------------------------"));
54+
Serial.println(F("SparkFun APDS-9960 - ColorSensor"));
55+
Serial.println(F("--------------------------------"));
56+
57+
// Initialize APDS-9960 (configure I2C and initial values)
58+
if ( apds.init() ) {
59+
Serial.println(F("APDS-9960 initialization complete"));
60+
} else {
61+
Serial.println(F("Something went wrong during APDS-9960 init!"));
62+
}
63+
64+
// Start running the APDS-9960 light sensor (no interrupts)
65+
if ( apds.enableLightSensor(false) ) {
66+
Serial.println(F("Light sensor is now running"));
67+
} else {
68+
Serial.println(F("Something went wrong during light sensor init!"));
69+
}
70+
71+
// Wait for initialization and calibration to finish
72+
delay(500);
73+
}
74+
75+
void loop() {
76+
77+
// Read the light levels (ambient, red, green, blue)
78+
if ( !apds.readAmbientLight(ambient_light) ||
79+
!apds.readRedLight(red_light) ||
80+
!apds.readGreenLight(green_light) ||
81+
!apds.readBlueLight(blue_light) ) {
82+
Serial.println("Error reading light values");
83+
} else {
84+
Serial.print("Ambient: ");
85+
Serial.print(ambient_light);
86+
Serial.print(" Red: ");
87+
Serial.print(red_light);
88+
Serial.print(" Green: ");
89+
Serial.print(green_light);
90+
Serial.print(" Blue: ");
91+
Serial.println(blue_light);
92+
}
93+
94+
// Wait 1 second before next reading
95+
delay(1000);
96+
}

0 commit comments

Comments
 (0)