arduino - Strange magnetometer readout -


i attempting readout data mpu-9150 magnetometer , getting odd numbers. have accessed magnetometer within imu , getting data changes orientation of imu not within range specified product specification guide. i'm think either variable type using store data or method using manipulate twos compliment data make readable, here code anyway...

void mpu9150::getmag(double* mag_x, double* mag_y, double* mag_z){     uint8_t  asax, asay, asaz;       i2cdev::writebyte(mpu9150_address, int_pin_cfg, 0x02);//set i2c bypass enable pin true access magnetometer.     i2cdev::writebyte(mpu9150_mag_address, mpu9150_mag_cntrl, 0x0f);//fuse rom access mode.     i2cdev::readbytes(mpu9150_mag_address, mpu9150_mag_asax, 3, buffer);//get sensitivity adjustment values.     asax = buffer[0];     asay = buffer[1];     asaz = buffer[2];      // serial.print("asax = "); serial.print(asax); serial.print("\n");     // serial.print("asay = "); serial.print(asay); serial.print("\n");     // serial.print("asaz = "); serial.print(asaz); serial.print("\n\n");      i2cdev::writebyte(mpu9150_mag_address, mpu9150_mag_cntrl, 0x01);//enable magnetometer.     delay(10);     i2cdev::readbytes(mpu9150_mag_address, mpu9150_mag_xout_l, 6, buffer);//read magnetometer readings.     mx = ((((int16_t)buffer[0]) << 8) | buffer[1]) * 0.3;     = ((((int16_t)buffer[2]) << 8) | buffer[3]) * 0.3;     mz = ((((int16_t)buffer[4]) << 8) | buffer[5]) * 0.3;      *mag_x = mx * ((((asax - 128)*0.5)/(128)) + 1);//adjust readings sensitivity adjustment values.     *mag_y = * ((((asay - 128)*0.5)/(128)) + 1);     *mag_z = mz * ((((asaz - 128)*0.5)/(128)) + 1); 

}

the decimal range each axis should between 4096 , -4096, , there 6 data registers each containing 8 bit high , low values each axis. data getting seems in range >10000 <-10000 highest value have seen @ 9830. if has ideas appreciated, :)

edit: buffer private integer array, used hold bytes axis registers.

private:      uint8_t buffer[14]; 

also reversing order of bytes (as have realised should done first byte in each register low , second high) has resulted in range of output reduced range of -170 170...

mx = (((int16_t)buffer[1]) << 8) | buffer[0]; = (((int16_t)buffer[3]) << 8) | buffer[2]; mz = (((int16_t)buffer[5]) << 8) | buffer[4]; 


Comments

Popular posts from this blog

Fail to load namespace Spring Security http://www.springframework.org/security/tags -

sql - MySQL query optimization using coalesce -

unity3d - Unity local avoidance in user created world -