Skip to content

MPU9150 - Magnetometer/Compass support #2

Open

Description

@GOHO

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....

Activity

  1. gregd72002 commented on Dec 27, 2014

    @gregd72002
    Contributor

    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

  2. GOHO commented on Dec 27, 2014

    @GOHO
    Author

    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.

  3. GOHO commented on Dec 27, 2014

    @GOHO
    Author

    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.

  4. gregd72002 commented on Dec 27, 2014

    @gregd72002
    Contributor

    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

  5. GOHO commented on Dec 27, 2014

    @GOHO
    Author

    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.

  6. GOHO commented on Dec 27, 2014

    @GOHO
    Author

    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.

  7. gregd72002 commented on Dec 27, 2014

    @gregd72002
    Contributor

    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/

  8. changed the title [-]MPU9150[/-] [+]MPU9150 - Magnetometer/Compass support[/+] on Dec 27, 2014
  9. GOHO commented on Dec 27, 2014

    @GOHO
    Author

    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.

                      =
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions