How to Adjust X and Y Axis Scale in Arduino Serial Plotter (No Extra Software Needed)

By on September 27, 2024
Pin It

The Serial Plotter in Arduino is an excellent tool for quickly visualizing serial data. However, it has a limitation that can frustrate many users: it’s not immediately obvious how to adjust the X and Y axis scales, especially the X axis. In this article, I will guide you step by step on how to solve this issue without the need for additional software like Python or Processing.

Why Adjusting the Scale Is Important

In the latest version of the Arduino IDE (from version 2 onwards), the X-axis has a moving scale that only shows 50 data points, while the Y-axis is dynamic, adapting to the minimum and maximum values of the last 50 points. This can make data interpretation difficult, especially if you’re monitoring a stable signal such as a sine wave.
You can try this code to experience the visualization challenges:

float t; float y;
void setup() { Serial.begin(115200); }

void loop() { t = micros() / 1.0e6; y = sin(2PIt); Serial.println(y); }

Steps to Modify the Axis Scales

1. Stabilize the Y-Axis

To keep the Y-axis constant, you can add horizontal lines near the desired minimum and maximum values. Here’s how to do it:

  • Define Horizontal Lines in the Code: In your Arduino sketch, add the following lines to set Y-axis limits:
    Serial.print("1.1, "); Serial.print("-1.1, "); 

    This will keep the Y-axis constant between -1.1 and 1.1, making it easier to visualize the signal.

float t; float y;
void setup() { Serial.begin(115200); }

void loop() { t = micros() / 1.0e6; y = sin(2PIt); Serial.print("1.1, "); Serial.print("-1.1, "); Serial.println(y); }

2. Increase the X-Axis Scale

To modify the X-axis scale and display more than 50 data points, you need to edit a JavaScript file within the Arduino IDE. Here’s how to proceed:

a. Locate the JavaScript File

  1. Access the Program Files: Go to the folder where the Arduino IDE is installed.
  2. Navigate the Path: Follow this path: Resources > App > Lib > Backend > Resources > Arduino Serial Plotter Web App > Static > JS [C:\Program Files\Arduino IDE\resources\app\lib\backend\resources\arduino-serial-plotter-webapp\static\js].
    • If the path doesn’t match, search the IDE folder using the keyword “plotter”.

b. Edit the main.35ae02cb.chunk.js File

  1. Create a Backup Copy: Copy the file main.35ae02cb.chunk.js to the desktop for safety.
  2. Open the File in a Text Editor: Use an editor like WordPad or VS Code.
  3. Find the Line to Edit: Search for useState)(50).
  4. Modify the Value: Change 50 to the desired number of data points. For example, to increase it to 3000:
    useState(3000)
  5. Save and Overwrite the Original File: Save the changes and copy the modified file back to the original folder, replacing the existing file. You may need to grant the necessary permissions.

3. Verify the Changes

  • Reopen the Serial Plotter: After saving the changes, open the Arduino Serial Plotter again.
  • Check the New Scale: The X-axis should now display up to 3000 data points.

4. Be Aware of Limits

It’s important to note that there is a limit to the X-axis size, depending on the amount of data you’re sending. If you set a value too high, you might find that the plotter can’t display all the points. For example, setting the X-axis to 5000 may cause the plotter to stop between 3000 and 4000 points due to data overload.

Conclusion

Adjusting the axis scales in the Arduino Serial Plotter can significantly improve your data visualization experience. By following the steps outlined above, you can stabilize the Y-axis and increase the X-axis scale, making it easier to analyze your signals. If you prefer a more advanced solution, consider using Python for an even more customized visualization.
Happy working on your Arduino projects!

About Boris Landoni

Boris Landoni is the technical manager of Open-Electronics.org. Skilled in the GSM field, embraces the Open Source philosophy and its projects are available to the community.

Leave a Reply

Your email address will not be published. Required fields are marked *