German English
Sensors

BH1710FVC - Read light values from BH1710FVC light sensor

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 BH1710FVC included.

This examples shows how to access a BH1710FVC sensor. The program reads the light 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;

import com.virtenio.drivers.gpio.NativeGPIO;
import com.virtenio.drivers.i2c.NativeI2C;
import com.virtenio.drivers.sensors.i2c.BH1710FVC;

import java.io.IOException;

public class LightI2C {

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

        // The GPIO pin for the DVI signal.
        NativeGPIO dvi = NativeGPIO.getInstance(10);

        // The i2c bus connected to BH1715FVC
        NativeI2C i2c = NativeI2C.getInstance(1);
        i2c.open();

        // initialise BH1715FVC
        BH1710FVC lightsensor = new BH1710FVC(i2c, BH1710FVC.ADDR_L, null, dvi);
        lightsensor.enable(true);
        lightsensor.setPowerMode(BH1710FVC.POWER_ON);
        lightsensor.setSamplingMode(BH1710FVC.CONT_HRES_MODE);

        // capture measured value every 1000ms
        while (true) {
            int raw = lightsensor.getValueLx();
            int lx = BH1710FVC.convertRawToLx(raw);
            System.out.println("BH1710FVC: raw=" + raw + "; " + lx + " [lx]");
            Thread.sleep(1000);
        }
    }
}