Using the I2C Bus for Connecting the CMPS03 to the Basic Atom

Introduction
The compass module uses either a PWM output or the I2C bus for communications.
This example uses the I2C Bus. The SDA
(data) and SCL (clock) lines are connected to pins 13 and 14 on the Basic
Atom. These are arbitrarily chosen,
you can use any pins you choose to. The example presented here uses the Basic
Atoms I2CIN command to read the compass bearing in a single line of code. A push button for calibration connected to pin
6 on the Compass module. Refer to calibration for
further information on calibrating the compass module.
The Basic Atom internal 5v regulator is not suitable for powering much external
circuitry. I therefore recommend you use a separate 5v regulator.
Note - the CMPS01 cannot be used with the Basic Atom. This is because the
Atom's I2C commands do not appear to implement the I2C bus hold feature.
Circuit Schematic for connecting the Basic Atom to the CMPS03 Compass Module using the I2C bus

Note the switch connecting pin 6 on the compass module to Ground . This is all that is needed for calibration.
Software
The sample code below displays the compass bearing as Degrees (0-359) in a
Terminal window on the PC.
It can be downloaded here
| '*********************************************************** '** ** '** CMPS03 Demonstration Software for the Basic Atom ** '** ** '** Copyright 2002 - Devantech Ltd ** '** Commercial use of this software is prohibited ** '** Private and educational use only is permitted ** '** ** '** Written by Gerald Coe - April 2002 ** '** ** '*********************************************************** SDA Con P8 ' Define Data pin SCL Con P9 ' Define Clk pin Compass Con 0xC0 ' Compass I2C Address CmdReg Con 0 ' Sonar Command register BearingReg Con 2 ' Sonar 1st Range register Bearing Var Word ' 16 bit variable for Bearing Main |
You can find Compass Documentation Here as well as a small FAQ