MPU9150 Magnetometer/Compass RAW values - I'm lost


hi all,

i'm out of ideas.

i have problems accessing raw values of magnetometer of mpu9150. acc & gyro work , simple senor fusion works nicely.
i read through lot of threads here. suggested had tried or included in code (e.g. "first clear sleep bit").

i tried other code:
https://github.com/sparkfun/mpu-9150_breakout
https://github.com/kriswiner/mpu-9150
still same...no communication compass acc&gyr works. may possible hardware damaged? may try?

the demotivating thing: worked before @ time don't plausible values (values not reproducable @ all). cannot remember change in code may affect since then, maybe i'm blind already?! may expert have short look?

this try if had similar problems before , may me. please see code in attachment...i tried keep short , commented

thanks
tim

the short answer:
try imu!

simply read i2c registers (or uart) want:
3d compass
3d gyro
3d accelerometer
sensor fusion 16 bit cpu on-board feat. kalman filtering
provides well-filtered , stabalized heading, pitch, , roll.
no monster-libs required, wire or serial.



http://de.manu-systems.com/cmps11.shtml
http://www.hobbytronics.co.uk/cmps11-tilt-compass
http://www.roboter-teile.de/oxid/navigation/kompassmodul-cmps11.html

manual:
http://www.robot-electronics.co.uk/htm/cmps11i2c.htm

example source code:
code: [select]

/****************************************************************
*                  arduino cmps10 example code                  *
*                    cmps10 running i2c mode                    *
*                    james henderson, 2012                   *
*****************************************************************/
#include <wire.h>
#include <softwareserial.h>

#define address 0x60                                          // defines address of cmps10

#define lcd_rx              0x02                              // rx , tx pins used lcd0303 serial port
#define lcd_tx              0x03
#define lcd03_hide_cur      0x04
#define lcd03_clear         0x0c
#define lcd03_set_cur       0x02

softwareserial lcd03 =  softwareserial(lcd_rx, lcd_tx);      // defines software serial port lcd03

void setup(){
  wire.begin();                                               // conects i2c
  lcd03.begin(9600);
  lcd03.write(lcd03_hide_cur);
  lcd03.write(lcd03_clear);
}

void loop(){
   byte highbyte, lowbyte, fine;              // highbyte , lowbyte store high , low bytes of bearing , fine stores decimal place of bearing
   char pitch, roll;                          // stores pitch , roll values of cmps10, chars used because support signed value
   int bearing;                               // stores full bearing
   
   wire.begintransmission(address);           //starts communication cmps10
   wire.write(2);                              //sends register wish start reading from
   wire.endtransmission();

   wire.requestfrom(address, 4);              // request 4 bytes cmps10
   while(wire.available() < 4);               // wait bytes become available
   highbyte = wire.read();           
   lowbyte = wire.read();           
   pitch = wire.read();             
   roll = wire.read();               
   
   bearing = ((highbyte<<8)+lowbyte)/10;      // calculate full bearing
   fine = ((highbyte<<8)+lowbyte)%10;         // calculate decimal place of bearing
   
   display_data(bearing, fine, pitch, roll);  // display data lcd03
   
   delay(100);
}

void display_data(int b, int f, int p, int r){    // pitch , roll (p, r) recieved ints instead oif bytes display corectly signed values.
 
  lcd03.write(lcd03_set_cur);                     // set lcd03 cursor position
  lcd03.write(1); 
  lcd03.print("cmps10 example v:");
  lcd03.print(soft_ver());                        // display software version of cmps10
 
  delay(5);                                       // delay allow lcd03 proscess data 
 
  lcd03.write(lcd03_set_cur);
  lcd03.write(21); 
  lcd03.print("bearing = ");                      // display full bearing , fine bearing seperated decimal poin on lcd03
  lcd03.print(b);                               
  lcd03.print(".");
  lcd03.print(f);
  lcd03.print("  ");

  delay(5);

  lcd03.write(lcd03_set_cur);                     // display pitch value lcd03
  lcd03.write(41);
  lcd03.print("pitch = ");
  lcd03.print(p);
  lcd03.print(" ");

  delay(5);
 
  lcd03.write(lcd03_set_cur);                     // display roll value lcd03
  lcd03.write(61);
  lcd03.print("roll = ");
  lcd03.print(r);
  lcd03.print(" ");
}

int soft_ver(){
   int data;                                      // software version of  cmps10 read data , returned
   
   wire.begintransmission(address);
   // values of 0 being sent write need masked byte not misinterpreted null bug in arduino 1.0
   wire.write((byte)0);                           // sends register wish start reading from
   wire.endtransmission();

   wire.requestfrom(address, 1);                  // request byte cmps10
   while(wire.available() < 1);
   data = wire.read();           
   
   return(data);
}



Arduino Forum > Using Arduino > Sensors > MPU9150 Magnetometer/Compass RAW values - I'm lost


arduino

Comments