RobTillaart / MS5611

Arduino library for MS5611 temperature and pressure sensor
MIT License
18 stars 5 forks source link

A few questions about how the code works #39

Open brightproject opened 2 days ago

brightproject commented 2 days ago

Good afternoon @RobTillaart I run this code for two sensors

#include "MS5611.h"

MS5611 MS5611_1(0x76);
MS5611 MS5611_2(0x77);

uint32_t start1, stop1, start2, stop2, count;

void setup()
{
  Serial.begin(115200);
  while (!Serial);
  Serial.println();
  Serial.println(__FILE__);
  Serial.print("MS5611_LIB_VERSION: ");
  Serial.println(MS5611_LIB_VERSION);
  Serial.println();

  Wire.begin();
  if (MS5611_1.begin() == true)
  {
    Serial.println("MS5611_1 found.");
  }
  else
  {
    Serial.println("MS5611_1 not found. halt.");
    while (1);
  }
  if (MS5611_2.begin() == true)
  {
    Serial.println("MS5611_2 found.");
  }
  else
  {
    Serial.println("MS5611_2 not found. halt.");
    while (1);
  }
  count = 0;
}

void loop()
{
  delay(1000);

  // MS5611_1.setOversampling(OSR_LOW);
  MS5611_1.setOversampling(OSR_ULTRA_HIGH);
  start1 = micros();
  int result_1 = MS5611_1.read();   //  uses OSR_ULTRA_HIGH
  stop1 = micros();
  start2 = micros();
  int result_2 = MS5611_2.read();   //  uses default OSR_ULTRA_LOW  (fastest)
  stop2 = micros();

  if (count % 20 == 0)
  {
    Serial.println();
    Serial.println("CNT\tOSR1\tDUR1\tRES1\tTEMP1\tPRES1\tOSR2\tDUR2\tRES2\tTEMP2\tPRES2\tDIFF_T\tDIFF_P");
  }

  Serial.print(count);
  count++;
  Serial.print("\t");
  Serial.print( (uint8_t) MS5611_1.getOversampling());
  Serial.print("\t");
  Serial.print(stop1 - start1);
  Serial.print("\t");
  Serial.print(result_1);
  Serial.print("\t");
  Serial.print(MS5611_1.getTemperature(), 2);
  Serial.print("\t");
  Serial.print(MS5611_1.getPressure(), 2);
  Serial.print("\t");
  Serial.print( (uint8_t) MS5611_2.getOversampling());
  Serial.print("\t");
  Serial.print(stop2 - start2);
  Serial.print("\t");
  Serial.print(result_2);
  Serial.print("\t");
  Serial.print(MS5611_2.getTemperature(), 2);
  Serial.print("\t");
  Serial.print(MS5611_2.getPressure(), 2);
  Serial.print("\tT: ");
  Serial.print(MS5611_1.getTemperature() - MS5611_2.getTemperature(), 2);
  Serial.print("\tP: ");
  Serial.print(MS5611_1.getPressure() - MS5611_2.getPressure(), 2);
  Serial.println();
}

I get the following output in the serial port

src\main.cpp
MS5611_LIB_VERSION: 0.4.0

MS5611_1 found.
MS5611_2 found.

CNT     OSR1    DUR1    RES1    TEMP1   PRES1   OSR2    DUR2    RES2    TEMP2   PRES2   DIFF_T  DIFF_P
0       12      19763   0       28.26   1009.77 8       2760    0       28.11   1009.29 T: 0.15 P: 0.48
1       12      19763   0       28.26   1009.76 8       2760    0       28.11   1009.41 T: 0.15 P: 0.35
2       12      19763   0       28.27   1009.76 8       2760    0       28.13   1009.33 T: 0.14 P: 0.43

I have a simple interest in the values ​​in the columns RES1 and RES2. I also don't understand why different OSR's give approximately the same data from each sensor, although the resolution should be different. Previously worked with BMP280 sensors and when changing the OSR, the accuracy of the sensors changes. I will be glad to start a discussion with you🙂

(updated syntax highlighting)

RobTillaart commented 2 days ago

Thanks for your questions, Might take a few days to dive into it. R.

RobTillaart commented 2 days ago

With sensor 1 you should notice that the readings are the same in the 0.01 range while sensor two varies (roughly) 0.1 between measurements. Although the absolute difference looks small it still is a factor 10.

An experiment you could do is to "whistle" over the sensors so the get variation in air pressure. I expect you should see a bigger delta between the readings of both sensors.

What you should also notice is the difference in duration of the calls. The extra digit in accuracy takes about 6x as much time, so depending on your requirements you choose the oversampling level.

brightproject commented 2 days ago

Although the absolute difference looks small it still is a factor 10.

It seems to me that you are using incorrect discrediting of ADC sensors by entering ODR coefficients. You need to use the bits from the datasheet to set the sensor data sampling frequencies. I believe that ODR will be different for SPI and I2C.

RobTillaart commented 2 days ago

I recall the SPI version had problems with self heating effect.

Need to reread the datasheet in detail to understand what you mean exactly. Do you have a reference or proposal how to improve the code?

brightproject commented 2 days ago

Do you have a reference or proposal how to improve the code?

I'm making an air data computer device. I think there will be test parameters soon.

baro_sensor

5226480234772164764

RobTillaart commented 1 day ago

Nice box, looks pro, what's the application?

brightproject commented 1 day ago

Nice box, looks pro, what's the application?

Homemade sensor measuring differential gas pressure.

brightproject commented 1 hour ago

I still don't understand the library's output. Here's an example of the code

int result = MS5611.read();

It returns 0, what does this mean - no errors or how should I understand it?