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:
CODE:
#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.
//Differential
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 = Wire.read();
Press_L = Wire.read();
Temp_H = Wire.read();
Temp_L = Wire.read();
_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()
{
Serial.begin(115200);
Wire.begin();
//wait untill serial port opens for native USB devices.
while(! Serial)
{
delay(1);
}
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);
switch(_status)
{
case 0:
//Serial.print("Ok");
break;
case 1:
Serial.println("Busy");
break;
case 2:
Serial.println("Slate");
break;
default:
Serial.println("Error");
break;
}
psi =(static_cast(static_cast<int16_t>(P_dat)-MS4525ZeroCounts))/static_cast(MS4525Span)*static_cast(MS4525FullScaleRange);
Serial.print("psi:");
Serial.println(psi);
}
ERROR:
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.