Differential Pressure Sensor Programming Question

I would like to use a differential pressure sensor for detecting airspeed
The selected sensor is MS4525DO
Here is the spec. sheet: MS4525DO
After I run the program, I found that there are some problems in data reading

//#include <WireMW.h>
#include <Wire.h>   //I2C library 0x28H 
byte fetch_pressure(unsigned int *p_Pressure); //convert value to byte data type


#define TRUE 1
#define FALSE 0

void setup(void)
{
  Serial.begin(9600);
  Wire.begin();
  delay(500);
  Serial.println(">>>>>>>>>>>>>>>>>>>>>>>>");  // just to be sure things are working
}

void loop()
{
  byte _status;
  unsigned int P_dat;
  unsigned int T_dat;
  double PR;
  double TR;
  double V;
  double VV;
  while (1)
  {
    _status = fetch_pressure(&P_dat, &T_dat);

    switch (_status)
    {
      case 0: Serial.println("Ok ");
        break;
      case 1: Serial.println("Busy");
        break;
      case 2: Serial.println("Slate");
        break;
      default: Serial.println("Error");
        break;
    }


    PR = (double)((P_dat-819.15)/(14744.7)) ;
    PR = (PR - 0.49060678) ;
    PR = abs(PR);
     V = ((PR*13789.5144)/1.225);
    VV = (sqrt((V)));

    
    TR = (double)((T_dat*0.09770395701));
    TR = TR-50;
    
  
    
   Serial.print("raw Pressure:");
   Serial.println(P_dat);
   //Serial.println(P_dat,DEC);
   //Serial.println(P_dat,BIN);
   Serial.print("pressure psi:");
   Serial.println(PR,10);
   Serial.print(" ");
   Serial.print("raw Temp:");
   Serial.println(T_dat);
   Serial.print("temp:");
   Serial.println(TR);
   Serial.print("speed m/s :");
   Serial.println(VV,5);
  



    delay(1000);
  }
}

byte fetch_pressure(unsigned int *p_P_dat, unsigned int *p_T_dat)
{


  byte address, Press_H, Press_L, _status;
  unsigned int P_dat;
  unsigned int T_dat;

  address = 0x28;
  Wire.beginTransmission(address);
  Wire.endTransmission();
  delay(100);

  Wire.requestFrom((int)address, (int) 4);//Request 4 bytes need 4 bytes are read
  Press_H = Wire.read();
  Press_L = Wire.read();
  byte Temp_H = Wire.read();
  byte  Temp_L = Wire.read();
  Wire.endTransmission();


  _status = (Press_H >> 6) & 0x03;
  Press_H = Press_H & 0x3f;
  P_dat = (((unsigned int)Press_H) << 8) | Press_L;
  *p_P_dat = P_dat;

  Temp_L = (Temp_L >> 5);
  T_dat = (((unsigned int)Temp_H) << 3) | Temp_L;
  *p_T_dat = T_dat;
  return (_status);



}

cychengad:
I would like to use a differential pressure sensor for detecting airspeed
The selected sensor is MS4525DO
Here is the spec. sheet: MS4525DO
After I run the program, I found that there are some problems in data reading

Be sure not to tell us what "some problems" are.

That always gets us interested, and invested in your problem.

AWOL:
Be sure not to tell us what "some problems" are.

That always gets us interested, and invested in your problem.

The problems are:

  1. The airspeed is always at 8 m/s when stagnation
  2. when i blow the sensor ,the air speed data drops

Looking at the data sheet , is there an offset ? - ie it gives “ counts at zero pressure difference” - you can check that in your code.
If the output drops with increasing differential , have you got the pressure connections the right way around ?

I’d suggest writing some simple code just to print out the pressure from the sensor , to see if you have that correct, then move on to the other stuff .
Btw - why declare variables inside the loop ?

hammy:
Btw - why declare variables inside the loop ?

Why not, if they have no need of persistence?

My preference would be to define them even closer to where they're used.

Fair comment .

can somebody comment?
thanks

Can you post a diagram showing how you have it hooked up?

Thanks

The differential sensor outputs at 50%cycle if port a and port b are equal.
If pressure increases on port a it then drops closer to 0% and if pressure increases on port b it goes up towards the 100% . Does your program calculate for this. 8 m/s might be the 50% point.

in your picture you have a value called raw pressure. which is 8153.
is this the digital count value from the sensor. if it is then it is the 50% cycle value.
this is the value you get when the pressure is equal on port a and b.

Why have a while(1) loop inside the function loop()? Loop() already loops indefinitely.

I'd also checkout the BlinkWithoutDelay example to see how to get rid of that call to
delay() allowing the sketch to do other stuff too.

hi,
have got your answer bro.i m also having problem reading this sensor.
if anybody can help pls answer.

Yes we can help. What is the specific problem?

It is usually best if you start your own thread with your question and show a link to this one or any other psge you googled, if you think we might get useful information from what you found already.