Difference between revisions of "SparkFun: ITG-3200,Triple-Axis Gyro"

From eLinux.org
Jump to: navigation, search
(Bone Usage)
Line 23: Line 23:
  
 
''Note: ''There are two unpopulated resistors on the I2C lines, these can be added later by the customer if desired..
 
''Note: ''There are two unpopulated resistors on the I2C lines, these can be added later by the customer if desired..
 +
 +
=== Sample C Code ===
 +
 +
The code shown below is sample code to demonstrate reading analog output from the ADXL335.
 +
 +
<pre>
 +
/***************************************
 +
#* adxl335.c
 +
#*
 +
#* This file demonstrates the usage of the ADXL335 accelerometer.
 +
#*
 +
#* With the proper accelerometer axis inputs defined below,
 +
#* this application will output and constantly update the readings
 +
#* from the accelerometer
 +
#*
 +
***************************************/
 +
 +
#include <stdio.h>
 +
#include <stdlib.h>
 +
#include <signal.h>
 +
#include <sys/time.h>
 +
 +
#define ANINX 7
 +
#define ANINY 3
 +
#define ANINZ 1
 +
 +
int keepGoing = 1;
 +
 +
void signal_handler(int sig)
 +
{
 +
printf( "Ctrl-C pressed, cleaning up and exiting..\n" );
 +
keepGoing = 0;
 +
}
 +
 +
/*
 +
* int read_anin(char * fileName)
 +
*
 +
* The argument is the fileName instead of the integer because this will be called a lot for only 3 filenames,
 +
* so we want to save ourselves the work of constructing the filename each time.
 +
*
 +
*/
 +
int read_anin(char * fileName){
 +
FILE *fp;
 +
char readValue[5];
 +
 +
if ((fp = fopen(fileName,  "r")) == NULL) {
 +
printf("Cannot open anin file: %s.\n", fileName);
 +
exit(1);
 +
}
 +
 +
//Set pointer to begining of the file
 +
rewind(fp);
 +
//Write our value of "out" to the file
 +
fread(readValue, sizeof(char), 10, fp);
 +
readValue[4] = '\0'; //for some reason when reading 4 digit numbers you get weird garbage after the value
 +
fclose(fp);
 +
 +
return atoi(readValue);
 +
}
 +
 +
int main(int argc, char **argv, char **envp){
 +
int i;
 +
 +
char fileNameX[50], fileNameY[50], fileNameZ[50];
 +
sprintf(fileNameX, "/sys/devices/platform/omap/tsc/ain%d", ANINX);
 +
sprintf(fileNameY, "/sys/devices/platform/omap/tsc/ain%d", ANINY);
 +
sprintf(fileNameZ, "/sys/devices/platform/omap/tsc/ain%d", ANINZ);
 +
 +
signal(SIGINT, signal_handler);
 +
 +
while(keepGoing){
 +
printf("X: %d | Y: %d | Z: %d\r", read_anin(fileNameX), read_anin(fileNameY), read_anin(fileNameZ));
 +
usleep(10000);
 +
}
 +
 +
 +
}
 +
</pre>
 +
 +
This code can be compiled with the command ''gcc adxl335.c -o adxl335''
 +
  
 
== Features ==
 
== Features ==

Revision as of 15:50, 25 September 2012


Overview

The ADXL335 is a three-axis accelerometer that can be purchased from SparkFun. The datasheet describes it:

The ITG-3200 is the world’s first single-chip, digital-output, 3-axis MEMS gyro IC optimized for gaming, 3D mice, and 3D remote control applications. The part features enhanced bias and sensitivity temperature stability, reducing the need for user calibration. Low frequency noise is lower than previous generation devices, simplifying application development and making for more-responsive remote controls.

Inputs and Outputs

The ITG-3200 takes a supply voltage (Vs) of 1.8-3.6 V. The analog outputs are scaled proportionally to the supply voltage; at Vs = 3.6 V, the output will change by 2x for the same acceleration as compared to Vs = 1.8 V. Although the output sensitivity is scaled proportionally to the input voltage, noise is not, so higher supply voltages are advisable to reduce the impact of noise.

At all supply voltages, 0 g acceleration corresponds to an output voltage of Vs/2. At Vs = 3.6 V, the datasheet specs the typical sensitivity at 360 mV / g, with g as standard gravitational acceleration.

Bone Usage

Because the ITG-3200 has and I2C port, data can be read into the Bone via the I2C buss pins. One sets of I2C buss pins are required, for the X, Y, Z, and temperature outputs on the gyro. Here we will use the ITG300.h (This header also imports the i2c-dev.h and errno.h automatically, these are necessary to poll the device later on). See the picture on the right for an example wiring configuration.

"
File:ABone.jpg
Wiring example for ITG-3200 on a Bone
"

Note: There are two unpopulated resistors on the I2C lines, these can be added later by the customer if desired..

Sample C Code

The code shown below is sample code to demonstrate reading analog output from the ADXL335.

/***************************************
#* adxl335.c
#* 
#* This file demonstrates the usage of the ADXL335 accelerometer.
#* 
#* With the proper accelerometer axis inputs defined below, 
#* this application will output and constantly update the readings
#* from the accelerometer
#*
***************************************/

#include <stdio.h>
#include <stdlib.h>
#include <signal.h>
#include <sys/time.h>

#define ANINX 7
#define ANINY 3
#define ANINZ 1

int keepGoing = 1;

void signal_handler(int sig)
{
	printf( "Ctrl-C pressed, cleaning up and exiting..\n" );
	keepGoing = 0;
}

/*
*	int read_anin(char * fileName)
*
*	The argument is the fileName instead of the integer because this will be called a lot for only 3 filenames,
*	so we want to save ourselves the work of constructing the filename each time.
*
*/
int read_anin(char * fileName){
	FILE *fp;
	char readValue[5];

	if ((fp = fopen(fileName,  "r")) == NULL) {
		printf("Cannot open anin file: %s.\n", fileName);
		exit(1);
	}

	//Set pointer to begining of the file
	rewind(fp);
	//Write our value of "out" to the file
	fread(readValue, sizeof(char), 10, fp);
	readValue[4] = '\0'; //for some reason when reading 4 digit numbers you get weird garbage after the value
	fclose(fp);

	return atoi(readValue);
}

int main(int argc, char **argv, char **envp){
	int i;

	char fileNameX[50], fileNameY[50], fileNameZ[50];
	sprintf(fileNameX, "/sys/devices/platform/omap/tsc/ain%d", ANINX);
	sprintf(fileNameY, "/sys/devices/platform/omap/tsc/ain%d", ANINY);
	sprintf(fileNameZ, "/sys/devices/platform/omap/tsc/ain%d", ANINZ);
	
	signal(SIGINT, signal_handler);

	while(keepGoing){
		printf("X: %d | Y: %d | Z: %d\r", read_anin(fileNameX), read_anin(fileNameY), read_anin(fileNameZ));
		usleep(10000);
	}
	
	
}

This code can be compiled with the command gcc adxl335.c -o adxl335


Features

Digital-output X-, Y-, and Z-Axis angular rate sensors (gyros) on one integrated circuit Digitally-programmable low-pass filter Low 6.5mA operating current consumption for long battery life Wide VDD supply voltage range of 2.1V to 3.6V Standby current: 5μA Digital-output temperature sensor Fast Mode I2C (400kHz) serial interface Optional external clock inputs of 32.768kHz or 19.2MHz to synchronize with system clock Pins broken out to a breadboard friendly 7-pin 0.1" pitch header

Dimensions

0.70 x 0.55" (17.78 x 13.97mm)

Documents

Schematic

Eagle Files

Quickstart Guide

ITG-3200 Datasheet

Code (ATmega328)

Example