Page 1 of 1

Multiple values with same time stamp in time plot

Posted: Thu Feb 18, 2021 9:28 am
by TuigWerk
Hi there,

I have been looking for the cause of this issue for a couple of hours now and I can't figure out how to improve the smoothness of my time plot in Megunolink. I hope someone can help me with this..
As you can see in the attached screenshots, the time plot of Megunolink is stepped, whereas the Arduino serial plotter shown a smooth signal. This is done with the same sketch and sensors.
The weird thing is that this jaggedness of the Megunolink does not seem constant. Sometimes its worse, sometimes better.

Does anyone know what the issue could be?

Cheers, Tjeerd

Re: Megunolink time plot is jagged, but Arduino serial plotter is smooth

Posted: Fri Feb 19, 2021 1:09 pm
by TuigWerk
The problem seems that the time plot displays multiple values with the same timestamp, then about 15 ms later does the same thing, but I still don't know why.
I stripped down my code, and tried adding a delay, but it still gives me the same issue and it seems that the resolution of the time axis is not sufficient.
Hopefully it is just a setting that I have overlooked. I hope someone can help, because it is really annoying small, but critical issue.

Best Regards, Tjeerd

Code: Select all

 const int xpin1 = A0; // x-axis of the accelerometer 1

#include "MegunoLink.h"
#include "CommandHandler.h"

TimePlot Acc1 ("Acc1");

CommandHandler<> Commands;
InterfacePanel AccPanel;


void setup() {

  Serial.begin(115200);

}


void loop() {
  Commands.Process();
  int x1raw = analogRead(xpin1);

  float x1g = map(x1raw, 410, 613, -100, 100) * 0.01; //Mapping with raw values

  Acc1.SendData(F("Acc1"), x1g);

}


Re: Multiple values with same time stamp in time plot

Posted: Fri Feb 26, 2021 6:02 am
by philr
The issue is one of processing jitter. Windows computers are typically allocates slices in time to process data. Because you are sending data at full speed multiple messages are arriving at the computer and are being processed in quick succession. Because the timestamp is being generated in the computer this leads to jagged plots. 

If you switch to generating your own timestamp (easiest is using the xyplot and millisecond counter rather than having to keep time) your plot should be nice and smooth. How fast do you need data? You could adjust it to send data every 50ms or so which will probably solve your problem as well.

Here is one method for syncing time to your device if you still need absolute time.
https://www.megunolink.com/documentatio ... egunolink/

Re: Multiple values with same time stamp in time plot

Posted: Sun Mar 07, 2021 11:43 am
by TuigWerk
Hi Phil,

thanks a lot for your suggestion!
Using a XY plot not only solved the jagged display caused by using the pc time, but also made it possible to display the standing sine wave by using a trigger to reset the time.
I have posted my solution in this thread: https://megunolink.com/discussion/viewt ... f=5&t=1516.

Cheers, Tjeerd

Re: Multiple values with same time stamp in time plot

Posted: Thu Mar 11, 2021 6:13 am
by philr
Nice, great work!