arduino / arduino-ide

Arduino IDE 2.x
https://www.arduino.cc/en/software
GNU Affero General Public License v3.0
2.29k stars 388 forks source link

Serial Plotter recovery from overload state #695

Closed per1234 closed 2 years ago

per1234 commented 2 years ago

Describe the current behavior

The Arduino IDE 2.x Serial Plotter has an undocumented maximum limit of 8 variables.

When this limit is exceeded, the plotter goes into an overload state (currently a blank window: https://github.com/arduino/arduino-ide/issues/651).

The only way to recover from that overload state is to close and then reopen the Serial Plotter window.

To reproduce

  1. Upload a sketch that causes more than 8 variables to be plotted:
    byte variableCount = 9;
    void setup() {
     Serial.begin(9600);
    }
    void loop() {
     for (byte variableCounter = 0; variableCounter < variableCount; variableCounter++) {
       Serial.print(random(100));
       Serial.print('\t');
     }
     Serial.println();
     delay(500);
    }
  2. Select Tools > Serial Plotter from the Arduino IDE windows. Notice that the plotter goes into the overload state.
  3. Upload a sketch that causes 8 or less variables to be plotted:
    byte variableCount = 8;
    void setup() {
     Serial.begin(9600);
    }
    void loop() {
     for (byte variableCounter = 0; variableCounter < variableCount; variableCounter++) {
       Serial.print(random(100));
       Serial.print('\t');
     }
     Serial.println();
     delay(500);
    }

    :bug: Notice that the Serial Plotter remains in the overload state, despite the data no longer exceeding its limitations.

  4. Close the Serial Plotter window.
  5. Select Tools > Serial Plotter from the Arduino IDE windows. Notice that the plotter is now plotting the data as expected 🙂

Describe the request

Recover from the overloaded Serial Plotter state once the over limit data conditions no longer exist.

Desktop

Additional context

I chose to use the example of the user correcting the overload by uploading a new sketch that produces 8 or less plotted variables, since I think that would be the most common occurrence (and perhaps the easiest to recover from since the upload could be used as a trigger for a recovery attempt). However, it is also possible for the number of variables to drop below the limit at sketch run time.

That seems unlikely to occur in practice, but I have noticed that sometimes there are spurious extra plotted variables when the Serial Plotter starts, which I believe is caused either by parsing of the data starting in the middle of a set or else by the initial data being corrupted, as sometimes happens with serial data printed immediately on initialization.

If the number of legitimate variables is already close to the limit, these spurious variables might push the count over the limit, which would result in a confusing situation for the user. That would be mitigated by the ability to recover on the fly.

Here is a contrived demo of the variable count dropping below the limit at run time:

byte variableCount = 9;  // The first set will exceed the maximum count of 8 variables
void setup() {
  Serial.begin(9600);
  while (!Serial) {}
  delay(1000);  // Without a delay, sometimes SP/SM doesn't receive the first of the data
}
void loop() {
  for (byte variableCounter = 0; variableCounter < variableCount; variableCounter++) {
    Serial.print(random(100));
    Serial.print('\t');
  }
  Serial.println();
  delay(500);
  variableCount = 8;  // Subsequent sets will contain 8 variables
}
per1234 commented 2 years ago

Fixed by https://github.com/arduino/arduino-serial-plotter-webapp/pull/5 This eliminates the issue entirely by plotting only up to the maximum number of variables, so there is never an overload state to recover from. Even though that PR has not yet been merged, the fix there was already published to the npm registry and brought into Arduino IDE by https://github.com/arduino/arduino-ide/pull/698