MS5837 result is going crazy

Hello all,

I am using a MS5837 pressure sensor with the Arduino code modified to use with a Particle Electron. For some reason, the pressure readings are consistently drifting downwards by 2-6 every time it logs to the console. Having reached -5000, I am at a loss for a solution. The sensor is not floating, as I have a pull-up connected. My code is linked here: Particle Web IDE

Please help!

Can you please provide a picture of how you have everything connected?

Of course:

Is this picture at a bad angle? Everything above is soldered in. Thanks a bunch for the quick response.

Please capture the entire electronics. What is the name of this board?
Are you using a logic level shifter?

I see.

Also, can’t see the code without an account.

Ah, sorry. I’m new to posting on the forums. Ubidots is a program that allows you to track and plot data. Do you need the .h and .cpp files as well? They are basically the same as the ones Blue Robotics posted on GitHub but with D1 and D2 changed to P1 and P2.

#include "MS5837.h"
#include "Particle.h"

MS5837 sensor;

#include <Ubidots.h>
#define TOKEN "A1E-nKhZbeFhtLLp7VGOhbnK3WaXvCsaa8"
#define DATA_SOURCE_NAME "tessa-2-pressure"
Ubidots ubidots(TOKEN);

STARTUP(System.enableFeature(FEATURE_RETAINED_MEMORY));

PMIC pmic;

retained int twoDays;
int pressure;
int now;
retained int then;
int inches;
FuelGauge fuel;
int battery;

void setup() {
  
  Serial.begin(9600);
  
  ubidots.setDeviceLabel(DATA_SOURCE_NAME);
  
  Serial.println("Starting");
  
  Wire.begin();
  
  pinMode(D5, OUTPUT);
  digitalWrite(D5, HIGH);
  delay(500);

  // 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);
  }
  Serial.println("Sensor initiated succesfully");
  sensor.setModel(MS5837::MS5837_30BA);
  sensor.setFluidDensity(997); // kg/m^3 (freshwater, 1029 for seawater)
  
}

void loop() {

  twoDays += 1;
  // Update pressure and temperature readings
  sensor.read();
  pressure = sensor.pressure();
  inches = pressure*0.401865;
  battery = fuel.getSoC();
  
    if (battery == 90) {
        PMIC().disableCharging();
    } else {
        PMIC().enableCharging();
    }
    
    if (now >= then - 10) {
        if (twoDays == 24) {
            Serial.println(now);
            ubidots.add("water-level", now);
            twoDays = 0;
        }
    } else {
        then = now;
        twoDays = 0;
    }
      
  ubidots.add("battery-level", battery);
  ubidots.add("two-days", twoDays);
  
  Serial.print("Pressure: "); 
  Serial.print(pressure); 
  Serial.println(" mbar");
  
  Serial.print("Battery level: ");
  Serial.print(battery);
  Serial.println("% of capacity");
  
  Serial.print("Amount of water: ");
  Serial.print(inches);
  Serial.println(" square inches of water");
  
  Serial.print("Temperature: "); 
  Serial.print(sensor.temperature() * 9/5 + 32); 
  Serial.println(" deg F");
  Serial.println();
  Serial.println("---------------------------------------------------------------------------");
  Serial.println();
  
  ubidots.sendAll();
  
  System.sleep(SLEEP_MODE_DEEP,(10));  
  
  delay(1000);
}

Have you tried using a regular arduino with the avr microcontroller?

I don’t actually have an Arduino, this is my only option in the short term, which is what I need.

Sorry!

Do you have any fixes for a Particle Electron?

Anyone have a fix?

We’ve been hearing reports of similar issues with these sensors recently. Please contact support@bluerobotics.com so that we can arrange an exchange at no cost.