plotting multiple graphs in Arduino Serial Plotter

Hi,

I am doing a project with the Arduino Uno in which I am trying to plot the values of 5 sensors in multiple graphs (real time). I have tried the Serial Plotter of Arduino, but when I use that one, I just get a singular graph line. Because I am using also the BMP280 sensor as a pressure sensor, the y-axis of the graph is way to high, with the consequence that the graph looks quite ridiculous.
So my question is, if it is possible to plot multiple graphs with the Arduino Serial Plotter.

This is the code I use:

#include <SoftwareSerial.h>
#include <HMC5883L.h>
#include <Wire.h>
#include <Adafruit_Sensor.h>
#include <Adafruit_HMC5883_U.h>
#include <SPI.h>
#include <SD.h>
#include <Adafruit_BMP280.h>

File SDsaver;
int chipSelect=4;

int sensorPin = A1; // select the input pin for LDR
int sensorValue = 0; // variable to store the value coming from the sensor

Adafruit_HMC5883_Unified mag = Adafruit_HMC5883_Unified(12345);

//bmp280 pins
#define BMP_SCK 6
#define BMP_MISO 7
#define BMP_MOSI 5
#define BMP_CS 4

Adafruit_BMP280 bmp(BMP_CS, BMP_MOSI, BMP_MISO,  BMP_SCK); //spi software library

void setup() {
Serial.begin(9600); //sets serial port for communication
Serial.begin(9600);
Serial.begin(9600);
SD.begin(chipSelect);

  Serial.println("HMC5883 Magnetometer Test"); Serial.println("");
  
  /* Initialise the sensor */
  if(!mag.begin())
  {
    /* There was a problem detecting the HMC5883 ... check your connections */
    Serial.println("Ooops, no HMC5883 detected ... Check your wiring!");
    while(1);
  }
  
Serial.begin(9600);
Serial.println(F("BMP280 test"));
  
  if (!bmp.begin()) {  
    Serial.println(F("Could not find a valid BMP280 sensor, check wiring!"));
    while (1);  
}
}


void loop() {

SDsaver=SD.open("PTDATA.txt" , FILE_WRITE);
sensorValue = analogRead(sensorPin); 
Serial.println(sensorValue); 
delay(150);



  sensors_event_t event; 
  mag.getEvent(&event);
 
  /* Display the results (magnetic vector values are in micro-Tesla (uT)) */
  Serial.print("X: "); Serial.print(event.magnetic.x); Serial.print("  ");
  Serial.print("Y: "); Serial.print(event.magnetic.y); Serial.print("  ");
  Serial.print("Z: "); Serial.print(event.magnetic.z); Serial.print("  ");Serial.println("uT");

 
  float heading = atan2(event.magnetic.y, event.magnetic.x);
  
  
  float declinationAngle = 0.0;
  heading += declinationAngle;
  
 
  if(heading < 0)
    heading += 2*PI;
    
  if(heading > 2*PI)
    heading -= 2*PI;
   
  
  float headingDegrees = heading * 180/M_PI; 
  
  Serial.print("Heading (degrees): "); Serial.println(headingDegrees);
  
  delay(150);


  float sensorVoltage; 
  float sensorValue;
 
  sensorValue = analogRead(A0);
  sensorVoltage = sensorValue/1024*3.3;
  Serial.print("sensor reading = ");
  Serial.print(sensorValue);
  Serial.println("");
  Serial.print("sensor voltage = ");
  Serial.print(sensorVoltage);
  Serial.println(" V");
  delay(150);


 Serial.print(F("Temperature = "));
 Serial.print(bmp.readTemperature());
 Serial.println(" *C");
    
 Serial.print(F("Pressure = "));
 Serial.print(bmp.readPressure());
 Serial.println(" Pa");

 Serial.print(F("Approx altitude = "));
 Serial.print(bmp.readAltitude(1000.25)); 
 Serial.println(" m");
    
 Serial.println();
 delay(150);

if(SDsaver) {
SDsaver.print(event.magnetic.x);
SDsaver.print(" , ");
SDsaver.print(event.magnetic.y); 
SDsaver.print(" , ");
SDsaver.print(event.magnetic.z); 
SDsaver.print(" , ");
SDsaver.println("uT"); 
SDsaver.println(headingDegrees);
SDsaver.println(sensorValue);
SDsaver.print(sensorVoltage);
SDsaver.print(" , ");
SDsaver.println(sensorVoltage);
SDsaver.print(bmp.readTemperature());
SDsaver.print(" , ");
SDsaver.print(bmp.readPressure());
SDsaver.print(" , ");
SDsaver.println(bmp.readAltitude(1013.25));
SDsaver.close();
  
}
}

PS: the values are also being written onto a micro Sd-Card.

Cheers.

Hi,
So from what I can gather;
You have a number of variables you want to plot.
Because one is very large compared with the rest, and the Monitor Plot auto scales to the largest value the others appear as very low virtually straight lines.

You need to scale up the lower variables, but only in the Serial.print statement

So if you have;

Serial.print(VeryBigVar); \\  say between 0 and 1000
Serial.print(SmallVar1);  \\ say 0 to 10
Serial.print(SmallVar2);  \\ say 0 to 50

Then ;

Serial.print(VeryBigVar); \\  say between 0 and 1000
Serial.print(SmallVar1*10);  \\ say 0 to 10 will display as 0 to 100
Serial.print(SmallVar2*10);  \\ say 0 to 50 will display as 0 to 500

You just have to note that the two smaller values are displayed at 10 times their real value.
You will see some straight line between points as you are expanding the variable points by a factor of 10.

By putting the scale factor in the Serial.print, you do not change the value of the variables within your code.

I hope this helps.

Tom.. :slight_smile:

You need to spend some time learning the basics of how the Serial Plotter works. Run some basic sketches and then check the results. For example:

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

void loop() {
  Serial.print("X: "); Serial.print(1); Serial.print("  ");
  Serial.print("Y: "); Serial.print(2); Serial.print("  ");
  Serial.print("Z: "); Serial.print(3); Serial.print("  ");
  Serial.println("uT");
}

As expected, this generates a flat line at 1, 2, and 3 on the the y axis:

Clipboard01.png

But the Serial Plotter reads everything you print and your sketch prints a bunch of other stuff. For example this line:

Serial.println(sensorValue);

So let's do a simple test of what that does to our pretty graph by running this code:

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

void loop() {
  Serial.println(6);

  Serial.print("X: "); Serial.print(1); Serial.print("  ");
  Serial.print("Y: "); Serial.print(2); Serial.print("  ");
  Serial.print("Z: "); Serial.print(3); Serial.print("  ");
  Serial.println("uT");
}

Clipboard02.png

Do you see the problem?

Shouln't it be:

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

void loop() {
  Serial.println("F"); Serial.print(6); Serial.print(" ");

  Serial.print("X: "); Serial.print(1); Serial.print("  ");
  Serial.print("Y: "); Serial.print(2); Serial.print("  ");
  Serial.print("Z: "); Serial.print(3); Serial.print("  ");
  Serial.println("uT");
}