Adruino Serial Plotter

221,493

140

33

Introduction: Adruino Serial Plotter

About: I'm an Electronics Engineer who likes to make Doze Lamps, Lumen Powered Thingamajigs, Almighty Brainy Buttons, Tweeting Weather Stations and share them on Instructables.

The Arduino Serial Plotter function has been added to the Arduino IDE, allowing you to natively graph serial data from your Arduino to your computer in real time. If you’re tired of seeing your Arduino’s analog sensor input data pour onto your screen like The Matrix, this looks like a prettier way to visualize what’s going on. A Serial plotter is an offline tool allowing you too Visualize data and troubleshoot your code offline without having to use third-party services like Processing or Plotly. Since there is no official documentation on the Arduino website regarding the use & functionality of the Serial Plotter, I decided to documents its uses and features.

Features

  • Plotting of Multiple Graph
  • Offline
  • Auto-Resize Graph
  • Supports Negative Value graphs
  • Auto-scroll along X-axis
  • Different colors for each variable

Applications

  • Offline Data Visualization
  • Code Troubleshooting
  • Waveform Analysis

Parts Required

Arduino - AliExpress or
Arduino Starter Kit - AliExpress

Step 1: Plotting a Graph

Now that you have installed the latest version of the Arduino IDE(1.6.7 or above) its time to understand how the Serial Plotter actually works. The Arduino Serial Plotter takes incoming serial data values over the USB connection and is able to graph the data along the X/Y axis, beyond just seeing numbers being spit out on to the Serial Monitor. The vertical Y-axis auto adjusts itself as the value of the output increases or decreases, and the X-axis is a fixed 500 point axis with each tick of the axis equal to an executed Serial.println() command. In other words the plot is updated along the X-axis every time the Serial.println() is updated with a new value.

Remember to set the Baud Rate of the Serial Plotter so that it matches that of the code.

Multiple Plots

When displaying multiple waveforms, every separate variable/value/parameter is displayed using a different colour like shown below.

Inorder to plot multiple variables or waveforms simultaneously a 'space' is printed between the two print statements.

Serial.print(temperature);
Serial.print(" ");
Serial.println(humidity);

OR

Serial.print(temperature);
Serial.print("\t");
Serial.println(humidity); 

In this case the values of the variables 'temperature & humidity will have separate waveforms plotted on the same graph simultaneously.

Step 2: Offline Data Visulization

I used the Arduino Serial Monitor in my Automatic Plant Watering System to visualize & plot Moisture Sensor Data.

The main purpose of having the Serial plotter is that you do not need to be connected to the Internet in-order to visualize the data from a sensor or your project. And hence for the purpose of Data Visualization the Serial plotter excels at its job.

Whether its a singular wave or a multiple plot graph the Serial Plotter auto-resizes itself and color codes each wave. In-order to test the Data Visualization function you can follow the following steps:

  1. Connect a couple of sensors to your Arduino
  2. Print the values of the sensors & Upload the code.
  3. Open the Serial Plotter.

I have used the Serial Plotter in my Tweeting Weather Station to visualize the reading of the various sensors on the Weather Station. The above waveforms show the plot of the Temperature(26°C) & Humidity(65%RH) readings of the SL-HS-220 sensor.

Step 3: Troubleshooting

One of the best uses of the Serial Plotter is to troubleshoot the code & circuit. Faulty connections or incorrect coding logic can sometimes return an undesired output. In such cases where there too many lines of code or too many wires to debug the Serial Plotter can show the exact point of error.

With the help of the Serial Plotter you can check if a sensors reading is incorrect or even if the sensor is not connected properly to the Arduino. The Serial Plotter will also help debugging code by displaying the values various conditional statements and variables or even the states of the pins of the Arduino.

A good example of would be troubleshooting a Obstacle Avoidance Robot. In this example the Blue waveform represents the Ultrasonic sensor and the Yellow and Red waveforms represent the left and right motors. As the distance between the obstacle & the robot decreases, the Blue waveform decreases. At a threshold value(minimum distance) of 10, the robot turns right hence the two motors have different value's;Right=50,Left=100. You can see the Red waveform decreasing and the Yellow waveform remaining constant speed which represents the right turn.

Troubleshooting whether a wire was not connected properly or a component was malfunctioning or your coding logic was incorrect would have cost you a lot of time. But with the help of the Serial Plotter the amount of time it takes to troubleshoot the problem can be significantly reduced by analyzing the waveforms.

Step 4: Function Generation & Analysis

With a basic programming sense and a couple of lines of code, the Arduino is able to act as a Function Generator. The Arduino is capable of producing Square,Triangular, Sine & Sawtooth waveforms. In previous versions of the Arduino IDE one could only observe the values of the type of waveform being produced in the Serial Monitor without any visualization. It would be time consuming to analyze the output solely on the basis of numerical value's; and this is the place where the Serial Plotter comes handy; in visualizing the waveforms being produced.

Function Generator.inoFunction Generator.ino

Step 5: Future Improvement & Additions

The Arduino IDE has for long needed the addition of the Serial Plotter. It has increased the functionality of the Arduino IDE but still lacks some features:

  • Autoscroll Toggle
  • Simultaneous use of Serial Plotter & Serial Monitor.
  • X-axis Scale/Time scale required.

As these features are added to the Arduino IDE, I will continue to make changes and add new steps to this Instructable.

Digital Life 101 Challenge

Participated in the
Digital Life 101 Challenge

Raspberry Pi Contest 2016

Participated in the
Raspberry Pi Contest 2016

3 People Made This Project!

Recommendations

  • Unusual Uses Contest

    Unusual Uses Contest
  • Made with Math Contest

    Made with Math Contest
  • Laser Challenge

    Laser Challenge

33 Comments

0
Vabrinnta
Vabrinnta

4 years ago

First of all thank you for showing how to use the plotter function.

I have one question:

Is it somehow possible to plot the data and simultaneously save the data with i.g. CoolTerm? If I try to do it, the Arduino sketch will give me an error telling me that the monitor can´t be opened while the plotter is open.

Thanks in advance.

Best regards

Florian

0
Jonathanrjpereira
Jonathanrjpereira

Reply 4 years ago

I am not familiar with CoolTerm. But in my experience if something is sharing the same serial port as the serial monitor/plotter while they are open could result in a similar error.
It could also be that your serial monitor is already opened & hence the plotter cannot be opened simultaneously.

0
joerch
joerch

Tip 8 months ago

It is possible to add a description to the colors, if you just print the words in the setup routine.

Thank you for this instructable!
Best regards
Jörg

SeriellerPlotter.pngSeriellerPlotter_2.png
0
Prof-NoLife
Prof-NoLife

Reply 8 months ago

Thank you, this works great. Took me some moments to figure out what you meant exactly though ;)
For reference: The part you are looking for is line 11: Serial.println("Temperature Humidity");

0
MikeyMoMo
MikeyMoMo

Question 10 months ago on Step 5

As an additional feature, I would like to have a way to have the Serial Plotter ignore lines of data. Say, start it with "//" like a code comment line. This way, if you have debug print lines in your code, it will not throw the plotter off into space. Just start text lines with // then they will show on the Serial Monitor and not affect the Serial Plotter. So easy. Now, you have to put in a variable or expunge all of the prints in your code to switch. Then, to switch back, change again.

0
Prof-NoLife
Prof-NoLife

Answer 8 months ago

Well, for bigger projects you dont want to use the Arduino IDE but Platformio or similar. As a workaround you could wrap your debug prints into preprocessor directives and just enable them, if you really need.
Con: - you need to reupload your code to change it.
Pro: + if not enabled, your debug statements will be omitted while compiling thus save memory.
See the example I made for you.
Further informations could be found here: https://www.educba.com/preprocessor-directives-in-c/

Example_PreprocessorDirectives.JPG
0
NuttyProfessor47
NuttyProfessor47

Question 3 years ago on Introduction

Thank you very much for showing how the plotter can be used. I cannot believe it's been added to the Arduino IDE with no guidance at all on how to use it. Surely the author knows? Anyway can the waveform be "locked", or in oscilloscope parlance, synchronised? Or, is there a way to get fewer cycles displayed and expanded across the window? I need to examine the phase relationship between two waveforms, and can't when they are scrolling rapidly left.

0
MikeyMoMo
MikeyMoMo

Answer 10 months ago

Remember: Millennials DON'T document anything. Sad but true.

0
Jonathanrjpereira
Jonathanrjpereira

Answer 3 years ago

As of now, there is no way to disable AutoScroll on the Serial Plotter.

Assuming you have two physical input signals, an XOR gate can be used to calculate the phase difference.

Otherwise try taking a screenshot. (Start+PrintScreen).

0
Nurul HananiM
Nurul HananiM

3 years ago

Hi there ! can i know how to save the data or graph collected from the seriel monitor/plotter?

0
MikeyMoMo
MikeyMoMo

Reply 10 months ago

There are a couple of things you can do. If you want to "lock" the display and see it add from the last point rather than the end, just remember how many plots you have and code in 0 output lines for the difference of how many you have and 500. This fails, of course, after 500.

To expand the plot, double or triple up the output values. Do the same one mulitple times.. This will make a fatter curve.

0
Jonathanrjpereira
Jonathanrjpereira

Reply 3 years ago

I would employ one of these two methods:
1. Read the data onto a laptop/PC connected through the serial port & save that data into a CSV file. You can then plot that data using a simple Matplotlib script in Python.
2. Read & Save the data onto an SD card using an SD card module. You can then use the same python script to plot the CSV data.

I'm sure there are other methods too.

0
CaseyS2
CaseyS2

Question 2 years ago on Step 5

Is there a way to reverse this?

Such as I want to make a data plotter using a small screen or LED matrix be the display for the plotter?

I was curious if there is an easy way to do this or if you kind of have to code the visualization from scratch?

0
stevew17
stevew17

4 years ago

does anyone know where in the IDE does one adjust the Baud rate (I know how to set the baud rate in the code but I am referring to the serial plotter) ?? It shows a picture on one of the steps where it says your code and the serial plotter must be set at equal baud rates (and it shows a pic of the baud rate of 9600 and a scroll down) but it doesn't show how to actually adjust the baud rate on the serial plotter. I ASK this question because on several projects now I have been able to build and test many of these projects but could never get results plotted on the plotter.

0
Jonathanrjpereira
Jonathanrjpereira

Reply 3 years ago

In the images/gifs in steps 4 & 5, at the bottom left handside corner, there is a drop down menu to set the Baud Rate of the Serial Plotter.

0
paraklet
paraklet

4 years ago

are these graphs vs time?

can I get a table with the variables value?

0
Jonathanrjpereira
Jonathanrjpereira

Reply 3 years ago

Yes these graphs are Variable vs Time. Note: It doesn't use a RTC.

0
dasraiser
dasraiser

3 years ago

Hi, thank you for this, I've just started with the serial plot and just discovered you can

Serial.print(UpperLimit); //constant max X
Serial.print(" ");
Serial.print(LowerLimit);// constant min X
Serial.print(" ");
Serial.println(Value X);

this locks the graph and stops it from auto scaling :D

0
Jonathanrjpereira
Jonathanrjpereira

Reply 3 years ago

Cool. I may add this to the Instructable.

0
acboother
acboother

5 years ago

I agree about the lack of plotting facilities. I made this https://www.instructables.com/id/Arduino-Developmen...

over three years ago to address that issue plus add in a lot of other visualisers which can all be used simultaneously. Still freely available to those who contact me for the link.