I have a Sparkfun APDS9960 Gesture Sensor that works great in a Feather ESP32-V2 project with a Charlieplex screen. I get great response for up, down, left, right. Trying to get the sensor to work with Argon, without the Charlieplex, just publishing the response as an event. So far, I’ve had very little luck moving this project into Particle after two days.
I’ve tried all the libraries available, with mixed results. I read through the past posts on this, but they were unhelpful, and are all closed, so I can’t continue those threads.
What is the proven library for this device? The way that the Particle libraries are organized is pretty sloppy. There are two labeled from Adafruit, with and without typos in the name. There appear to be two Sparkfun versions, but no real distinguishing documentation as to why.
Code shown below does not work, yet I can’t see why it shouldn’t:
#include <Wire.h>
#include <SparkFun_APDS9960.h>
// Pins
#define APDS9960_INT D3 // Needs to be an interrupt pin JJD
// Constants
// Global Variables
SparkFun_APDS9960 apds = SparkFun_APDS9960();
int isr_flag = 0;
void setup() {
// Initialize Serial port
Serial.begin(9600);
Serial.println();
Serial.println(F("--------------------------------"));
Serial.println(F("SparkFun APDS-9960 - GestureTest"));
Serial.println(F("--------------------------------"));
// Initialize interrupt service routine
attachInterrupt(0, interruptRoutine, FALLING);
// Initialize APDS-9960 (configure I2C and initial values)
if ( apds.init() ) {
Serial.println(F("APDS-9960 initialization complete"));
} else {
Serial.println(F("Something went wrong during APDS-9960 init!"));
}
// Start running the APDS-9960 gesture sensor engine
if ( apds.enableGestureSensor(true) ) {
Serial.println(F("Gesture sensor is now running"));
} else {
Serial.println(F("Something went wrong during gesture sensor init!"));
}
}
void loop() {
if( isr_flag == 1 ) {
detachInterrupt(0);
handleGesture();
isr_flag = 0;
attachInterrupt(0, interruptRoutine, FALLING);
}
}
void interruptRoutine() {
isr_flag = 1;
}
void handleGesture() {
if ( apds.isGestureAvailable() ) {
switch ( apds.readGesture() ) {
case DIR_UP:
Serial.println("UP");
Particle.publish("Gesture", "UP"); // Test gesture
break;
case DIR_DOWN:
Serial.println("DOWN");
Particle.publish("Gesture", "DOWN"); // Test gesture
break;
case DIR_LEFT:
Serial.println("LEFT");
Particle.publish("Gesture", "LEFT"); // Test gesture
break;
case DIR_RIGHT:
Serial.println("RIGHT");
Particle.publish("Gesture", "RIGHT"); // Test gesture
break;
case DIR_NEAR:
Serial.println("NEAR");
Particle.publish("Gesture", "NEAR"); // Test gesture
break;
case DIR_FAR:
Serial.println("FAR");
Particle.publish("Gesture", "FAR"); // Test gesture
break;
default:
Serial.println("NONE");
}
}
}