Compass to OOPic Example
Last Modified: 2006-10-31
find:

basket

Acroname Robotics  

Related
Products

Product image for Devantech Compass
Devantech Compass

Contents

Introduction

In this example, an OOPic module uses a Devantech Compass Module to gain orientation information.  The OOPic reads a 1-byte, 255-step compass reading representing one full revolution in headings from the compass module. 

The compass module is connected to the OOPic via the OOPic's built-in I2C bus.  You will also need a LED and a 330ohm resistor for this example.  To make the connections, do the following steps in the order:

  • Connect pin1 (5v) to pin22 (+5v) on the OOPic 40 way connector. 
  • Connect pin2 (SCL) to pin3 (LSCL) on the OOPic 40 way connector. 
  • Connect pin3 (SDA to pin1 (LSDA) on the OOPic 40 way connector. 
  • Connect pin9 (0v) to pin2 (GND) on the OOPic 40 way connector.  Leave the other pins unconnected for now. 
  • Connect the LED cathode (shorter leg) to pin 24 on the OOPic. 
  • Connect the LED anode (longer leg) to the 330R resistor. 
  • Connect the other end of the 330R resistor to pin28 (I/O 30) on the OOPic. 

Circuit Schematic

Source Code

' compass-2.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.Node = 96 ' Decimal of Hex address 0xC0 shifted right by 1 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

Revision History:

  • 2001-07-16: Example Created.
 
 
voice: 720-564-0373, email: sales@acroname.com, address: 4822 Sterling Dr., Boulder CO, 80301-2350, privacy
© Copyright 1994-2012 Acroname, Inc., Boulder, Colorado. All rights reserved.