MS5837 pressure sensor library by BlueRobotics

Hi there. I’m looking to use a 7 Bar i2c MS5837-07BA pressure sensor with a 3.3V pro mini. I’ve found a library written by Blue Robotics (GitHub - bluerobotics/BlueRobotics_MS5837_Library: Arduino library for the MS5837 pressure sensor.), but it is only written for the 2Bar (MS5837-02BA) and 30Bar (MS5837-20BA) versions. I’ve new to this so if anyone can explain to me how this works I’d be very thankful. What would need to changed in the code to make it work for the different rated sensor?

Try this example, I edited line 28 to suit your sensor,
marked with "<<<<<<<<"

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

MS5837 sensor;

void setup() {

  Serial.begin(9600);

  Serial.println("Starting");

  Wire.begin();

  // Initialize pressure sensor
  // Returns true if initialization was successful
  // We can't continue with the rest of the program unless we can initialize the sensor
  while (!sensor.init()) {
    Serial.println("Init failed!");
    Serial.println("Are SDA/SCL connected correctly?");
    Serial.println("Blue Robotics Bar30: White=SDA, Green=SCL");
    Serial.println("\n\n\n");
    delay(5000);
  }

  // .init sets the sensor model for us but we can override it if required.
  // Uncomment the next line to force the sensor model to the MS5837_30BA.
  // sensor.setModel(MS5837::MS5837_30BA);
  sensor.setModel(MS5837::MS5837_07BA); // <<<<<<<<<<<<<

  sensor.setFluidDensity(997); // kg/m^3 (freshwater, 1029 for seawater)
}

void loop() {
  // Update pressure and temperature readings
  sensor.read();

  Serial.print("Pressure: ");
  Serial.print(sensor.pressure());
  Serial.println(" mbar");

  Serial.print("Temperature: ");
  Serial.print(sensor.temperature());
  Serial.println(" deg C");

  Serial.print("Depth: ");
  Serial.print(sensor.depth());
  Serial.println(" m");

  Serial.print("Altitude: ");
  Serial.print(sensor.altitude());
  Serial.println(" m above mean sea level");

  delay(1000);
}

Thanks, but I mean in the library code itself, it’s not been written for the 7bar version.

Ok, figured it out. The only difference I can see are in the compensation and calibration equations. Easy enough to change.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.