Problem Graphing data


#1

Hi,
I am doing a project for a health device, I will be uploading ECG, temperature and an accelerometer.
I can only upload my x,y,z axis seperate as only a numerical value but any time I try and change it to a line graph it comes up as incompatible widget. Then when i do a custom widget it said no data. This is happening with the ECG too, i really need them as graphs, please help.

Cayenne.loop();
if (millis() - lastMillis > 2000) {
lastMillis = millis();

//float ECG=SENSOR_PIN2;
Cayenne.virtualWrite(HEART_VIRTUAL_CHANNEL,analogRead(SENSOR_PIN2));
//Cayenne.virtualWrite(2, analogRead(SENSOR_PIN2), “analog_sensor”, “null”);
Cayenne.celsiusWrite(TEMPERATURE_VIRTUAL_CHANNEL,analogRead(SENSOR_PIN1)*5/1024.0-(-0.3)/0.01);
}
Cayenne.virtualWrite(3, accel.acceleration.x);
Cayenne.virtualWrite(4, accel.acceleration.y);
Cayenne.virtualWrite(5, accel.acceleration.z);

Also the data going over to cayenne from ECG only transmits every 20 seconds, just wondering is there a way to store the data until the cayenne gets the data. I tried working with eeprom but its complicated.


#2

first delete all the widget from the dashboard.
change the following line :

to

Cayenne.loop();
if (millis() - lastMillis > 10000) {
lastMillis = millis();
    Cayenne.virtualWrite(HEART_VIRTUAL_CHANNEL, analogRead(SENSOR_PIN2), "analog_sensor", "null");

    Cayenne.celsiusWrite(TEMPERATURE_VIRTUAL_CHANNEL,analogRead(SENSOR_PIN1)*5/1024.0-(-0.3)/0.01, "analog_sensor", "null");
//Cayenne.virtualWrite(TEMPERATURE_VIRTUAL_CHANNEL, analogRead(SENSOR_PIN1)*5/1024.0-(-0.3)/0.01, "temp", "c")

Cayenne.virtualWrite(3, accel.acceleration.x, "accel", "g");
Cayenne.virtualWrite(4, accel.acceleration.y, "accel", "g");
Cayenne.virtualWrite(5, accel.acceleration.z, "accel", "g");
}

once you upload the code. the dashboard will be populated with a temporary green color widget. click on “+” add them to your dashboard.
click on the setting “gear icon” and change the choose widget to line chart.

in your code if (millis() - lastMillis > 2000) this line used to send data every 2 sec which I have changed to 10 sec as the sending data more then the rate limit will cause interrupt in connection. also, you were sending the acceleration value continuously so I have placed it inside the if function. have a look at this Sending MQTT messages within rate limits

why you want to do this?


#3

Thanks for the quick reply

I done what you said and this is what i am getting in now.
I need it to look like this graph in the serial monitor image because it is what an ecg looks like but because it takes the values every 20 seconds the wave is just a random wave.


#4

sorry but the minimum time between every value is 10 sec,Sending MQTT messages within rate limits


#5

Is there any way to save the values and send them over every 10 seconds?


#6

wont it be the same case as your previous problem. u will get data on dashboard every 10sec.


#7

Yeah but inbetween the 10 seconds if there was a way to save it to flash or eeprom and then when the 10 seconds are up, cayenne gets all the values?


#8

I just played around with what you wanted and made this a rough code. not sure whether it will work. give it a try.

int myPins[10];

void loop() {
  Cayenne.loop();
  int i;
  for (i = 0; i < 10; i = i + 1) {
    myPins[i] = analogRead(SENSOR_PIN2);
  delay(100);
}
  if (millis() - lastMillis > 10000) {
    lastMillis = millis();
    for (i = 0; i < 10; i = i + 1) {
      Cayenne.virtualWrite(HEART_VIRTUAL_CHANNEL, myPins[i], "analog_sensor", "null");
      delay(100);
    }
  }
}