rpicopter / ArduinoMotionSensorExample

MPU6050/MPU6500/MPU9150/MPU9250 over I2c for Arduino
117 stars 40 forks source link

MPU9150 - Magnetometer/Compass support #2

Open GOHO opened 9 years ago

GOHO commented 9 years ago

I download your code and compiled this to my Leonardo. It works fine but how do I access the Compass or Magnetometer output? I see only Accel and gyro....

gregd72002 commented 9 years ago

MPU9150 has a magnetometer. Compass data (heading) has to be calculated based on the magnetometer data.

To get magnetometer working you will need to alter the sensor initialisation in mpu.cpp: mpu_set_sensors(INV_XYZ_GYRO I INV_XYZ_ACCEL I INV_XYZ_COMPASS)

And set the sample rate for compass: mpu_set_compass_sample_rate(50);

To read data: mpu_get_compass_reg(comp,NULL); Where comp is short[3].

See: https://github.com/rpicopter/AvrMiniCopter/blob/master/arduino/mpu.cpp

GOHO commented 9 years ago

Thank you for the quick reply!!!

Merry Christmas!

Greg

Sent from my iPhone

On Dec 27, 2014, at 8:00 AM, gregd72002 notifications@github.com wrote:

MPU9150 has a magnetometer. Compass data (heading) has to be calculated based on the magnetometer data.

To get magnetometer working you will need to alter the sensor initialisation in mpu.cpp: mpu_set_sensors(INV_XYZ_GYRO I INV_XYZ_ACCEL I INV_XYZ_COMPASS)

And set the sample rate for compass: mpu_set_compass_sample_rate(50);

To read data: mpu_get_compass_reg(comp,NULL); Where comp is short[3].

See: https://github.com/rpicopter/AvrMiniCopter/blob/master/arduino/mpu.cpp

— Reply to this email directly or view it on GitHub.

GOHO commented 9 years ago

One more question, what file do i add the compass sample rate? Do i add it to the mpu.cpp or my main sketch?

Thanks! Greg

Sent from my iPhone

On Dec 27, 2014, at 8:00 AM, gregd72002 notifications@github.com wrote:

MPU9150 has a magnetometer. Compass data (heading) has to be calculated based on the magnetometer data.

To get magnetometer working you will need to alter the sensor initialisation in mpu.cpp: mpu_set_sensors(INV_XYZ_GYRO I INV_XYZ_ACCEL I INV_XYZ_COMPASS)

And set the sample rate for compass: mpu_set_compass_sample_rate(50);

To read data: mpu_get_compass_reg(comp,NULL); Where comp is short[3].

See: https://github.com/rpicopter/AvrMiniCopter/blob/master/arduino/mpu.cpp

— Reply to this email directly or view it on GitHub.

gregd72002 commented 9 years ago

it should be in mpu.cpp in mympu_open function. Similar to this: https://github.com/rpicopter/AvrMiniCopter/blob/master/arduino/mpu.cpp#L68

Please do not forget to create a pull request once you are finished.

Thanks

GOHO commented 9 years ago

Ok found the set rate for compass in the mpu.cpp but what about the read compass, does that go into the mpu.cpp?

In the main sketch you have mympu.gyro & mympu.y. To read the sensor, does the compass have the same type read command?

Thanks again

Greg

Sent from my iPhone

On Dec 27, 2014, at 8:00 AM, gregd72002 notifications@github.com wrote:

MPU9150 has a magnetometer. Compass data (heading) has to be calculated based on the magnetometer data.

To get magnetometer working you will need to alter the sensor initialisation in mpu.cpp: mpu_set_sensors(INV_XYZ_GYRO I INV_XYZ_ACCEL I INV_XYZ_COMPASS)

And set the sample rate for compass: mpu_set_compass_sample_rate(50);

To read data: mpu_get_compass_reg(comp,NULL); Where comp is short[3].

See: https://github.com/rpicopter/AvrMiniCopter/blob/master/arduino/mpu.cpp

— Reply to this email directly or view it on GitHub.

GOHO commented 9 years ago

I appreciate all your help

Im am not sure what you mean by pull request.

G

Sent from my iPhone

On Dec 27, 2014, at 11:29 AM, gregd72002 notifications@github.com wrote:

it should be in mpu.cpp in mympu_open function. Similar to this: https://github.com/rpicopter/AvrMiniCopter/blob/master/arduino/mpu.cpp#L68

Please do not forget to create a pull request once you are finished.

Thanks

— Reply to this email directly or view it on GitHub.

gregd72002 commented 9 years ago

it should go to mpu.cpp

As for the pull request I meant to contribute your work to this project. See: https://help.github.com/articles/using-pull-requests/

GOHO commented 9 years ago

Hi Greg, I put the commands in the mpu.cpp and the sketch compiles ok until I try and call up the compass. I used the command "mympu.comp[0]" but this is the error I get....

This report would have more information with "Show verbose output during compilation" enabled in File > Preferences.Arduino: 1.0.6 (Windows 7), Board: "Arduino Leonardo"AvrCopter.ino: In function 'void loop()':AvrCopter:44: error: 'struct s_mympu' has no member named 'comp'

Im really sorry for being a pain in the Ass!!! I sure appreciate your help in getting this to compile and run...

How should I call up the compass in my sketch to see my heading? I would try the link you sent me but the leonardo does not have enough memory to run it...

Greg Bounds772-571-7911

Date: Sat, 27 Dec 2014 08:53:33 -0800 From: notifications@github.com To: ArduinoMotionSensorExample@noreply.github.com CC: goldhoundgreg@hotmail.com Subject: Re: [ArduinoMotionSensorExample] MPU9150 (#2)

it should go to mpu.cpp

As for the pull request I meant to contribute your work to this project.

See: https://help.github.com/articles/using-pull-requests/

— Reply to this email directly or view it on GitHub.

                  =