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

basket

Acroname Robotics PDF webpage version Compass to BrainStem Example PDF

Related
Products

Product image for BrainStem Moto 1.0 Module
BrainStem Moto 1.0 Module
Product image for Brainstem GP 1.0 Module
Brainstem GP 1.0 Module
Product image for Devantech Compass
Devantech Compass
Product image for 4X AA Battery Pack w/Connector
4X AA Battery Pack w/Connector

Contents

Photo of interface between BrainStem GP 1.0 and Devantech Compass

Introduction

In this example, a BrainStem GP 1.0 module uses a Devantech Compass Module to gain orientation information.  The BrainStem GP 1.0 reads a 2-byte reading from the compass module and displays the result in degrees.  This example displays the output on the Console on any of the supported platforms.  A BrainStem Moto 1.0 could also be used to run the example program since it has identical I2C capabilities. 

Circuit Schematic

Schematic of the Compass to BrainStem interface

In the above schematic, the I2C bus connector on the BrainStem GP 1.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 1.0 so the only additional component needed is a bypass capacitor (C1) as outlined in the Devantech Compass Documentation .  The size of this capacitor is not critical and may not even be necessary in most cases as the BrainStem GP 1.0 has quite good surge protection in the power supply in the form of several bypass capacitors.  In this example, we used a .012 uF, 100V metal poly capacitor but anything in this range should work.  The circuit is powered by 4 NiMH AAA batteries. 

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-2008 Acroname, Inc., Boulder, Colorado. All rights reserved.