Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added functionality to plot multiple signals at the same time #4022

Merged
merged 2 commits into from
Nov 18, 2015

Conversation

henningpohl
Copy link
Contributor

Instead of plotting only one value, the SerialPlotter with this change can plot any number of values at the same time. The color cycle used for this is specified in theme.txt and can be easily changed to enable custom colors for plots with many values (though that might not look very good or be very usable). This is a feature requested by @q2dg in #2177 and #3451. I tested this on one machine, so it would be great if others can try this a bit. There can sometimes be hickups on startup when malformed strings arrive on the Serial port (incomplete lines).

@cmaglie cmaglie added the Component: IDE user interface The Arduino IDE's user interface label Oct 23, 2015
@ffissore
Copy link
Contributor

Thank you @henningpohl. I would ask you a modification: instead of hardcoding colours in theme.txt, how about specifying them in the sketch? Syntax would then become something like

// one line
Serial.println("3 FF0000, 5 00FF00, 7 0000FF");

// wrapped in a function
void printSensorReadings() {
    Serial.print(sensorOneReading);
    Serial.print(" FF0000,");
    Serial.print(sensorTwoReading);
    Serial.print(" 00FF00,");
    Serial.print(sensorThreeReading);
    Serial.print(" 0000FF");
    Serial.println();
}

This makes using the plotter easier as user has full control on which and how many colours to use. It would be even better if colours were optional: when missing, use default colour

@NicoHood
Copy link
Contributor

This way you could also display multiple channels. Which I would really like for my music visualization debugging.

@q2dg
Copy link

q2dg commented Oct 28, 2015

But if we wanted to use "Serial Monitor" instead "Serial Plotter", data would be shown a bit (I don't know how to say it) verbose/recharged/cluttered, wouldn't?

@ffissore
Copy link
Contributor

The alternative is to locate an almost hidden file in IDE installation folder, being sure user can edit it (on windows it may not be possible, especially in schools/colleges), restart the ide and reopen the serial plotter
I much prefer a cluttered output if that's the price of flexibility. And I can deal with that in sketch code, like having:

#define PLOTTER 1
#if PLOTTER == 1
void printSensorReadings() {
    Serial.print(sensorOneReading);
    Serial.print(" FF0000,");
    Serial.print(sensorTwoReading);
    Serial.print(" 00FF00,");
    Serial.print(sensorThreeReading);
    Serial.print(" 0000FF");
    Serial.println();
}
#else
void printSensorReadings() {
    Serial.print(sensorOneReading);
    Serial.print(",");
    Serial.print(sensorTwoReading);
    Serial.print(",");
    Serial.print(sensorThreeReading);
    Serial.println();
}
#endif

@henningpohl
Copy link
Contributor Author

Hmm... my personal take is that I would avoid putting any command codes into the serial stream from the Arduino. Several reasons:

  • It would roughly double the number of bytes to send
  • I fear this is a bit of a slippery slope: would we, e.g., also want to configure line width that way? With multiple settings to be changed, there would need to be a command mode and a data mode, maybe dedicated tokens to switch modes, ...
  • It would clutter the output when looking at it in text mode
  • Sending this every frame is redundant. Also: would we like colors to change mid-plotting?
  • It couples IDE and sketch together with the Arduino running code intended for the IDE. With much more power on the IDE side of things, shouldn't the Arduino part stay as basic as possible?

I think a nicer way to allow changing this in a sketch would be to have annotations in a sketch to be extracted by the IDE, but not compiled into the program to run on the Arduino. In a way this is similar to issues arduino/arduino-ide#2438 and #3228: we'd like the IDE to pick up on settings related to a specific sketch. One way to do this would be to abuse #pragmas. For example, the header of a sketch could read something like:

    #pragma comment(board, "Arduino Nano")
    #pragma comment(port, "COM4")
    #pragma comment(plotcolors, "#FF0000,#00FF00,#0000FF")

@NicoHood
Copy link
Contributor

@henningpohl is right. Speed matter much and if I think (especially) on mz music visualization, I need this time. In any case his solution makes more sense. Or just have no different colors, then it is like that. Thats the limitation.

@damellis
Copy link
Contributor

I'll chime in to say that I also think it's a bad idea to specify the colors in the serial data itself. For instance, someone may want to switch back and forth between plotting the data and sending it to an application; having the colors in the serial stream will confuse / complicate that other application. Anyway, this is just a debugging visualization, not a final / end-user interface, so I don't think we need to provide that kind of customization.

@damellis
Copy link
Contributor

Also, can we split on tabs as well as spaces (if this doesn't already do so)? I use them in my code and I've definitely seen others do the same.

@ffissore ffissore added this to the Release 1.6.7 milestone Nov 4, 2015
@agdl
Copy link
Member

agdl commented Nov 17, 2015

If I can say what I think, the feature is really cool!!! I can agree about the fact that printing the color in the Serial monitor can be confusing for the datas, but however I think that putting some label is better. If i write some data on the serial monitor I always print variableName: variableValue. In this way you cannot understand one thing for another. You can use something like:

Serial.print("i:");
Serial.print(i);
Serial.print(" ");
Serial.print("j:");
Serial.println(j);

To have a legend in the serial monitor.

If you don't put anything you don't have the legend.

What do you think about this?

@agdl
Copy link
Member

agdl commented Nov 18, 2015

Sorry for the wrong reference, a mistake in the copy and paste

@ffissore
Copy link
Contributor

@agdl what about opening a separate issue for this improvement request?

@ffissore
Copy link
Contributor

If you agree, we can merge this PR and discuss how to further improve the plotter in a dedicate issue

@per1234
Copy link
Collaborator

per1234 commented Nov 18, 2015

Would it be possible to ask @ArduinoBot to build this so I can try it out? There was some discussion of this on the Arduino forum. The suggestion we came up with is demonstrated in this sketch: http://forum.arduino.cc/index.php?topic=357788.msg2468220#msg2468220.

@ffissore
Copy link
Contributor

@ArduinoBot build this please

@ffissore
Copy link
Contributor

@henningpohl I'm going to merge this PR (and thank you again). As you see, it's gaining much interest from the community. Should any of the proposed new features make sense to you, feel free to propose code or sponsor an open issue

ffissore added a commit that referenced this pull request Nov 18, 2015
Added functionality to plot multiple signals at the same time
@ffissore ffissore merged commit 846b821 into arduino:master Nov 18, 2015
@agdl agdl mentioned this pull request Nov 18, 2015
@per1234 per1234 added the SerialPlotter Tools > Serial Plotter label Apr 5, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Component: IDE user interface The Arduino IDE's user interface SerialPlotter Tools > Serial Plotter
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants