Sample Test Program for SparkFun APDS9960 Library. Currently only tested with HRM1017.

Dependencies:   SparkFun_APDS9960 mbed

Fork of SparkFun_APDS9960_Sample by devsar devsar

Sample Program for APDS9960 library using HRM1017. Tested Pin Connection:

APDS9960 <=======> HRM1017

  • VL (Not Connected)
  • GND <=======> GND (0V)
  • VCC <=======> VDD (3.3V)
  • SDA <=======> P0_22 (sda I2C0)
  • SCL <=======> P0_20 (scl I2C0)
  • INT <=======> P0_2

Gesture result is printed out using Serial (PC).

PS: Currently planning to use HRM1017 BLE to send the result to smartphone.

APDS9960 Pinout: https://learn.sparkfun.com/tutorials/apds-9960-rgb-and-gesture-sensor-hookup-guide

HRM1017 Pinout: http://developer.mbed.org/platforms/mbed-HRM1017/

Files at this revision

API Documentation at this revision

Comitter:
devsar
Date:
Sun Apr 05 13:51:12 2015 +0000
Child:
1:530e1adf4cf4
Commit message:
Initial Release

Changed in this revision

BLE_API.lib Show annotated file Show diff for this revision Revisions of this file
SparkFun_APDS9960.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
nRF51822.lib Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/BLE_API.lib	Sun Apr 05 13:51:12 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/teams/Bluetooth-Low-Energy/code/BLE_API/#8c645f5694b2
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/SparkFun_APDS9960.lib	Sun Apr 05 13:51:12 2015 +0000
@@ -0,0 +1,1 @@
+http://developer.mbed.org/users/devsar/code/SparkFun_APDS9960/#830ac1db5bf7
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Sun Apr 05 13:51:12 2015 +0000
@@ -0,0 +1,110 @@
+/**
+ *
+ * I'm using HRM1017 for testing.
+ * Connect the following pin:
+ *  APDS9960       HRM1017
+ *   VL  (Not Connected)
+ *   GND <----------> GND (0V)
+ *   VCC <----------> VDD (3.3V)
+ *   SDA <----------> P0_22 (sda I2C0)
+ *   SCL <----------> P0_20 (scl I2C0)
+ *   INT <----------> P0_2
+ */
+
+#include "mbed.h"
+#include "apds9960.h"
+
+Ticker timer;
+Serial pc(USBTX, USBRX);
+apds9960 sensor(P0_22,P0_20);
+bool intFlag = false;
+InterruptIn interrupt(P0_2);
+DigitalOut myled(LED1);
+
+void trigger() {    
+//    pc.printf("triggered\n\r");
+    intFlag = true;
+}
+
+void printGesture(int gesture) {
+    switch ( gesture ) {
+        case DIR_UP:
+            pc.printf("UP\n\r");
+            break;
+        case DIR_DOWN:
+            pc.printf("DOWN\n\r");
+            break;
+        case DIR_LEFT:
+            pc.printf("LEFT\n\r");
+            break;
+        case DIR_RIGHT:
+            pc.printf("RIGHT\n\r");
+            break;
+        case DIR_NEAR:
+            pc.printf("NEAR\n\r");
+            break;
+        case DIR_FAR:
+            pc.printf("FAR\n\r");
+            break;
+        default:
+            pc.printf("NONE\n\r");
+    }
+}
+
+int getGesture() {
+
+    if(sensor.isGestureAvailable()) {
+        pc.printf("Gesture Available!\n\r");
+        // Process it.
+        switch ( sensor.readGesture() ) {
+            case DIR_UP: return DIR_UP;
+            case DIR_DOWN: return DIR_DOWN;
+            case DIR_LEFT: return DIR_LEFT;
+            case DIR_RIGHT: return DIR_RIGHT;
+            case DIR_NEAR: return DIR_NEAR;
+            case DIR_FAR: return DIR_FAR;
+            default: return DIR_NONE;
+        }
+    }
+    return DIR_NONE;
+}
+
+int main()
+{
+    pc.baud(115200);
+    pc.printf("Start\n\r");
+    
+    myled = 0;
+    
+    if ( sensor.ginit(pc) ) {
+        pc.printf("APDS-9960 initialization complete\n\r");
+    } else {
+        pc.printf("Something went wrong during APDS-9960 init\n\r");
+        return 1;
+    }
+ 
+    // Start running the APDS-9960 gesture sensor engine
+    if ( sensor.enableGestureSensor(true) ) {
+        pc.printf("Gesture sensor is now running\n\r");
+    } else {
+        pc.printf("Something went wrong during gesture sensor init!\n\r");
+        return 1;
+    }
+
+    interrupt.fall(&trigger);
+           
+    while(1) {
+        
+        // when interrupt trigerred, flag is set.
+        if(intFlag) {
+            //
+            printGesture(getGesture());
+            
+            // Clean interrupt handler flag.
+            intFlag = false;
+        }
+            
+        // Do somethings else
+        wait_ms(100);
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Sun Apr 05 13:51:12 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/487b796308b0
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/nRF51822.lib	Sun Apr 05 13:51:12 2015 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/teams/Nordic-Semiconductor/code/nRF51822/#bdc690669431