How to Adjust the Width of the Serial Plotter Window


The Serial Plotter is a great feature introduced with ARDUINO 1.6.6 in 03.11.2015.
In most cases, the autoscaling works pretty well. Actually, there are situations where the Moiré effect will occur.
The Serial Plotter always shows the last 500 values that have been sent. With some patterns you will see strange pictures like this:

or this:

The patterns shown in these windows obviously are artefacts and can be avoided by setting the proper width to the Plotter window.

But how can you adjust the width as desired?

Still incorrect:

And now the correct window width:

With these few lines of code you can produce such a pattern which makes it easy to adjust the proper width of the plotter window:

void setup() {
  Serial.begin(9600);
  int a1 =  1;
  int a2 = 11;
  int b1 = 13;
  int b2 = 23;
  for (int i = 0; i < 500; i++) {
    int a, b;
    if (i % 2 == 0) a = a1; else a = a2;
    if (i/2 % 2 == 0) b = b1; else b = b2;
    Serial.print(a);
    Serial.print("\t");
    Serial.println(b);
  }
}

void loop() {}

Once you have adjusted it you can use the sketch you are currently working with and get the result you wanted to see.

Of course, if width of your monitor supports it you can increase the x-axis by multiplying it by 2 or 3 ...

Now, stop: all of this is only true as long as the values on the y-axis do not exceed 99 as the length of the x-axis is affected by the number of digits printed on the left of the y-axis. So, in case your application produces higher values you have to adapt the b2-values in my sketch.




contact: nji(at)gmx.de