How can I plot graph of 3 sensor value with Serial plotter

hi, I want to ask that How can I plot 3 sensor or more values graph using arduinos' new feature SERIAL PLOTTER? (last version) I can just plot 1 sensor value graph not more!! I spent many time to make graph on another programs so you have to learn another programs but this feature will be quite usefull for me and active graph users on arduino. I am waiting for your answers.

Thanks...
SERHAT BUYRUK

I am waiting for your answers.

Without posting your code, you're in for a long wait.

Paul What you mean "you are in for a long wait" so what should I do?
Thanks

so what should I do?

Didn't I make that clear enough? You are in for a long wait BECAUSE you didn't post any code.

Post your code if you want to shorten the wait.

It is possible to plot graph of a sensor value with that code;

int ldr = A1;
int ldrvalue = 0;
void setup(){
Serial.begin(9600);
pinMode(ldr,INPUT); }

void loop(){
ldrvalue = analogRead(ldr);
Serial.println(ldrvalue); }

but whenever I want to plot 3 sensors values graphs in code with the feature of SERIAL PLOTTER, it doesn't show me 3 graphs. WHY?

int ldr = A0;
int ldrvalue = 0;

int ldr1 = A1;
int ldrvalue1 = 0;

int ldr2 = A2;
int ldrvalue2 = 0;

void setup(){

Serial.begin(9600);
pinMode(ldr,INPUT);
pinMode(ldr1,INPUT);
pinMode(ldr2,INPUT); }
void loop(){

ldrvalue = analogRead(ldr);
Serial.print(ldrvalue);

ldrvalue1 = analogRead(ldr1);
Serial.print(ldrvalue1);

ldrvalue2 = analogRead(ldr2);
Serial.println(ldrvalue2);}

 ldrvalue = analogRead(ldr);
  Serial.print(ldrvalue);
 
  ldrvalue1 = analogRead(ldr1);
  Serial.print(ldrvalue1);
 
  ldrvalue2 = analogRead(ldr2);
  Serial.println(ldrvalue2);}

Lets suppose that the values read from the pins are 123, 347, and 45. What you are sending, using this code, is "12334745". How it the receiving end supposed to know how to parse that, and make sense of it?

Now, suppose that you sent "123,34,745" instead. Would the answer be any different?

As far as I know the Serial plotter only supports one channel at the moment.
There is a discussion how to support multiple channels in the future (no link at hand)

disclaimer: I still need to check this new feature

#7 below shows the best way to post code in the discussion:

http://forum.arduino.cc/index.php/topic,148850.0.html

Dear friends, so it means I will try to come over my problem with another programs. That's terrible for me because I have learned only arduino programming. It is too hard to plot graph via another programs(Proccesing, Phyton e.g.) by the way I sometimes use sda and scl communication sensors It makes me very tired :frowning: If you learn and hear someting about this subject, You can share here!

Thanks for your helps...
SERHAT BUYRUK

The easiest way to plot a graph is to export a csv (comma separated values) string to the PC.

capture this and write to file,

open with Excel or open office or so.

make a graph in Excel

drawback, not real time

For realTime with excel google PLX-DAQ

You can use RealTerm to capture and save data then import it into Excel.
Other serial monitors can do the same.

http://realterm.sourceforge.net/

I hate seeing something not quite answered - here's some sample code; no idea if it compiles or works, but it should give the idea of the matter:

================================================================================
Arduino code - UNTESTED
================================================================================

void setup() {
  Serial.begin(9600);
}

void loop() {
  int ldrvalue0 = analogRead(A0);
  delay(2);
  int ldrvalue1 = analogRead(A1);
  delay(2);
  int ldrvalue2 = analogRead(A2);
  
  Serial.print(ldrvalue0);
  Serial.print(",");
  Serial.print(ldrvalue1);
  Serial.print(",");
  Serial.println(ldrvalue2);}
}

================================================================================
Processing code - UNTESTED
================================================================================

import processing.serial.*;

Serial myPort;        // The serial port

int xPos = 1;         // horizontal position of the graph

int height0 = 0;
int height1 = 0;
int height2 = 0;

int width = 400;

void setup () {
	// set the window size:
	size(width, 300);

	// List all the available serial ports
	// if using Processing 2.1 or later, use Serial.printArray()
	println(Serial.list());

	// I know that the first port in the serial list on my mac
	// is always my  Arduino, so I open Serial.list()[0].
	// Open whatever port is the one you're using.
	myPort = new Serial(this, Serial.list()[0], 9600);

	// don't generate a serialEvent() unless you get a newline character:
	myPort.bufferUntil('\n');

	// set inital background:
	background(0);
 }
 
 void draw () {
	// everything happens in the serialEvent()
 }

 void serialEvent (Serial myPort) {
	// get the ASCII string:
	String inString = myPort.readStringUntil('\n');

	if (inString != null) {
		// trim off any whitespace:
		inString = trim(inString);
		
		// split up by the separator
		String[] v = splitTokens(inString, ",");
		
		// convert to an int and map to the screen height:
		float inByte0 = float(v[0]);
		float inByte1 = float(v[1]);
		float inByte2 = float(v[2]);
		
		inByte0 = map(inByte0, 0, 1023, 0, height0);
		inByte1 = map(inByte1, 0, 1023, 0, height1);
		inByte2 = map(inByte2, 0, 1023, 0, height2);

		// draw the lines (overlapping each other):
		stroke(0, 0, 255); // blue
		line(xPos, height0, xPos, height0 - inByte0);

		stroke(0, 255, 0); // green
		line(xPos, height1, xPos, height1 - inByte1);

		stroke(255, 0, 0); // red
		line(xPos, height2, xPos, height2 - inByte2);

		// at the edge of the screen, go back to the beginning:
		if (xPos >= width) {
			xPos = 0;
			background(0);
		}
		else {
			// increment the horizontal position:
			xPos++;
		}
	}
 }

Note that one part is for the Arduino, the other is for Processing (running on the PC). This code is basically a "mash-up" from the following places:

...plus a bit of other various online consulting via google. I don't know much about Processing, and I have never used it, but it seems straightforward enough. Hopefully, this bit of code will help someone, or at least spur people on in this thread to refine and correct any mistakes I have probably made.

Cheers! :smiley:

robtillaart:
There is a discussion how to support multiple channels in the future (no link at hand)

Here's the discussion: Serial Plotter: Suggested framework for future enhancements - Suggestions for the Arduino Project - Arduino Forum
Here's the pull request: Added functionality to plot multiple signals at the same time by henningpohl · Pull Request #4022 · arduino/Arduino · GitHub

That will create an interesting graph, mapping everything to the range 0 to 0...

@PaulS - who are you responding to? What @pert wrote, or my code? If you posting about my code, note that I did say it was completely untested code (but if so - can you point out the line(s) that are problematic - or post a correction?)...

:slight_smile:

I wrote this app to graph multiple values from an Ardunio Uno.

The Arduino sends data with something like:

String name = "sensor1";
int value = 144;
Serial.println("%s:%d", name, value);

The previously mentioned pull request was merged and the Arduino IDE Serial Plotter now supports multiple values.

The Arduino serial plotter is a great addition to the IDE. Prior to this feature, I created a real-time plotting library and client that you may find useful.

The main advantages over Arduino serial plotter are:

  • Simultaneous transmission of data and Textual data.
  • Multiple plot windows
  • Recording and saving data to CSV.

Heres some more information if interested: Arduino AdvancedSerial - Real-Time data plotting and recording - Interfacing w/ Software on the Computer - Arduino Forum

I've been following this discussion and playing with my Arduino serial plotter using the syntax described. It is my impression that rather than stacking multiple channels one under the other, the commands required actually plot multiple lines of overlapping data. That would be expected as print rather than println is used for all but the last channel. My question then: How might one get greater separation between multiple chanels on the serial plotter?