Connecting the CMPS01/03 Compass Module to the OOPic

The compass module is connected to the OOPic via the OOPic's built in I2C
bus. You will also need a LED and a 330R resistor for this example.
To make the connections, do the following;
1. Connect pin1 (5v) to pin22 (+5v) on the OOPic 40 way connector
2. Connect pin2 (SCL) to pin3 (LSCL) on the OOPic 40 way connector
3. Connect pin3 (SDA to pin1 (LSDA) on the OOPic 40 way connector
4. Connect pin9 (0v) to pin2 (GND) on the OOPic 40 way connector
Leave the other pins unconnected for now.
5. Connect the LED cathode (shorter leg) to pin 24 on the OOPic.
6. Connect the LED anode (longer leg) to the 330R resistor.
7. Connect the other end of the 330R resistor to pin28 (I/O 30) on the
OOPic.
Circuit Schematic for connecting the OOPic to the CMPS01/CMPS03 Compass Module
The sample code below can be downloaded here cmp01.osc
' CMPS01 Compass -> OOPic Example Code ' ' This reads compass register 1, an 8 bit value representing the bearing ' as a 0 - 255 value. ' To read the value in degrees, change the Bearing from oByte to oWord ' and the .Location to 2, and the .Width to cv16bit ' Registers 2,3 are 0 - 3599 representing 0 - 359.9 degrees ' Dim Compass As New oI2C ' Create the compass objects Dim Led As New oDio1 ' Dim Bearing as new oByte ' Somewhere to store the reading Sub main() Setup ' Setup the LED and compass Do Compass.Location = 1 ' Address of single byte bearing Compass.Width = cv8bit ' Compass Data is 1-byte wide. Bearing = Compass.Value ' Get it If( (Bearing<5) Or (Bearing>250) ) Then Led = 1 Else ' Light the Led if within 5 degrees of north Led = 0 End If Loop End Sub Sub Setup() Compass.Mode = cv10bit ' I2C mode is 10-Bit Addressing. Compass.NoInc = 1 ' Don't increment Led.IOLine = 30 ' Pin 28 on 40 way connector Led.Direction = cvOutput ' End Sub |
You can find Compass Documentation Here as well as a small FAQ