I am running into a situation with the MS5837 30 bar sensor where the depth, pressure, and temp does not seem to work. The pressure is always 0, the depth is always -33.99, and the temp is alway 20.
I have tried three different sensors (same model). Once I had the same issue. The other time I got wonky readouts.
This is the wiring:
The sensor is connected though I2C with a Sparkfun Mux board to allow other I2C connections from other sensors. VIN is 3.3V.
This is the code:
#include <Wire.h>
#include <SparkFun_I2C_Mux_Arduino_Library.h> //Click here to get the library: http://librarymanager/All#SparkFun_I2C_Mux
#include "MS5837.h"
#include <DFRobot_OxygenSensor.h>
#include <SparkFun_SCD4x_Arduino_Library.h>
#include <SparkFunBME280.h>
#define COLLECT_NUMBER 10
#define Oxygen_IICAddress ADDRESS_3
MS5837 sensor;
QWIICMUX myMux;
DFRobot_OxygenSensor oxygen;
SCD4x mySensorSCD;
BME280 mySensorBME;
const int OXYGEN = 2;
const int NITROGEN = 3;
const int BLEED = 4;
float water_level_pressure;
float uw_water_level_pressure;
void setup() {
Serial.begin(115200);
Serial.println();
Serial.println("Qwiic Mux Shield Read Example");
Wire.begin();
if (myMux.begin() == false)
{
Serial.println("Mux not detected. Freezing...");
while (1)
;
}
Serial.println("Mux detected");
// Initialize SCD4x sensor
while (!mySensorSCD.begin()) {
Serial.println("SCD4x sensor initialization failed.");
delay(1000);
}
while (!oxygen.begin(Oxygen_IICAddress)) {
Serial.println("Oxygen sensor initialization failed.");
delay(1000);
}
// Initialize BME280 sensor
while (!mySensorBME.beginI2C()) {
Serial.println("BME280 sensor initialization failed.");
delay(1000);
}
sensor.setModel(MS5837::MS5837_30BA);
sensor.setFluidDensity(997); // kg/m^3 (freshwater, 1029 for seawater)
pinMode(OXYGEN, OUTPUT);
pinMode(NITROGEN, OUTPUT);
pinMode(BLEED, OUTPUT);
// Initially turn off all relays
digitalWrite(OXYGEN, LOW);
digitalWrite(NITROGEN, LOW);
digitalWrite(BLEED, LOW);
delay(100); // wait for co2 levels to stabilize
water_level_pressure = mySensorBME.readFloatPressure() / 100.0; // Read circuit pressure and convert pressure to hPa
uw_water_level_pressure = sensor.pressure(); // mbar
uw_water_level_pressure = uw_water_level_pressure * 100; // convert to hPa
}
void loop()
{
myMux.setPort(0); // underwater sensor
sensor.read();
float uw_pressure = sensor.pressure(); // mbar
uw_pressure = uw_pressure * 100; // convert to hPa
float uw_temp = sensor.temperature(); // celsius
float uw_depth = sensor.depth(); // meters
uw_depth = uw_depth * 3.28084; // convert to feet
float o2 = oxygen.getOxygenData(COLLECT_NUMBER); // percent
int co2 = mySensorSCD.getCO2(); // ppm
float temp = mySensorBME.readTempC(); // celsius
float humidity = mySensorBME.readFloatHumidity(); // RH (percent)
float pressure = mySensorBME.readFloatPressure() / 100.0; // Read circuit pressure and convert pressure to hPa
float ata = pressure / water_level_pressure;
float uw_ata = uw_pressure / uw_water_level_pressure;
float ppo2 = (o2 / 100) * (pressure * 0.75006375541921); // pressure in mmhg
float ppco2 = (co2 / 1000000) * (pressure * 0.75006375541921); // pressure in mmhg
int bleed_time = 0;
int o2_time = 0;
int n2_time = 0;
Serial.print("UW pressure: ");
Serial.print(uw_pressure); // 0
Serial.print(",");
Serial.print("UW temp: ");
Serial.print(uw_temp); // 1
Serial.print(",");
Serial.print("UW depth: ");
Serial.print(uw_depth); // 2
Serial.print(",");
Serial.print("O2: ");
Serial.print(o2); // 3
Serial.print(",");
Serial.print("CO2: ");
Serial.print(co2); // 4
Serial.print(",");
Serial.print("Temp: ");
Serial.print(temp); // 5
Serial.print(",");
Serial.print("Humidity: ");
Serial.print(humidity); // 6
Serial.print(",");
Serial.print("Pressure: ");
Serial.print(pressure); // 7
Serial.print(",");
Serial.print("O2 time: ");
Serial.print(o2_time); // 8
Serial.print(",");
Serial.print("N2 time: ");
Serial.print(n2_time); // 9
Serial.print(",");
Serial.print("Bleed time: ");
Serial.print(bleed_time); // 10
Serial.print(",");
Serial.print("UW ata: ");
Serial.print(uw_ata); // 11
Serial.print(",");
Serial.print("ata: ");
Serial.print(ata); // 12
Serial.print(",");
Serial.print("PPO2: ");
Serial.print(ppo2); // 13
Serial.print(",");
Serial.print("PPCO2: ");
Serial.print(ppco2); // 14
Serial.print("\n\n");
delay(2500);
}
Readout over serial is:
UW pressure: 0.00,UW temp: 20.00,UW depth: -33.99,O2: 20.07,CO2: 527,Temp: 26.34,Humidity: 62.58,Pressure: 1001.22,O2 time: 0,N2 time: 0,Bleed time: 0,UW ata: nan,ata: 1.04,PPO2: 150.69,PPCO2: 0.00
My soldering skills suck, so maybe that’s the reason? Did I fry the sensor?