Compass to BrainStem Example
Last Modified: 2008-12-19
find:

basket

Acroname Robotics PDF webpage version Compass to BrainStem Example PDF

Related
Products

Product image for BrainStem GP 2.0
BrainStem GP 2.0
Product image for 2600mAh AA NiMH Battery
2600mAh AA NiMH Battery
Product image for Devantech Compass
Devantech Compass
Product image for 3 Conductor Cable w/ Connector
3 Conductor Cable w/ Connector
Product image for 4X AA Battery Pack w/Connector
4X AA Battery Pack w/Connector
Product image for 35 Crimps and various housings
35 Crimps and various housings

Contents

Photo of interface between BrainStem GP 1.0 and Devantech Compass

Introduction

In this example, a BrainStem GP 2.0 module uses a Devantech Compass Module to gain orientation information.  The BrainStem GP 2.0 reads a 2-byte reading from the compass module and displays the result in degrees.  This example displays the output on the Console application. 

Circuit Schematic

In the following schematic, the I2C bus connector on the BrainStem GP 2.0 is tied directly to the I2C connections on the compass module.  The pull-up resistors required on the I2C bus are incorporated into the BrainStem GP 2.0.  The circuit is powered by 4 NiMH AA batteries, but a wide range of DC power sources can be used since the BrainStem regulates the power to the compass. 

Schematic of the Compass to BrainStem interface

Source Code

This code uses the TEA language which is very similar to ANSI C.  It is compiled using the BrainStem Console with the steep command.  The code gets a reading as a 2-byte integer value and then formats it to display on the BrainStem Console in decimal format including the decimal point in 0.1 degree increments. 

#include <aCore.tea> #include <aPrint.tea> #include <aCompass.tea> void main () { int reading; while (1) { reading = aCompass_ReadInt(); aPrint_IntDec(reading / (int)10); aPrint_Char('.'); aPrint_IntDec(reading % (int)10); aPrint_String(" degrees\n"); aCore_Sleep(10000); } /* while (1) */ } /* main */

This program utilizes the built-in library for handling Devantech Compasses.  The program takes continuous readings using the aCompass_ReadInt command.  There is also a aCompass_ReadChar command should you only need 256 steps in the full 360 degree range of the compass. 

Note:

The CMPS03 compass cannot handle a 1MBit or 400Khz I2C data rate.  The TEA compass functions automatically set the IIC baud rate to 100kb to take a reading then restore the baud rate to its previous value when finished. 

Revision History:

  • 2001-07-16: Created
  • 2002-01-11: Updated for compatibility with Build 5 Software
  • 2003-10-28: Updated with info for baud and module compatibility
 

Related Links:

Brainstem Software: Console Overview

voice: 720-564-0373, email: sales@acroname.com, address: 4822 Sterling Dr., Boulder CO, 80301-2350, privacy
© Copyright 1994-2009 Acroname, Inc., Boulder, Colorado. All rights reserved.