Wednesday, October 27, 2010

ITG-3200 Gyroscope Library for Arduino

Here's the first revision of a library I made for the ITG-3200 3-Axis Gyroscope made by Invensense.

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(){
gyro.begin(0x69); // as for SparkFun breakout, all default values

void loop(){

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.


  1. Hi thanks for sharing this, I do encounter some problems using your code.
    Code 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

  2. resolved SCL SDA to analog 4 and 5 . Can i change the pin numbers? (is this in the wire lib?)

  3. Thanks Jef for commenting.

    In 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 :)

  4. Hi there, would you like to join forces and help us working on ?

    Thank you,

    Fabio Varesano