German English

ADT7410 - Read temperatur values from the ADT7410 sensor

The microcontroller on the radio module Preon32 has several IO interfaces. This interfaces allows accessing nearly all sensors. The product VariSen, which is designed for use with Preon32, contains some sensors, the ADT7410 included.

This examples shows how to access an ADT7410 sensor using an I2C interface. The sensor is configured to produce values continuously and the program reads values each second and prints it out.
 * Copyright (c) 2011., Virtenio GmbH
 * All rights reserved.
package com.virtenio.webdemo;

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


public class TemperatureI2C {

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

        // define
        NativeI2C i2c = null;               // native I2C
        ADT7410 temperatureSensor = null;   // driver for temperture sensor
        i2c = NativeI2C.getInstance(1);     // get i2c instance 1;                         // open i2c for r/w-access
        // create instance and set address
        temperatureSensor = new ADT7410(i2c, ADT7410.ADDR_0, null, null);
        temperatureSensor.setMode(ADT7410.CONFIG_MODE_CONTINUOUS);// set continuous mode

        // capture samples
        while (true) {
            int raw = temperatureSensor.getTemperatureRaw();      // read raw value
            float celsius = temperatureSensor.getTemperatureCelsius();// read celsius
            System.out.println("raw=" + raw + "; " + celsius + " [°C]");// print to screen
            Thread.sleep(1000);                                         // sample period