German English

MPL115A2 - Read air pressure values from a MPL115A2 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 MPL115A2 included.

This examples shows how to access a MPL115A2 sensor using an I2C interface. The sensor is configured to produce values continuously and the program reads the pressure values each second and prints it out. Accessing this sensor is 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.gpio.GPIO;
import com.virtenio.drivers.gpio.NativeGPIO;
import com.virtenio.drivers.i2c.NativeI2C;
import com.virtenio.drivers.sensors.i2c.MPL115A2;


public class PressureI2C {

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

        NativeI2C i2c = NativeI2C.getInstance(1);;
        GPIO resetPin = NativeGPIO.getInstance(24);
        GPIO shutDownPin = NativeGPIO.getInstance(12);

        MPL115A2 pressureSensor = new MPL115A2(i2c, resetPin, shutDownPin);

        while (true) {
            // capture measured value every 1000ms
            int pressurePr = pressureSensor.getPressureRaw();
            System.out.println("MPL115A2 rawP=" + pressurePr);
            Thread.sleep(1000 - MPL115A2.BOTH_CONVERSION_TIME);