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.