German English
Sensors

ITG3200 - Read gyro sensor values to track motions

The microcontroller on the radio module Preon32 has several IO interfaces which allows accessing nearly each kind of sensor. The product VariSen which is designed for use with Preon32 contains some sensors, the ITG3200 included.

This examples shows how to access an ITG3200 sensor via the I2C interface. The program reads the gyro sensor values each second and prints it out. Accessing this sensor is very easy because Virtenio provides a driver for it.
/*
 * Copyright (c) 2011., Virtenio GmbH
 * All rights reserved.
 */
package com.virtenio.webdemo.sensor;

import com.virtenio.drivers.i2c.NativeI2C;
import com.virtenio.drivers.sensors.i2c.ITG3200;

import java.io.IOException;

public class GyrosScope {

    public static void main(String[] args) throws IOException, InterruptedException {

        // open Native I2C Bus
        NativeI2C i2c = NativeI2C.getInstance(1);
        i2c.open();

        // initialise ITG3200 sensor
        ITG3200 gyroSensor = new ITG3200(i2c, ITG3200.ADDR_L, null);

        while (true) {
            // get gyro values
            short[] ch = new short[3];
            gyroSensor.getGyroRaw(ch, 0);
            System.out.println("Motion " +
                               "CH[0]:" + ch[0] + " " +
                               "CH[1]:" + ch[1] + " " +
                               "CH[2]:" + ch[2]);
            Thread.sleep(1000);
        }
    }
}