Sadly, all your data seems to be zeros.
Try this, I've tried to put some comments in.
Can you say how the device is connected - as far as I can see you must have it connected to the serial output line, so everything that is
a Serial.print("some string") is being sent to your device as well as the host computer.
// declare a union to convert bytes to a float
union t_long_fl {
byte b_arr[4];
float f_var;
} t1 ;
// prints the 4 bytes of the union byte array, for debugging to see what is coming back
void print_ba()
{
for (int i = 0; i < 4; i++)
{
Serial.print(" ");
Serial.print((int)t1.b_arr[i]);
}
Serial.println();
}
// prints a float with 2 decimal places
void print_float(float f)
{
long i_i = (long)f;
int i_f = 100 * (f - (float)i_i);
Serial.print(i_i);
Serial.print('.');
Serial.print(i_f);
}
char d;
void setup()
{
Serial.begin(115200);
//d=194;
d = 0xC2; // this is the command value for Acceleration & Angular Rate (0xC2)
Serial.print(d);
}
void loop()
{
int i;
boolean frame_all_done = false;
if (Serial.available())
{
char c = Serial.read();
if (c == 0xC2) {
// have got the first character of the frame we expect, wait for rest of frame to come it
// if the frame character is not an 0xC2 will not process in this block
while (Serial.available() < 30) {
// loop waits until there are 30 bytes read from the interface
// overall response frame is 31 long, but we already got the 1st one
}
Serial.println(" Received all frame bytes");
//Bytes 2-5 AccelX
Serial.print("Accel X:");
for (i = 0; i < 4 ; i++)
{
t1.b_arr[i] = Serial.read();
}
print_float(t1.f_var);
print_ba();
//Bytes 6-9 AccelY
Serial.print("Accel Y:");
for (i = 0; i < 4 ; i++)
{
t1.b_arr[i] = Serial.read();
}
print_float(t1.f_var);
print_ba();
//Bytes 10-13 AccelZ
Serial.print("Accel Z:");
for (i = 0; i < 4 ; i++)
{
t1.b_arr[i] = Serial.read();
}
print_float(t1.f_var);
print_ba();
//Bytes 14-17 AngRateX
Serial.print("AR X:");
for (i = 0; i < 4 ; i++)
{
t1.b_arr[i] = Serial.read();
}
print_float(t1.f_var);
print_ba();
//Bytes 18-21 AngRateY
Serial.print("AR Y:");
for (i = 0; i < 4 ; i++)
{
t1.b_arr[i] = Serial.read();
}
print_float(t1.f_var);
print_ba();
//Bytes 22-25 AngRateZ
Serial.print("AR Z:");
for (i = 0; i < 4 ; i++)
{
t1.b_arr[i] = Serial.read();
}
print_float(t1.f_var);
print_ba();
//Bytes 26-29 Timer
for (i = 0; i < 4 ; i++)
{
Serial.read(); // just discarding
}
//Bytes 30-31 Checksum
for (i = 0; i < 2 ; i++)
{
Serial.read(); // just discarding
}
frame_all_done = true; // set up flag to ask for another frame
} // end if frame start detected
else
{
Serial.print("First byte rx is not expected frame start:");
Serial.print((byte)c,HEX);
}
} // end if serial data available
// frame is now finished, the loop is ready for another frame, so try asking for another frame
if (frame_all_done == true)
{
char d;
d = 0xC2;
delay(2000); // wait two seconds
Serial.print(d);
frame_all_done = false;
}
} // end loop