Forum Rule: Always post complete source code & details to reproduce any issue!
Page 2 of 2 FirstFirst 1 2
Results 26 to 47 of 47

Thread: i2c Pressure Sensor Reading Help?

  1. #26
    Quote Originally Posted by el_supremo View Post
    Where did you get this from? This is completely wrong and is why you were seeing temperatures in the region of 26000 instead of 20.
    The original code that I have is:
    Code:
    int64_t dT = raw[1] - (((int64_t)T_REF) << Q5);
    and this gives the correct results.

    I've done some testing of the original code with the raw numbers and PROM values that you've posted and they produce reasonable values. Therefore, the code is correct as it is.
    If you've changed the calculations, I suggest that you go back to the original code.

    Pete
    But using the correct version you just said some of my other sensors don't give the same values. One of my sensors is nearly spot on and the other is like .04psi wrong all the time.

  2. #27
    Senior Member+ Frank B's Avatar
    Join Date
    Apr 2014
    Location
    Germany
    Posts
    8,681
    That is why brackets in the right places are important:
    (removing them gives a completely different(wrong) result)

    https://en.cppreference.com/w/c/lang...tor_precedence

  3. #28
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,696
    You can use both sensors by modifying the call to begin. The example code just uses sensor_pres.begin() which will use the default I2C address of 0x76. The .h header file has defines for both addresses:
    Code:
    #define I2C_MS5525DSO_ADDR      0x76  /* Sensor address, CSB pin HIGH */
    #define I2C_MS5525DSO_ADDR_ALT  0x77  /* Sensor address, CSB pin LOW */
    You can use these to explicitly start up each sensor:
    Code:
    // At the top of the file instantiate the two sensors
    MS5525DSO sensor_pres_1(pp005GS);
    MS5525DSO sensor_pres_2(pp005GS);
    .
    .
    .
    // In setup() start up the two sensors making sure that they do start up properly
      if (!sensor_pres_1.begin(I2C_MS5525DSO_ADDR)) {
      Serial.println("ERROR: Failed to start first sensor");
        while (true) delay(100);
      }
    
      if (!sensor_pres_2.begin(I2C_MS5525DSO_ADDR_ALT  )) {
        Serial.println("ERROR: Failed to start second sensor");
        while (true) delay(100);
      }
    Pete

  4. #29
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,696
    you just said some of my other sensors don't give the same values
    I don't know what you're referring to here. Which other sensors and "same values" as what?

    BTW. I've only been checking the temperature results. I can have a look at the pressures.

    BTW2. The example code uses part number pp005GS. This is used to index into a table of parameters that are specific to that part. If you are using a different part number, some of those parameters will change and could throw off the results of the calculation of temperature and pressure.

    Pete

  5. #30
    I'm using pp001DS because I believe that's the right one. I'm saying that when I plug another sensor in its doesnt have the same accuracy as the main one I'm using. It's weird.

  6. #31
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,696
    Are they all the same part number?

    Pete

  7. #32
    My electrical engineer told me that was the model. I know theyre not all the same. We know because the Q1-Q5 Table has the same numbers as the data sheet under the pp001DS model the rest don't match the datasheets table.

  8. #33
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,696
    I just happened to scan the coefficients table in the code and compare it with the datasheet. There is an error in the _Q_coeff array (in MS5525DSO.cpp) entry for pp002DS.
    I've commented the old value.
    Code:
      { 16, 18, 6, 4/*7*/, 7, 22 }, // pp002DS
    Pete
    P.S. All the other entries match
    Last edited by el_supremo; 07-14-2021 at 01:18 AM.

  9. #34
    Quote Originally Posted by el_supremo View Post
    I just happened to scan the coefficients table in the code and compare it with the datasheet. There is an error in the _Q_coeff array (in MS5525DSO.cpp) entry for pp002DS.
    I've commented the old value.
    Code:
      { 16, 18, 6, 4/*7*/, 7, 22 }, // pp002DS
    Pete
    P.S. All the other entries match
    Thanks man you've been a lot of help. Like honestly. I don't need 002, but it still works. Could you still possibly go through the psi values to see if they're right? Just in case there's something wrong that I can't find?

  10. #35
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,696
    Sure, I'll have a look. In order to be sure that I'm using the correct Q coefficients, I need to know which part number was used.
    Can you change the code I gave you for the _begin_common function to this:
    Code:
    #define MS5525_TEST
    #ifdef MS5525_TEST
      uint16_t temporary;
      Serial.printf("Part number = %d\n",_partNum);
      Serial.printf("uint16_t nprom[8] = {");
      for (uint8_t i = 0; i <= 7; i++) {
        if(!_read_prom(i,&temporary)) success = false;
        Serial.printf("0x%04X, ",temporary);
      }
      Serial.println("};");
    #endif
    and then run the example again and post the results. If you have part numbers other pp001DS, it would be interesting to get some data from them too.

    Pete

  11. #36
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,696
    Sure, I'll have a look. In order to be sure that I'm using the correct Q coefficients, I need to know which part number was used.
    Can you change the code I gave you for the _begin_common function to this:
    Code:
    #define MS5525_TEST
    #ifdef MS5525_TEST
      uint16_t temporary;
      Serial.printf("Part number = %d\n",_partNum);
      Serial.printf("uint16_t nprom[8] = {");
      for (uint8_t i = 0; i <= 7; i++) {
        if(!_read_prom(i,&temporary)) success = false;
        Serial.printf("0x%04X, ",temporary);
      }
      Serial.println("};");
    #endif
    and then run the example again and post the results. If you have part numbers other than pp001DS, it would be interesting to get some data from them too.

    Pete

  12. #37
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,696
    I've checked the library code for the pressure calculation using the example data from Page 7 of the datasheet and they agree.

    Pete

  13. #38
    We only have pp001DS on hand. This is my output.
    Code:
    Commencing Pressure Sensors: 
    
    Part number = 0
    uint16_t nprom[8] = {0x0001, 0x3CDE, 0x2EC0, 0x0EE5, 0x0A85, 0x7A4D, 0x20B6, 0x0003, };
    Part number = 0
    uint16_t nprom[8] = {0x0001, 0x3D89, 0x2948, 0x0EB3, 0x0896, 0x7581, 0x20F2, 0x0004, };
    --------------------------
    SENSOR 1 | -0.001600 psi
    SENSOR 2 | 0.013900 psi
    --------------------------
    --------------------------
    SENSOR 1 | -0.001700 psi
    SENSOR 2 | 0.014200 psi
    --------------------------
    --------------------------
    SENSOR 1 | -0.001700 psi
    SENSOR 2 | 0.014000 psi
    --------------------------

  14. #39
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,696
    I also need the raw numbers produced by the added code I mention in #21.
    Can you also post the code that produces the output in #38?

    Pete

  15. #40
    Code:
    Part number = 0
    uint16_t nprom[8] = {0x0001, 0x3CDE, 0x2EC0, 0x0EE5, 0x0A85, 0x7A4D, 0x20B6, 0x0003, };
    Part number = 0
    uint16_t nprom[8] = {0x0001, 0x3D89, 0x2948, 0x0EB3, 0x0896, 0x7581, 0x20F2, 0x0004, };
    raw = 6436340, 4134496
    raw = 5640154, 3979960
    raw = 6436386, 4134836
    ----------------------------
    Diff Sensor | -0.002100 psi
    raw = 5640162, 3980240
    Flow Sensor | 0.013500 psi
    ----------------------------
    
    raw = 6436404, 4134662
    raw = 5640050, 3979884
    raw = 6436380, 4134814
    fyi #include <Sensor1.h> refers to the MS5525DSO i just changed the name of the library.

    Code:
    #include <Sensor1.h>
    #include <Wire.h>
    
    MS5525DSO diff_sensor(pp001DS);
    MS5525DSO flow_sensor(pp001DS);
    void setup() {
      // put your setup code here, to run once:
      Serial.begin(115200);
      Wire.begin();
      delay(500);
      //Serial.println("----------------------------");
      //Serial.println("Commencing Sensor Readings: ");
      //Serial.println("----------------------------\n");
      delay(1500);
      if (!diff_sensor.begin(I2C_MS5525DSO_ADDR)) {
      Serial.println("ERROR: Failed to start first sensor");
        while (true) delay(100);
      }
    
      if (!flow_sensor.begin(I2C_MS5525DSO_ADDR_ALT  )) {
        Serial.println("ERROR: Failed to start second sensor");
        while (true) delay(100);
      }
    }
    
    void loop() {
      // put your main code here, to run repeatedly:
      double pressure1;
      double pressure2;
      
      if (!diff_sensor.readPressureAndTemperature(&pressure1)) {
        Serial.println("ERROR: Cannot read from sensor 1!"); 
        }
      else if (!flow_sensor.readPressureAndTemperature(&pressure2)) {
        Serial.println("ERROR: Cannot read from sensor 2!");
        } 
      if (diff_sensor.readPressureAndTemperature(&pressure1)){
        Serial.println("----------------------------");
        Serial.printf("Diff Sensor | %lf psi\r\n", pressure1);
        if (flow_sensor.readPressureAndTemperature(&pressure2)){
          Serial.printf("Flow Sensor | %lf psi\r\n", pressure2);
          Serial.println("----------------------------\n");
          delay(5000);
        }
      }
    }

  16. #41
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,696
    Your loop function will only delay for 5 seconds if it gets a valid reading from both sensors and in this case it will have read from each sensor twice, throwing away the first reading. If either sensor fails to read, there is no delay and the code will try to read both sensors as fast as it can, all the while spitting out error messages.
    I'd suggest you rework that function like this:
    Code:
    void loop()
    {
      // put your main code here, to run repeatedly:
      double pressure1;
      double pressure2;
    
      Serial.println("----------------------------");
      if (diff_sensor.readPressureAndTemperature(&pressure1)) {
        Serial.printf("Diff Sensor | %lf psi\r\n", pressure1);
      } else {
        Serial.println("ERROR: Cannot read from sensor 1!");
      }
      if (flow_sensor.readPressureAndTemperature(&pressure2)) {
        Serial.printf("Flow Sensor | %lf psi\r\n", pressure2);
      } else {
        Serial.println("ERROR: Cannot read from sensor 2!");
      }
      Serial.println("----------------------------\n");
      delay(5000);
    }
    Whether the sensors fail or not, the loop always waits five seconds between readings.

    I'll look at those numbers in an hour or two. Thanks.
    Pete

  17. #42
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,696
    As expected, I get the same pressures. I've also looked at the code itself and compared it with the datasheet. It looks correct to me and, as I mention in #37, the library matches the results in the datasheet when using the example data.

    Pete

  18. #43
    Thanks man. You're awesome.

  19. #44
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,696
    You're welcome

    FYI. I notice that by default the library uses an oversampling ratio of 4096 which will mean that it will take between 7 and 9 milliseconds to read the temperature or pressure (see page 4 of the datasheet).
    If needed, you can change this by calling the library's setOSR function using one of the defines in MS5525DSO.h as a parameter. E.g.
    Code:
      sensor_pres.setOSR(MS5525DSO_OSR_256);
    Pete

  20. #45
    What's the difference.

  21. #46
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,696
    Wikipedia explains oversampling better than I can. Basically, it reduces the noise and increases the resolution but at the cost of having to collect more samples. This is why the 4096 OSR conversion takes 16 times as long as 256 OSR. The 4096 OSR allows a sampling rate of about 120 samples/sec which is usually plenty fast enough for temperature. It would depend on the application whether a lower OSR is needed.

    Pete

  22. #47
    Senior Member
    Join Date
    Nov 2012
    Posts
    1,696
    FYI: I created a pull request on github for the error that I found in the _Q_coeff array (see #33). The PR was accepted about an hour ago.

    Pete

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •