Hi community,
I’m working on a project called Touchless gesture detection. When I flash the code using particle dev app the photon goes offline and it does not breathe cyan and it only stays with the Cyan. My code doesn’t have any errors and I’m using a cpp file with .ino file and apds9960 arduino library functions of Gesture sensor APDS9960. What seems to be the problem with photon if it’s connecting to the cloud or just stay cyan and not breathe cyan ?
Since we can’t see your code we can just guess, and I would guess your code does block in a way that even stalls the system logic.
// This #include statement was automatically added by the Particle IDE.
#include "SparkFun_APDS9960.h"
#define DEBUG
// This #include statement was automatically added by the Particle IDE.
#include "SparkFun_APDS9960.h"
// Interrupt Pin
#define APDS9960_INT D3
SparkFun_APDS9960 apds = SparkFun_APDS9960();
int isr_flag = 0;
void setup()
{
// Set interrupt pin as input
pinMode(APDS9960_INT, INPUT);
// Initialize Serial port
Serial.begin(9600);
delay(3000);
// Initialize interrupt service routine
attachInterrupt(APDS9960_INT, interruptRoutine, FALLING);
if(apds.init())
{
Serial.println(F("Gesture Sensor initialized."));
}
else
{
Serial.println(F("Gesture Sensor failed."));
}
if(apds.enableGestureSensor(true)){
Serial.println(F("Gesture sensor is now running"));
}
}
void loop() {
if(isr_flag == 1){
detachInterrupt(APDS9960_INT);
handleGesture();
isr_flag = 0;
attachInterrupt(APDS9960_INT, interruptRoutine, FALLING);
}
}
void interruptRoutine(){
isr_flag = 1;
}
void handleGesture(){
if(apds.isGestureAvailable())
{
char events[8];
events[0] = 0;
switch ( apds.readGesture() ) {
case DIR_UP: strcpy(events, "UP"); break;
case DIR_DOWN: strcpy(events, "DOWN"); break;
case DIR_LEFT: strcpy(events, "LEFT"); break;
case DIR_RIGHT: strcpy(events, "RIGHT"); break;
}
if(strlen(events) > 0){
Serial.println(events);
publishEvent(events);
}
}
}
void publishEvent(char* events){
Spark.publish("GESTURE-EVENT", events, 60, PRIVATE);
}
This is my code when I compile it doesn’t show any errors.
One thing: You should do this instead
volatile int isr_flag = 0;
It might not solve your problem tho’
But missing pull-up resistors on the I2C lines might explain your hanging Photon
@vnalla, @ScruffR is totally spot on (as usual). If you are using the Sparkfun sensor breakout then the pull-ups are there. One thing to note from the documentation is:
NOTE: pinMode() MUST be called prior to calling attachInterrupt() to set the desired mode for the interrupt pin (INPUT, INPUT_PULLUP or INPUT_PULLDOWN).
You may want to call pinMode() again prior to the attachInterrupt() in loop(). There still remains the possibility that I2C is stalling. One thing you have not mentioned is what, if anything, is showing up on the Serial port?
Just seen a parallel thread where the code comment suggests some possible issue with the wiring.
Gesture detection using Particle Core and SparkFun Gesture Sensor
How have you wired the board?