Connecting Bar30 and Celsius to Arduino Mega

Hi, I am trying to program the Bar30 and Celsius to take measurements at
the same time on the Arduino Mega. I was wondering how to combine the
example library, TSYS01.h, and MS5837.h. I want the measurements to be
run at the same time or at least on the same code file. The error state: Compilation error: 'class TSYS01' has no member named 'begin'.

I tried combining code like this:

#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.begin()) {
    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: ");
  Serial.print(sensor.pressure());
  Serial.print(" mbar, Temperature: ");
  Serial.print(sensor.temperature());
  Serial.println(" degC");

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

  delay(1000);
}

Hi @treeocean, welcome to the forum :slight_smile:

The error is telling you that your tsys01 object has no begin method. If you look at our library example you’ll see that the correct method to perform the sensor initialisation is tsys01.init(), not tsys01.begin().

In that case I’d recommend taking the measurement readings as close together as possible, then printing the output(s) afterwards - e.g. change your structure to

void loop() {
    ... // Read MS5837 sensor data
    ... // Read TSYS01 sensor data

    ... // Print both sets of sensor data

    ... // delay to avoid too much output
}

I tried changing it to tsys01.init() and now the error is “Compilation error: could not convert ‘tsys01.TSYS01::init()’ from ‘void’ to ‘bool’”

#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: ");
  Serial.print(sensor.pressure());
  Serial.print(" mbar, Temperature: ");
  Serial.print(sensor.temperature());
  Serial.println(" degC");

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

  delay(1000);
}

Hi @treeocean,

In the 1.0.0 version of our BlueRobotics_TSYS01_Arduino library the TSYS01::init() function has no return value, so your if (!tsys01.init()) {...} block doesn’t make sense - it should instead just be an unchecked tsys01.init(); call.

Thanks for bringing this up though - we apparently recently made that function return a boolean but didn’t update the library version, so we’re doing that now. You should be able to update to version 1.0.1 in the next day or so, after which your current code should no longer be running into that compilation error :slight_smile:

I don’t see the version 1.0.1 of the tsys01 library.

Sorry about that, we updated the version number but forgot to make a new tag, so the Arduino package manager didn’t know to look for it. It’s fixed now, and I’ve confirmed that the 1.0.1 version shows up :slight_smile:

Thank you for updating the library! Do you know if there is a way to print the data into a table format? That will make it easier to analyze the data.

In your own program you can print the data however you want :slight_smile:

As an example (modifying your posted code), you might want to do something like

... // includes

void setup() {
    ... // sensor initialisation
    Serial.begin(9600)
    // Print the header for a CSV file
    Serial.println("MS5837 Pressure [mbar],MS5837 Temperature [degC],TSYS01 Temperature [degC]");
}

void loop() {
    // Read the data and print it comma-separated
    sensor.read()
    Serial.print(sensor.pressure());
    Serial.print(",");
    Serial.print(sensor.temperature());
    Serial.print(",");
    Serial.println(tsys01.readTemperature());

    delay(1000);
}

in which case you can copy the output into a CSV file and open it in your spreadsheet or processing application of choice :slight_smile: