Photon keeps going to breathing green

Hey Guys!

I’m having a lot of trouble with a couple of photons. They are brand new.

Had a bit of trouble with it going to breathing magenta, but flashed new firmware to it via the dfu utility.
It runs a small blink led script - no problem.
But whenever i flash the code that i want it to run, it uploads and then shortly afterwards turns green.
I have two other photons running the code already so the code shouldn’t be a problem.
I’ve tried giving it the wifi credentials again but it doesn’t seem to work.

Any help? I dont know what to do since the code is compiling and running on 2 other photons already.

/Christian

Breathing green indicates a loss of cloud connection. Not sure why the other two work, but sharing your code here might help us figure things out. Adding Particle.process() in long running functions might also help.

1 Like

Thanks I’ll try putting in some Particle.process()'s in the longer functions.

The code looks like this:

#include "Adafruit_LIS3DH.h"
#include "Adafruit_Sensor.h"
// Used for software SPI
#define LIS3DH_CLK A3 //SCL
#define LIS3DH_MISO A4 //SDO
#define LIS3DH_MOSI A5 //SDA
// Used for hardware & software SPI
#define LIS3DH_CS A2 //CS
Adafruit_LIS3DH lis = Adafruit_LIS3DH(LIS3DH_CS, LIS3DH_MOSI, LIS3DH_MISO, LIS3DH_CLK);
//Defining pins
const int pingPin = D4;
const int pinMove = D5;
const int pinStand = D6;
const int pinExercise = D7;
const int pinButton = D3;
unsigned long data_timer;
double dist = 0.0;
double acc = 0.0;

void setup(){

    Serial.begin(9600);

    if (! lis.begin(0x18)) {   // change this to 0x19 for alternative i2c address
      Serial.println("Couldnt start");
      while (1);
    }
    delay(1000);

    lis.setRange(LIS3DH_RANGE_4_G);   // 2, 4, 8 or 16 G

    pinMode(pinMove, OUTPUT);
    pinMode(pinExercise, OUTPUT);
    pinMode(pinStand, OUTPUT);

    pinMode(pinButton,INPUT_PULLUP);
    delay(1000);
}

void loop(){

if (millis() - data_timer > 5000) {
  dist = dist_read();
  acc = acc_read();

  Serial.print("acc ");
  Serial.print(acc);
  Serial.print(" dist ");
  Serial.println(dist);

  changeLED(pinExercise,HIGH);
  delay(100);
  changeLED(pinExercise,LOW);
  changeLED(pinStand,HIGH);
  delay(100);
  changeLED(pinStand,LOW);
  changeLED(pinMove,HIGH);
  delay(100);
  changeLED(pinMove,LOW);

  data_timer = millis();
}
readButton();
}

// This function calculates the distance.
double dist_read(){
    // The PING))) is triggered by a HIGH pulse of 2 or more microseconds.
    // Give a short LOW pulse beforehand to ensure a clean HIGH pulse:
    pinMode(pingPin, OUTPUT);
    digitalWrite(pingPin, LOW);
    delayMicroseconds(2);
    digitalWrite(pingPin, HIGH);
    delayMicroseconds(5);
    digitalWrite(pingPin, LOW);
    // The same pin is used to read the signal from the PING))): a HIGH
    // pulse whose duration is the time (in microseconds) from the sending
    // of the ping to the reception of its echo off of an object.
    pinMode(pingPin, INPUT);
    long duration = pulseIn(pingPin, HIGH);
    double tempdist = double (duration) / 29.00 / 2.00; //convert time duration into distance in cm.
    return tempdist;
}

double acc_read(){
  lis.read();
  double temp_acc = (double) lis.z;
  return temp_acc;
}

//A function for the state of a LED
void changeLED(int pin, int onoff){
    digitalWrite(pin,onoff);
}

//A function for reading button input
void readButton(){
    if(digitalRead(pinButton) == 0){
      changeLED(pinExercise,HIGH);
      changeLED(pinStand,HIGH);
      changeLED(pinMove,HIGH);
      delay(100);
      changeLED(pinExercise,LOW);
      changeLED(pinStand,LOW);
      changeLED(pinMove,LOW);
    }
    else{
        return;
    }
    return;
}

This is most likely where your code gets stuck and telling that the code runs on other Photons omits the hardware dependency here, if your sensor doesn’t respond properly you’re stuck in that loop and will lose cloud connection.

Change this to

  while(1) Particle.process();

and see how it goes.

Hey ScruffR,

It was exactly what you said! The Particle.process(); solved the problem!
Thanks a lot for the help!

1 Like