Ms4525 coding error

Hi guys, I search about my airspeed sensor then I try to see the datas are coming and receiving . I search about code because I don't have any background about serial interface coding, I found in that topic,
here I rewrite the code because I got copy - paste error from Arduino IDE, then again tried to see any error and ofcourse it came out but I didn't figure out and don't know how to solve, here is the code and its error:

#include <Wire.h> //Arduino I2C lib.
#include <stdint.h> //Standard C, allows explicit data type decleration.

//MS4525D sensor characteristic.  

//MS4525D sensor I2C address (uncomment the interface type of the device you will use.
// Interface Type I
const uint8_t MS4525DAddress = 0x25;
//Interface Type J
//const uint8_t MS4525Daddress = 0x36;
//Interface Type K
//const uint8_t MS4525Daddress = 0x46;
//Interface Type 0
//const uint8_t MS4525Daddress = 0x48;

//MS4525D sensor full scale range and units
const int16_t MS4525FullScaleRange = 1; //1 psi
//const int16_t MS4525FullScaleRange = 0.0689476; // 1 psi in Bar
//const int16_t MS4525FullScaleRange = 6895 // 1 psi in Pascal
//const int16_t MS4525FullScaleRange = 2; // 2 psi
//const int16_t MS4525FullScaleRange = 5; // 5 psi

//MS4525D sensor type (A or B) comment out the wrong type assingments
//Type A (10% to 90%)
const int16_t MS4525MinScaleCounts = 1638;
const int16_t MS4525FullScaleCounts = 14746;
//Type B (5% to 95%)
//const int16_t MS4525MinScaleCounts = 819;
//const int16_t MS4525FullScaleCounts = 15563;
const int16_t MS4525Span = MS4525FullScaleCounts - MS4525MinScaleCounts;

//MS4525D sensor pressure style, differential or otherwise.Comment out the wrong one.
const int16_t MS4525ZeroCounts = (MS4525MinScaleCounts + MS4525FullScaleCounts)/2;
// Absolute ,Gauge
//const int16_t MS4525ZeroCounts = MS4525inScaleCounts;

// End of the MS4525D sensor characteristic

// fetch_pressure is a function to do the I2C read and extraction of the three data fileds.

byte fetch_pressure(uint16_t &P_dat, uint16_t &T_dat)
  byte _status;
  byte Press_H;
  byte Press_L;
  byte Temp_H;
  byte Temp_L;
  Wire.requestFrom(MS4525DAddress, static_cast<uint8_t>(4), static_cast<uint8_t>(true)); // REquest 4 bytes, 2 pressure/status and 2 temprature.
  Press_H =;
  Press_L =;
  Temp_H =;
  Temp_L =;

  _status = (Press_H >> 6) & 0x03;
  Press_H = Press_H & 0x3f;
  P_dat = (((uint16_t)Press_H) << 8 ) | Press_L;

  Temp_L = (Temp_L >> 5);
  T_dat = (((uint16_t)Temp_H) << 3) | Temp_L;

  return _status;

// setup is the main function to setup the diagonistic serial port and the I2C port
void setup()
  //wait untill serial port opens for native USB devices.
  while(! Serial)
  Serial.println("MS4525D0 test");
void loop()
  byte _status; // A two bit field indicating the status of the I2C read
  uint16_t P_dat; // 14 bit pressure data
  uint16_t T_dat; // 11 bit temperature data
  float psi;

  _status = fetch_pressure(P_dat,T_dat);
    case 0:
    case 1:
    case 2:
  psi =(static_cast(static_cast<int16_t>(P_dat)-MS4525ZeroCounts))/static_cast(MS4525Span)*static_cast(MS4525FullScaleRange);


Arduino: 1.8.16 (Linux), Board: "Arduino Uno"
/home/tugbakara/arduino/MS4525/sketch_dec14a_1/sketch_dec14a_1.ino: In function 'void loop()':
sketch_dec14a_1:106:20: error: expected '<' before '(' token
   psi =(static_cast(static_cast<int16_t>(P_dat)-MS4525ZeroCounts))/static_cast(MS4525Span)*static_cast(MS4525FullScaleRange);
sketch_dec14a_1:106:20: error: expected type-specifier before '(' token
sketch_dec14a_1:106:20: error: expected '>' before '(' token
sketch_dec14a_1:106:79: error: expected '<' before '(' token
   psi =(static_cast(static_cast<int16_t>(P_dat)-MS4525ZeroCounts))/static_cast(MS4525Span)*static_cast(MS4525FullScaleRange);
sketch_dec14a_1:106:79: error: expected type-specifier before '(' token
sketch_dec14a_1:106:79: error: expected '>' before '(' token
sketch_dec14a_1:106:103: error: expected '<' before '(' token
   psi =(static_cast(static_cast<int16_t>(P_dat)-MS4525ZeroCounts))/static_cast(MS4525Span)*static_cast(MS4525FullScaleRange);
sketch_dec14a_1:106:103: error: expected type-specifier before '(' token
sketch_dec14a_1:106:103: error: expected '>' before '(' token
exit status 1
expected '<' before '(' token

This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.

Without checked if the calculation is still correct, this version at least compiles:

psi =(static_cast<float>(static_cast<int16_t>(P_dat)-MS4525ZeroCounts))/static_cast<float>(MS4525Span)*static_cast<float>(MS4525FullScaleRange);

I saw the output like that, but it is not readable:

and it is going endlessly as expected but it's wrong where do I make mistake?

Now I got the f,irst m,stake that I made is just changing baudrate, I didn't recognize it was 9600 in code it is 115200, I changed it but right now it giving me that:

First: don't post pictures of text output, post the text!

You probably get the error because the hardware isn't correct. As you failed to post a wiring diagram of your setup we cannot help further.

I solve that issue the code was completely wrong for my sensor, someone added right code in that topic mentioned above . So I appreciate for your reply , you saved my life whatever happens.

Can you please post your working code, so others using this thread with similar problems, can see your solution.

Thanks.. Tom... :grinning: :+1: :coffee: :australia:

I said that topic mentioned in above has the right code.
Have a nice day.