MPU 9150 compass data reading -1


hi
getting -1 compass data. please help.

chandra  :)

here code using


void read_mag_data(int cmps[3])
{
 
  mpu9150_writesensor(mpu9150_int_pin_cfg, 0x02); //set bypass magnetometer
  mpu9150_i2c_address = mpu9150_cmps_addr; //change adress compass
  mpu9150_writesensor(0x0a, 0x00); //powerdownmode
  mpu9150_writesensor(0x0a, 0x0f); //selftest
  mpu9150_writesensor(0x0a, 0x00); //powerdownmode
  delay(10);
  mpu9150_writesensor(0x0a,0x01);  // enable magnetometer
  delay(10);
  cmps[0]=mpu9150_readsensor(mpu9150_cmps_xout_l,mpu9150_cmps_xout_h);
  cmps[1]=mpu9150_readsensor(mpu9150_cmps_yout_l,mpu9150_cmps_yout_h);
  cmps[2]=mpu9150_readsensor(mpu9150_cmps_zout_l,mpu9150_cmps_zout_h);
 
  mpu9150_i2c_address=mpu9150_addr_default;
}

int mpu9150_readsensor(int addrl, int addrh){
  wire.begintransmission(mpu9150_i2c_address);
  wire.write(addrl);
  wire.endtransmission(false);

  wire.requestfrom(mpu9150_i2c_address, 1, true);
  byte l = wire.read();

  wire.begintransmission(mpu9150_i2c_address);
  wire.write(addrh);
  wire.endtransmission(false);

  wire.requestfrom(mpu9150_i2c_address, 1, true);
  byte h = wire.read();

  return (h<<8)+l;
}

the first ting run i2c scanner (by nick gammon) make sure of device address , that  it's communicating bus.

code: [select]
#include <wire.h>

void setup() {
  serial.begin (115200);

  // leonardo: wait serial port connect
  while (!serial)
    {
    }

  serial.println ();
  serial.println ("i2c scanner. scanning ...");
  byte count = 0;
 
  wire.begin();
  (byte = 1; < 120; i++)
  {
    wire.begintransmission (i);
    if (wire.endtransmission () == 0)
      {
      serial.print ("found address: ");
      serial.print (i, dec);
      serial.print (" (0x");
      serial.print (i, hex);
      serial.println (")");
      count++;
      delay (1);  // maybe unneeded?
      } // end of response
  } // end of loop
  serial.println ("done.");
  serial.print ("found ");
  serial.print (count, dec);
  serial.println (" device(s).");
}  // end of setup

void loop() {}


Arduino Forum > Using Arduino > Sensors > MPU 9150 compass data reading -1


arduino

Comments

Popular posts from this blog

opencv3, tbb and rasp pi 2 - Raspberry Pi Forums

small ethernet problem - Raspberry Pi Forums

Multithumb configuration params not working? - Joomla! Forum - community, help and support