-4

I am working in C++ with the arduino and blue robotics sensor. I want to reformat the outputs into columns. For example:

MS5837 Pressure (mbar)     MS5837 Temperature (degC)    TSYS01 Temperature (degC)
        2                            6                            8  
        5                            6                            7  
        2                            3                            3  
        2                            8                            8         

This is what my code is and currently printing as

#include <Wire.h>
#include <MS5837.h>
#include <TSYS01.h>


MS5837 sensor;
TSYS01 tsys01;


void setup() {
  Wire.begin();


  // Initialize the MS5837 sensor
  if (!sensor.init()) {
    Serial.println("MS5837 sensor not found!");
    while (1);
  }
  sensor.setModel(MS5837::MS5837_30BA);
  sensor.setFluidDensity(1029);


  // Initialize the TSYS01 sensor
  if (!tsys01.init()) {
    Serial.println("TSYS01 sensor not found!");
    while (1);
  }


  Serial.begin(9600);
}



void loop() {
  // Read and display MS5837 sensor data
  sensor.read();
  Serial.print("MS5837 Pressure (mbar): ");
  Serial.print(sensor.pressure());
  Serial.print("MS5837 Temperature (degC): ");
  Serial.println(sensor.temperature());
  


  // Read and display TSYS01 sensor data
  float temperature = tsys01.temperature();
  sensor.read();
  Serial.print("TSYS01 Temperature (degC): ");
  Serial.println(sensor.temperature());
 


  delay(1000);
}
"MS5837 Pressure (mbar): 23
MS5837 Temperature (degC):5
TSYS01 Temperature (degC): 3.4"
PaulMcKenzie
  • 34,698
  • 4
  • 24
  • 45
Emma
  • 1
  • 1
  • Gather a full line of information put all of the information on the line , padding with appropriate whitespace to get nice columns, into a buffer in memory. Since Arduinio probably doesn't offer `std::format` yet, `sprintf` is probably your easiest path. One you've assembled the line, write it to the serial port. Repeat for next line. – user4581301 Aug 29 '23 at 22:21
  • 3
    Keep arduino (embedded code) as simple as it can be, just output data on your serial port. And then the receiver (of the data send on the serial port) format it. E.g. write your data comma separated save it to a .csv file client side (COM1 > file). And then view it in a spreadsheet. – Pepijn Kramer Aug 30 '23 at 03:59

0 Answers0