
The sensor communicates using the I2C protocol with other devices, for which I'm making use of the Wire library.
You will have to include Wire.h in your sketches if you plan to use this library.
Here's an example of how to use it (assuming you have already made the electrical connections):
#include "itg3200.h"
ITG3200 gyro;
void setup(){
Serial.begin(9600);
gyro.begin(0x69); // as for SparkFun breakout, all default values
delay(1);
}
void loop(){
Serial.print("X=");
Serial.println(gyro.getX());
Serial.print("Y=");
Serial.println(gyro.getY());
Serial.print("Z=");
Serial.println(gyro.getZ());
delay(400);
}
Running this sketch will make the Arduino transmit the readings for each axis through the first serial module every 400 milliseconds.
To download the library, visit the GitHub repository.
UPDATE: This library has been updated as of January 16th, 2011.
UPDATE: This library has been updated as of January 16th, 2011.
Hi thanks for sharing this, I do encounter some problems using your code.
ReplyDeleteCode compiled after adding the wire.h
runs until the first read
it starts looping the 'while (Wire.available() ==0)'
Where are your pins declared? maybe I connected it wrong... on the duemilanove
SCL =>digital 05
SDA =>digital 04
CLK => GND
INT => not connected
GND => GND
VIO => 3.3V
VDD => 3.3V
resolved SCL SDA to analog 4 and 5 . Can i change the pin numbers? (is this in the wire lib?)
ReplyDeleteThanks Jef for commenting.
ReplyDeleteIn newer versions of Arduino IDE, including the Wire library on your own sketch is required if the custom library requires it.
As for the pin connections, you got it all right.
The datasheet instructs to connect the CLK pin to GND if you are not going to use an external clock.
VIO should be connected to the same power source as your I2C lines. (It should not never be higher than VDD)
I don't have a Duemillanove, but rather a Seeeduino Mega (which is pin compatible with the Arduino Mega).
Pin 4 and 5 cannot be changed because those are the only two pins that work with the 2-wire serial interface of the microcontroller.
Hope it helps you :)
Hi there, would you like to join forces and help us working on http://code.google.com/p/itg-3200driver/ ?
ReplyDeleteThank you,
Fabio Varesano