Photon shows steady cyan

After flashing code OTA, and confirming that the firmware was updated to 0.4.4, the code originally ran fine. After powering down, and back up again, I now get a steady cyan, or sometimes, no light at all. What does this mean?

Steady cyan isn’t an expected type of LED behavior - it could indicate the system has hung. Does your code have any calls to System.sleep()? It could also be a high-priority interrupt that is preventing the LED from updating. What kind of peripherals do you have connected?

Please try flashing the code again, to see if that resolves the issue. If not, please post your code if you’re able to and we’ll try to reproduce and investigate the problem.

The thing is, the code ran correctly, then I added one line (to print out the wifi signal strength), and that’s when I got this unexpected behavior. I commented out that line and flashed again, but I still get the same behavior. When I try to flash new code (using the web IDE), I’m not getting any flashing magenta, but the IDE says that the code was flashed successfully. Here is the code,

int trigPin = D0;  
int echoRisingPin = D2;
int echoFallingPin = D4;
unsigned long startTime;
unsigned long endTime;
long distance;
STARTUP(WiFi.selectAntenna(ANT_INTERNAL));

void setup() {
    Serial.begin(9600);
    pinMode(trigPin, OUTPUT);
    attachInterrupt(echoRisingPin, risingDetect, RISING);
    attachInterrupt(echoFallingPin, fallingDetect, FALLING);
    digitalWrite(trigPin, LOW);
    delayMicroseconds(100);
}

void loop() {
    digitalWrite(trigPin, HIGH);
    delayMicroseconds(15);
    digitalWrite(trigPin, LOW);
    delay(1000);
}

void risingDetect() {
    startTime = micros();
}

void fallingDetect() {
    endTime = micros();
    distance = (endTime - startTime)/5.82; // distance in millimeters;
    if (distance > 0 && distance < 2000) {
        Serial.println(distance);
        //Serial.println(WiFi.RSSI());
    }
    
}

When your application code prevents OTA updates from happening, you can use Safe Mode to instruct the system to not run your app. Instructions for doing that are in the docs at http://docs.particle.io.

You’re calling Serial.println() from an interrupt. That’s not going to work! :wink: Interrupt handlers should be very quick and not perform complex I/O like USB serial.

I was not aware that Serial.println() was considered a complex operation that would be too slow for an ISR, so thanks for that tip. The program runs fine with Serial.println(distance), but not with Serial.println(WiFi.RSSI()), so is there something specific about that print statement that makes it not work? Should I avoid any use of serial within an ISR? I was just using the serial monitor for testing purposes; in actual use, I will expose distance as a Spark.variable, and query that from an iOS app, or publish based on a change of a certain magnitude of that variable. Is it safe to publish from an ISR, or do I need to do that from within loop()?

Actually, I might be mistaken here, Serial.print() might work since it’s just about copying data to a buffer, but I still personally prefer to avoid it, since Serial isn’t thread safe

The culprit is more likely to the WiFi.RSSI() call, this definitely is a complex operation on both the Core and the Photon, and should be performed on the main loop. I hope that helps. :smile:

I am getting steady cyan, from a brand new, just wifi configured photon… Theres no code in it.

Any ideas?

Can you try safe mode and see if you get breathing magenta?