I'm using
SparkFun MPU-9150 breakout board
Hterm for Windows / CoolTerm for Mac for testing .
Trying to code it such that it replies with the " Yaw , Pitch & Roll " readings when i request for it using CoolTerm .
However , I've been receiving " 00 00 00 00 " as a reply
I suspect it might be the 'count' that isn't counting causing the readings to be 0x00
void checkADCSCommand(byte byteRead[])
{
byte responseByte[7] = {0x00};
switch(byteRead[2])
{
case 01:
{
if(mpu.getIntDataReadyStatus() == 1) { // wait for data ready status register to update all data registers
mcount++;
// read the raw sensor data
mpu.getAcceleration ( &a1, &a2, &a3 );
ax = a12.0f/32768.0f; // 2 g full range for accelerometer
ay = a22.0f/32768.0f;
az = a3*2.0f/32768.0f;
mpu.getRotation ( &g1, &g2, &g3 );
gx = g1250.0f/32768.0f; // 250 deg/s full range for gyroscope
gy = g2250.0f/32768.0f;
gz = g3250.0f/32768.0f;
if (mcount > 1000/MagRate)
{ // this is a poor man's way of setting the magnetometer read rate (see below)
mpu.getMag ( &m1, &m2, &m3 );
mx = m110.0f1229.0f/4096.0f + 18.0f; // milliGauss (1229 microTesla per 2^12 bits, 10 mG per microTesla)
my = m210.0f1229.0f/4096.0f + 70.0f; // apply calibration offsets in mG that correspond to your environment and magnetometer
mz = m310.0f*1229.0f/4096.0f + 270.0f;
mcount = 0;
}
}
now = micros();
deltat = ((now - lastUpdate)/1000000.0f); // set integration time by time elapsed since last filter update
lastUpdate = now;
// Serial print and/or display at 0.5 s rate independent of data rates
delt_t = millis() - count;
if (delt_t > 500)
{
float yaw = atan2(2.0f * (q[1] * q[2] + q[0] * q[3]), q[0] * q[0] + q[1] * q[1] - q[2] * q[2] - q[3] * q[3]);
float pitch = -asin(2.0f * (q[1] * q[3] - q[0] * q[2]));
float roll = atan2(2.0f * (q[0] * q[1] + q[2] * q[3]), q[0] * q[0] - q[1] * q[1] - q[2] * q[2] + q[3] * q[3]);
pitch *= 180.0f / PI;
yaw *= 180.0f / PI - 13.8; // Declination at Danville, California is 13 degrees 48 minutes and 47 seconds on 2014-04-04
roll *= 180.0f / PI;
count = millis();
}
FTH.val = pitch ;
responseByte[3] = 0x04;//return 4 bytes
responseByte[4] = FTH.b[3];
responseByte[5] = FTH.b[2];
responseByte[6] = FTH.b[1];
responseByte[7] = FTH.b[0];
replyCommand(byteRead,responseByte,responseByte[3]);
}break;