| Compass to BrainStem Example Last Modified: 2008-12-19 | | |
| Acroname Robotics | PDF webpage version | ||
| ![]() 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. ![]() 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.
Revision History:
| ||||||||||
Related Links: | |||||||||||
| voice: 720-564-0373, email: sales@acroname.com, address: 4822 Sterling Dr., Boulder CO, 80301-2350, privacy © Copyright 1994-2010 Acroname, Inc., Boulder, Colorado. All rights reserved. |