Hi
I have a program that calculates the rpm of a motor using an IR proximity sensor. This works pretty well, the rpm is correctly displayed in the serial monitor. But if I want to send this variable to Cayenne, it doesn’t show up correctly in the dashboard (it just says 0). Anyone with some advice? This is the code I used:
float rev = 0;
float rpm = 0;
unsigned long timeold = 0;
int measuretime = 1000;
void setup()
{
Serial.begin(115200);
attachInterrupt(digitalPinToInterrupt(5),RPMcount,FALLING);
Cayenne.begin(username, password, clientID, ssid, wifiPassword);
}
ICACHE_RAM_ATTR void RPMcount()
rev++;
}
void loop() {
Cayenne.loop();
if (millis() - timeold == measuretime)
{ detachInterrupt(digitalPinToInterrupt(5));
rpm=rev*(60000/measuretime);
Serial.println(rpm, DEC);
rev=0;
timeold=millis();
attachInterrupt(digitalPinToInterrupt(5),RPMcount,FALLING);
}
Cayenne.virtualWrite(1, rpm, “analog_sensor”, “null”);