Skip to main content

Grove - 3-Axis Digitial Compass v2.0

pir

The Grove - 3-Axis Digital Compass is a digital compass sensor based on Bosch BMM150. It allows measurement of the magnatic field in three perpendicular axes and the output can be read out over I2C and SPI interface, perfectly suitable for 3-Axis mobile applications.

This is the second generation of Grove - 3-Axis Digital Compass, comparing to the first version, this version can perfectly match the demanding requirements of all 3-Axis applications while the price is almost half of the first version, very cost effective.

pir

Features

  • High resolution
  • High heading accuracy
  • Easy to use

Specifications

ItemValnue
Working Voltage3.3V / 5V
Magnetic field range typical±1300μT(x, y-axis), ±2500μT(z-axis)
Magnetic field resolution0.3μT
Output Degree0º ~ 360º
InterfaceI2C
Working Temperature-40℃ to +85 ℃
Dimensions20mm x 20mm x 15mm
I2C Address0x13
note
If you want to use multiplue I2C devices, please refer to [Software I2C](https://wiki.seeedstudio.com/Arduino_Software_I2C_user_guide/).
tip
More details about Grove modules please refer to [Grove System](https://wiki.seeedstudio.com/Grove_System/)

Platforms Supported

ArduinoRaspberry Pi

pir

pir

caution
The platforms mentioned above as supported is/are an indication of the module's software or theoritical compatibility. We only provide software library or code examples for Arduino platform in most cases. It is not possible to provide software library / demo code for all possible MCU platforms. Hence, users have to write their own software library.

Getting started

Play with Arduino

#### Hardware

  • Step 1. Prepare the below stuffs:
Seeeduino V4.2Base ShieldGrove-3-Axis_Digitial_Compass_v2.0

pir

pir

pir

Get One NowGet One NowGet One Now
  • Step 2. Connect Grove-3-Axis_Digitial_Compass_v2.0 to port I2C of Grove-Base Shield.

  • Step 3. Plug Grove - Base Shield into Seeeduino.

  • Step 4. Connect Seeeduino to PC via a USB cable.

    <!--link-->

    pir

note
    If we don't have Grove Base Shield, We also can directly connect this module to Seeeduino as below.
Seeeduino_v4Grove-3-Axis_Digitial_Compass_v2.0
5VVCC
GNDGND
SDASDA
SCLSCL

Caution

Please plug the USB cable gently, otherwise you may damage the interface.Please use the USB cable with 4 wires inside, the 2 wires cable can't transfer data. If you are not sure about the wire you have, you can click
here
to buy

Software

Step 1. Download the library from Github.

Step 2. Refer How to install library to install library for Arduino.

Step 3. Create a new Arduino sketch and paste the codes below to it or open the code directly by the path: File->Examples->Grove_3_Axis_Compass_V2.0_BMM150-master->compass

Here is the code

/**
* This example
*/

#include <Arduino.h>
#include <Wire.h>
// libraries
#include "bmm150.h"
#include "bmm150_defs.h"

BMM150 bmm = BMM150();

void setup()
{
Serial.begin(9600);

if(bmm.initialize() == BMM150_E_ID_NOT_CONFORM) {
Serial.println("Chip ID can not read!");
while(1);
} else {
Serial.println("Initialize done!");
}

}

void loop()
{
bmm150_mag_data value;
bmm.read_mag_data();

value.x = bmm.raw_mag_data.raw_datax;
value.y = bmm.raw_mag_data.raw_datay;
value.z = bmm.raw_mag_data.raw_dataz;

float xyHeading = atan2(value.x, value.y);
float zxHeading = atan2(value.z, value.x);
float heading = xyHeading;

if(heading < 0)
heading += 2*PI;
if(heading > 2*PI)
heading -= 2*PI;
float headingDegrees = heading * 180/M_PI;
float xyHeadingDegrees = xyHeading * 180 / M_PI;
float zxHeadingDegrees = zxHeading * 180 / M_PI;

Serial.print("Heading: ");
Serial.println(headingDegrees);

delay(100);
}

Step 4. Upload the code. If you do not know how to upload the code, please check how to upload code.

Step 5. Open the serial monitor to receive the sensor's data

pir

Step 6. Within these 3 seconds, please tilt and rotate the compass back and forth on every axis, as shown in the picture below.

pir

The calibration period time can be changed through the parameter timeout in the fuction calibrate(uint16_t timeout).

note
  The compass needs to be calibrated, otherwise you will get the inaccurate data! Please make sure you have done the Step 5.

Step 7. Finally, you will see the something like the following picture.

pir

tip
Heading value is in range of 0º ~ 360º, this value is for Y axis, 0º means Y axis points at North, 90º means Y axis points at West, 180º means Y axis points at South, 270º means Y points at East.

Enjoy your compass!

Play With Raspberry Pi (With Grove Base Hat for Raspberry Pi)

Hardware

  • Step 1. Things used in this project:
Raspberry piGrove Base Hat for RasPiGrove - 3-axis compass

pir

pir

pir

Get ONE NowGet ONE NowGet ONE Now
  • Step 2. Plug the Grove Base Hat into Raspberry.
  • Step 3. Connect the 3-axis compass to I2C port of the Base Hat.
  • Step 4. Connect the Raspberry Pi to PC through USB cable.

pir

Software

  • Step 1. Follow Setting Software to configure the development environment.
  • Step 2. Download the source file by cloning the grove.py library.
note
 If you are using **Raspberry Pi with Raspberrypi OS >= Bullseye**, you have to use this command line **only with Python3**.
note
You are required to install python-mraa and python-upm, see the instruction here https://github.com/Seeed-Studio/pi_repo#mraa--upm-package-repository-for-raspberry-pi for more information.
cd ~
git clone https://github.com/Seeed-Studio/grove.py

  • Step 3. Excute below commands to run the code.
cd grove.py/grove
python3 grove_3_axis_compass_bmm150.py

Following is the grove_3_axis_compass_bmm150.py code.


from __future__ import print_function
import time, sys, signal, atexit, math
try:
from upm import pyupm_bmm150 as sensorObj
except ImportError:
print('Error: Please install python-mraa python-upm module.\r\n'
'See instruction here https://github.com/Seeed-Studio/pi_repo#mraa--upm-package-repository-for-raspberry-pi ')


def main():
# Instantiate a BMP250E instance using default i2c bus and address
sensor = sensorObj.BMM150(0, 0x13)

# For SPI, bus 0, you would pass -1 as the address, and a valid pin for CS:
# BMM150(0, -1, 10);

## Exit handlers ##
# This function stops python from printing a stacktrace when you hit control-C
def SIGINTHandler(signum, frame):
raise SystemExit

# This function lets you run code on exit
def exitHandler():
print("Exiting")
sys.exit(0)

# Register exit handlers
atexit.register(exitHandler)
signal.signal(signal.SIGINT, SIGINTHandler)

# now output data every 250 milliseconds
while (1):
sensor.update()

data = sensor.getMagnetometer()
print("Magnetometer x: {0:.2f}".format(data[0]), end=' ')
print(" y: {0:.2f}".format(data[1]), end=' ')
print(" z: {0:.2f}".format(data[2]), end=' ')
print(" uT")

xyHeading = math.atan2(data[0], data[1])
zxHeading = math.atan2(data[2], data[0])
heading = xyHeading

if heading < 0:
heading += 2*math.pi
if heading > 2*math.pi:
heading -= 2*math.pi

headingDegrees = heading * 180/(math.pi);
xyHeadingDegrees = xyHeading * 180 / (math.pi)
zxHeadingDegrees = zxHeading * 180 / (math.pi)

print('heading(axis_Y point to): {0:.2f} degree'.format(headingDegrees))
time.sleep(.250)

if __name__ == '__main__':
main()


tip
If everything goes well, you will be able to see the following result

pi@raspberrypi:~/grove.py/grove $ python3 grove_3_axis_compass_bmm150.py
Magnetometer x: -34.12 y: 36.71 z: -21.25 uT
heading(axis_Y point to): 317.10 degree
Magnetometer x: -34.49 y: 38.20 z: -16.32 uT
heading(axis_Y point to): 317.92 degree
Magnetometer x: -34.12 y: 38.20 z: -9.87 uT
heading(axis_Y point to): 318.23 degree
Magnetometer x: -32.64 y: 38.94 z: -5.69 uT
heading(axis_Y point to): 320.03 degree
Magnetometer x: -31.52 y: 38.20 z: -2.28 uT
heading(axis_Y point to): 320.47 degree
Magnetometer x: -29.67 y: 38.20 z: 0.38 uT
heading(axis_Y point to): 322.16 degree
Magnetometer x: -26.33 y: 38.20 z: 4.55 uT
heading(axis_Y point to): 325.42 degree
^CExiting


You can quit this program by simply press ++ctrl+c++.

Schematic Online Viewer

Resources

Tech Support & Product Discussion

Thank you for choosing our products! We are here to provide you with different support to ensure that your experience with our products is as smooth as possible. We offer several communication channels to cater to different preferences and needs.

Loading Comments...