CMPS03 Compass Module
CMPS03
Compass Module
CMPS03 connector description
This module used I2C as a protocol to communicate with MCU and use 5V for power supply.
Data from I2C is compass Bearing as a word, i.e. 0-3599 for a full circle, representing 0-359.9 degrees.
Sample Code:
/*
CMPS03 with arduino I2C example
This will display a value of 0 - 359 for a full rotation of the compass.
The SDA line is on analog pin 4 of the arduino and is connected to pin 3 of the CMPS03.
The SCL line is on analog pin 5 of the arduino and is conected to pin 2 of the CMPS03.
Both SDA and SCL are also connected to the +5v via a couple of 1k8 resistors.
A switch to callibrate the CMPS03 can be connected between pin 6 of the CMPS03 and the ground.
*/
#include <wire .h>
#define ADDRESS 0x60 //defines address of compass
void setup(){
Wire.begin(); //conects I2C
Serial.begin(9600);
}
void loop(){
byte highByte;
byte lowByte;
Wire.beginTransmission(ADDRESS); //starts communication with cmps03
Wire.write(2); //Sends the register we wish to read
Wire.endTransmission();
Wire.requestFrom(ADDRESS, 2); //requests high byte
while(Wire.available() < 2); //while there is a byte to receive
highByte = Wire.read(); //reads the byte as an integer
lowByte = Wire.read();
int bearing =((highByte<<8)+lowByte)/10;
Serial.println(bearing);
delay(100);
}
This code will get a data from module via I2C communication about degrees from 0-359.9 degrees for compass and print output to serial port. (0 is North)
Reference: Technical Specs, Sample Code

Comments
Post a Comment