

The Grove Digital Compass is an electronic device designed to determine direction relative to the Earth's magnetic field. It utilizes magnetic sensors to provide accurate heading information, making it an essential component for navigation, orientation, and robotics applications. This compact and reliable module is ideal for projects requiring precise directional data.








The following table outlines the key technical details of the Grove Digital Compass:
| Parameter | Specification |
|---|---|
| Operating Voltage | 3.3V to 5V |
| Operating Current | < 10mA |
| Communication Protocol | I2C |
| Measurement Range | 360° (full circle) |
| Accuracy | ±1° to ±2° |
| Dimensions | 20mm x 20mm |
| Operating Temperature | -40°C to 85°C |
The Grove Digital Compass features a 4-pin interface for easy connection. The pinout is as follows:
| Pin | Name | Description |
|---|---|---|
| 1 | VCC | Power supply input (3.3V to 5V) |
| 2 | GND | Ground connection |
| 3 | SDA | I2C data line for communication |
| 4 | SCL | I2C clock line for communication |
Wire.h and Adafruit_Sensor).0x1E, but consult the datasheet to confirm.Below is an example Arduino sketch to read heading data from the Grove Digital Compass:
#include <Wire.h> // Include the Wire library for I2C communication
#define COMPASS_ADDRESS 0x1E // Default I2C address of the compass
void setup() {
Serial.begin(9600); // Initialize serial communication at 9600 baud
Wire.begin(); // Initialize I2C communication
initializeCompass(); // Call function to configure the compass
}
void loop() {
float heading = readHeading(); // Read the compass heading
Serial.print("Heading: ");
Serial.print(heading);
Serial.println("°"); // Print the heading in degrees
delay(500); // Wait for 500ms before the next reading
}
void initializeCompass() {
Wire.beginTransmission(COMPASS_ADDRESS); // Start communication with compass
Wire.write(0x00); // Select configuration register A
Wire.write(0x70); // Set measurement mode to normal
Wire.endTransmission();
Wire.beginTransmission(COMPASS_ADDRESS);
Wire.write(0x02); // Select mode register
Wire.write(0x00); // Set continuous measurement mode
Wire.endTransmission();
}
float readHeading() {
Wire.beginTransmission(COMPASS_ADDRESS);
Wire.write(0x03); // Select data output register
Wire.endTransmission();
Wire.requestFrom(COMPASS_ADDRESS, 6); // Request 6 bytes of data
if (Wire.available() == 6) {
int16_t x = (Wire.read() << 8) | Wire.read(); // Read X-axis data
int16_t z = (Wire.read() << 8) | Wire.read(); // Read Z-axis data
int16_t y = (Wire.read() << 8) | Wire.read(); // Read Y-axis data
// Calculate heading in degrees
float heading = atan2((float)y, (float)x) * 180 / PI;
if (heading < 0) heading += 360; // Ensure heading is positive
return heading;
}
return 0; // Return 0 if no data is available
}
No Data or Incorrect Readings
Inconsistent or Fluctuating Readings
I2C Communication Failure
Q: Can I use this module with a Raspberry Pi?
smbus for Python.Q: How do I calibrate the compass?
Q: What is the maximum cable length for I2C communication?
This documentation provides a comprehensive guide to using the Grove Digital Compass effectively in your projects.