Bosch Sensortec Community

    cancel
    Showing results for 
    Search instead for 
    Did you mean: 

    Reading BMM150 head

    NikitaMalikov
    Occasional Visitor

    Reading BMM150 head

    Hi

    I'm using the BMM150 to get earth compass read

    How to convert the X,Y,Z values to 0-360 compass heading read?

    Do I need to calibrate the BMM150 to improve the readout values?

     

    I set the following configuration using i2c:

     

    Register 0x4B Value 0x01 (Power)

    Register 0x4E Value 0x87 (Enable Data Ready bit)

    Register 0x4E Value 0x4C(Normal mode)

     

    Reading  sequnse + parsing raw data:

    When Data Ready Status bit is 1 read 6 byte from register 42 into buffer 

    x_raw[0] = (buffer[1] << 5) | (buffer[0] >> 3); // x
    y_raw[1] = (buffer[3] << 5) | (buffer[2] >> 3); // y

    xyHeading = atan2(x_raw[0], y_raw[1]);

    if(xyHeading < 0)
        xyHeading += 2*PI;
    if(xyHeading > 2*PI)
        xyHeading -= 2*PI;

    deg = xyHeading * 180/PI;

    I getting the same problem with every read call and the deg is alyaws 45 degrees regardless  the location of the sensor in space.

    Appreciate any help

    1 REPLY 1
    FAE_CA1
    Community Moderator

    Re: Reading BMM150 head

    Hi,

    Thanks for your inquiry.

    If you want to implement an eCompass in 3D space, then you need a 3-axis accelerometer to work with BMM150. If you only rotate the eCompass on a flat leveled surface in 2D, then you don't need the accel.

    For 2D eCompass, you can do the following:

    (1) Get BMM150 x/y/z values in the unit of uT from the API source code online at https://github.com/BoschSensortec/BMM150-Sensor-API. Or you can refer to the attached "bmm150-step-by-step-temperature-compensation-sample.pdf" about how to convert BMM150 raw signed integers to uT values.

    (2) After you get BMM150 x/y/z values in the unit of uT, then you can rotate your device clockwise or counterclockwise a few rounds slowly to collect BMM150 data.

    (3) Then you can plot BMM150 x/y data in x-y plane. It should look like a circle shifted from the origin. Now you can determine the offset x0 and y0 so that you cam move the shifted circle to the center.

    (4) Now you can use your formula below every time when you get the new BMM150 x/y/z data in the unit of uT:

    xyHeading = atan2[(x_raw-x0), (y_raw-y0);

    if(xyHeading < 0)
    xyHeading += 2*PI;
    if(xyHeading > 2*PI)
    xyHeading -= 2*PI;

    deg = xyHeading * 180/PI;

    For 3D space tilt compensated eCompass, you can find a lot of articles online about how to do it.

    Thanks.

    Icon--AD-black-48x48Icon--address-consumer-data-black-48x48Icon--appointment-black-48x48Icon--back-left-black-48x48Icon--calendar-black-48x48Icon--center-alignedIcon--Checkbox-checkIcon--clock-black-48x48Icon--close-black-48x48Icon--compare-black-48x48Icon--confirmation-black-48x48Icon--dealer-details-black-48x48Icon--delete-black-48x48Icon--delivery-black-48x48Icon--down-black-48x48Icon--download-black-48x48Ic-OverlayAlertIcon--externallink-black-48x48Icon-Filledforward-right_adjustedIcon--grid-view-black-48x48IC_gd_Check-Circle170821_Icons_Community170823_Bosch_Icons170823_Bosch_Icons170821_Icons_CommunityIC-logout170821_Icons_Community170825_Bosch_Icons170821_Icons_CommunityIC-shopping-cart2170821_Icons_CommunityIC-upIC_UserIcon--imageIcon--info-i-black-48x48Icon--left-alignedIcon--Less-minimize-black-48x48Icon-FilledIcon--List-Check-grennIcon--List-Check-blackIcon--List-Cross-blackIcon--list-view-mobile-black-48x48Icon--list-view-black-48x48Icon--More-Maximize-black-48x48Icon--my-product-black-48x48Icon--newsletter-black-48x48Icon--payment-black-48x48Icon--print-black-48x48Icon--promotion-black-48x48Icon--registration-black-48x48Icon--Reset-black-48x48Icon--right-alignedshare-circle1Icon--share-black-48x48Icon--shopping-bag-black-48x48Icon-shopping-cartIcon--start-play-black-48x48Icon--store-locator-black-48x48Ic-OverlayAlertIcon--summary-black-48x48tumblrIcon-FilledvineIc-OverlayAlertwhishlist