ESP32 - Serial Plotter
We are going to learn how to:
-
How to use Serial Plotter with ESP32.
Video Tutorial
you can watch this video tutorial
Hardware Required
1 | × | ESP-WROOM-32 Dev Module | |
1 | × | Micro USB Cable |
How To Open Serial Plotter
On Arduino IDE, Go to Tools >> Serial Plotter
Plotting of Single Line in Graph
To print a single graph, we just need to send the data and terminate it by “\r\n” character.
In detail, we just need to use Serial.println() function
Serial.println(variable);
※ NOTE THAT:
Serial.println() automatically appends “\r\n” characters after data.
Example Code
In this example, we will send the “esp32io.com” from ESP32 to Serial Monitor every second
void setup() { Serial.begin(9600); } void loop() { int y1 = analogRead(2); Serial.println(y1); delay(100); }
Quick Steps
- power up your board
- Open Arduino IDE
- Select the right board
- Select the right port
- Copy the above code and open with Arduino IDE
- Click Upload button on Arduino IDE to upload code to ESP32
- Open Serial Plotter on Arduino IDE
- Select baurate 9600
- See graph on Serial Plotter
Plotting of Multiple Lines in Graph
When we want to plot multiple variables, we need to separate variables from each other by “\t” or " " character. The last value MUST be terminated by “\r\n” characters.
In detail:
-
The first variable
Serial.print(variable_first); -
The middle variables
Serial.print("\t"); // or Serial.print(" ") Serial.println(variable_last); -
The last variable
Serial.print("\t"); // or Serial.print(" ") Serial.print("\t"); // or Serial.print(" ")
Example Code
This example reads the value from 4 analog input pins and plots them on Serial Plotter
Multiple Graph:
void setup() { Serial.begin(9600); } void loop() { int y1 = analogRead(2); int y2 = analogRead(4); int y3 = analogRead(5); int y4 = analogRead(18); Serial.print(y1); Serial.print(" "); // a space ' ' or tab '\t' character is printed between the two values. Serial.print(y2); Serial.print('\t'); // a space ' ' or tab '\t' character is printed between the two values. Serial.print(y3); Serial.print(" "); // a space ' ' or tab '\t' character is printed between the two values. Serial.println(y4); // the last value is followed by a carriage return and a newline characters. delay(100); }
Example of 3 Sine Waveforms
Multiple Sine Waveform Graph:
void setup() { Serial.begin(9600); } void loop() { for(int i = 0; i < 360; i += 5) { float y1 = 1 * sin(i * M_PI / 180); float y2 = 2 * sin((i + 90)* M_PI / 180); float y3 = 5 * sin((i + 180)* M_PI / 180); Serial.print(y1); Serial.print("\t"); // a space ' ' or tab '\t' character is printed between the two values. Serial.print(y2); Serial.print("\t"); // a space ' ' or tab '\t' character is printed between the two values. Serial.println(y3); // the last value is followed by a carriage return and a newline characters. delay(100); } }
Book Tutorial
We are considering to make the book tutorials. If you think the book tutorials are essential, you can download it. download book
See Also
References
※ NOTE THAT:
Some components works on 3.3v and others works on 5v!