Top community members
All Wiki Articles Create Wiki Article

Welcome to Dirask IT community! ❤ 💻
We are community of people that helps each other.

If you are beginner in IT field, you are more then welcome to ask questions, it will help you to learn faster. We are here to help you.

We are always beginner in something, we just need to remember it along the way.

there are no wrong questions - Ask Question

Arduino - draw charts by using Serial Plotter

0 contributions
13 points

Serial Plotter is a very useful feature of Arduino IDE for drawing linear charts. This post contains two examples that explain how to use it.

1. Simple example - zigzag line

A very simple example where variable y is increased from 0 to 10 by adding 1 in each iteration. If the value reaches 10, the y variable is back to 0.

Step 1. Write code below and upload a compiled program to Arduino (Sketch -> Upload).

Note: For single chart every value has to be printed in a new line (use: Serial.println() instead of Serial.print()).

int y = 0;

void setup() {
  // enable serial communication between Arduino and PC
  Serial.begin(9600);
}

void loop() {
  y += 1;
  if(y > 10) y = 0;
  
  Serial.println(y);

  // wait 10 ms
  delay(10);
}

Step 2. Open Serial Plotter (Tools -> Serial Plotter). In the new window you will see a similar chart:

Arduino Serial Plotter
Arduino Serial Plotter example.

2. Three charts example

There is a possibility to draw more than only one chart at the same time. The example code bellow drawing three charts: zigzag line (y1), straight line (y2) and sinus function (y3).

Note: For three charts, three values have to be printed in a single line. Values in line have to be separated by space or tab.

Step 1. Write code below and upload a compiled program to Arduino (Sketch -> Upload).

int y1 = 0, y2 = 15;
double x3 = 0.0, y3;

void setup() {
  // enable serial communication between Arduino and PC
  Serial.begin(9600);
}

void loop() {
  y1 += 1;
  if(y1 > 10) y1 = 0;

  y3 = sin(x3) -10.0;
  x3 += 0.1;

  Serial.print(y1); Serial.print("\t");
  Serial.print(y2); Serial.print("\t");
  Serial.println(y3);
  
  // wait 10 ms
  delay(10);
}

Step 2. Open Serial Plotter (Tools -> Serial Plotter). In the new window you will see a three charts:

Arduino Plotter example
Arduino Plotter for 3 charts example.

 

0 contributions

Checkout latest Findings & News:

Checkout latest questions:

Checkout latest wiki articles:

Hey 👋
Would you like to know what we do?
  • Dirask is IT community, where we share coding knowledge and help each other to solve coding problems.
  • We welcome everyone,
    no matter what the experience,
    no matter how basic the question is,
    this community will help you.
Read more