Particle Serial timing out, not detecting cloud variables. Serial output not showing anything

I can’t seem to find what’s causing this. When I run the Terminal command particle serial list, it shows my Photon connected to the serial /dev/cu.usbmodem1411 - Photon. But when I try to run the identify command, it gets timed out.

Also, I’m using Particle Dev so I can monitor variable values. The same code runs via the Web IDE, but on Particle Dev it says no cloud variables are registered, even with the Particle.variables command declaring the variable.

Another problem I’m having is that the Serial is not actually showing anything, even though I’m calling the println method.

I’ve attached the printscreen of Particle Dev to make it clearer. Any help would be greatly appreciated!

Thanks!

Normally, you put the call to Particle.variable() in setup(), not in loop(). It registers a variable (usually a global variable) and the Particle cloud code reads the variable whenever it’s requested automatically.

2 Likes

Also, the code above has Serial.print() instead of Serial.println(). Changing both things appears to work for me. I get serial output and the cloud variable updates.

int buzzerPin = D1;
int sensorPin = A0;
int valorSensor;
int limite = 100;

void setup() {
    Serial.begin(9600);
    pinMode(buzzerPin, OUTPUT);
    Particle.variable("valorSensor", valorSensor);
}

void loop() {
    valorSensor = analogRead(sensorPin);
    Serial.println(valorSensor);
    if (valorSensor > limite) {
        delay(200);
        digitalWrite(buzzerPin, HIGH);
        delay(200);
        digitalWrite(buzzerPin, LOW);
    }
}
1 Like

Hi! Thanks for the reply. It was actually working the way it was… It appears that the Particle Dev app was buggy. I restarted it and now it’s reading the variables and the serial monitor is working fine.

Regardless, that’s not how you should declare variables, and although it might work now, it’ll give you more problems than its worth later on. Please consider switching to the thoughtful suggestions made above.

2 Likes

But you'd still have to use Particle.variable() the way it's intended and pointed out by @rickkas7.
These are not to be pushed (over and over in loop()) but exposed (only once in setup()).

1 Like

Oh sorry! I forgot to mention that I made the suggested changes because indeed it makes more sense.

Particle.variables is now under Setup() :blush:

Thanks once again!