| Compass to OOPic Example Last Modified: 2006-10-31 | | |
| Acroname Robotics | |||
| ![]() 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:
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:
| |||
| 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. |