BMP280 Barometer

The Bmp280Barometer class is an extension of the Barometer class that interacts specifically with the BMP280 chip, the sensor on the MetaWear R Pro board.

Sensor Configuration

Sensor configuration is handled with a Bmp280Barometer.ConfigEditor. The sensor has three paremeters to set: filter mode, pressure oversampling, and standby time.

import com.mbientlab.metawear.module.Bmp280Barometer;
import com.mbientlab.metawear.module.Bmp280Barometer.*;

Bmp280Barometer bmp280Module= mwBoard.getModule(Bmp280Barometer.class);

// Set filter coefficient to 4 for IIR filter
// Set oversampling mode to low power
// Set standby time to 125ms
bmp280Module.configure()
    .setFilterMode(FilterMode.AVG_4)
    .setPressureOversampling(OversamplingMode.LOW_POWER)
    .setStandbyTime(StandbyTime.TIME_125)
    .commit();

Pressure Sampling

To start pressure sampling, call the start method, and conversely, to stop sampling, call stop. Data is interpreted as a float and reported as pascals (Pa).

import com.mbientlab.metawear.module.Bmp280Barometer;

final Bmp280Barometer bmp280Module= mwBoard.getModule(Bmp280Barometer.class);
bmp280Module.routeData().fromPressure().stream("pressure_stream").commit()
    .onComplete(new CompletionHandler<RouteManager>() {
        @Override
        public void success(RouteManager result) {
            result.subscribe("pressure_stream", new RouteManager.MessageHandler() {
                @Override
                public void process(Message msg) {
                    Log.i("MainActivity", String.format("Pressure= %.3fPa",
                            msg.getData(Float.class)));
                }
            });
            bmp280Module.start();
        }
    });

Altitude Sampling

Altitude can be computed by using the pressure data from the sensor. To enable altitude calculations along with pressure sampling, call enableAltitudeSampling method, and conversely, to disable altitude calculations, call disableAltitudeSampling. Data is interpreted as a float and reported in meters (m).

import com.mbientlab.metawear.module.Bmp280Barometer;

final Bmp280Barometer bmp280Module= mwBoard.getModule(Bmp280Barometer.class);
bmp280Module.routeData().fromAltitude().stream("altitude_stream").commit()
    .onComplete(new CompletionHandler<RouteManager>() {
        @Override
        public void success(RouteManager result) {
            result.subscribe("altitude_stream", new RouteManager.MessageHandler() {
                @Override
                public void process(Message msg) {
                    Log.i("MainActivity", String.format("Altitude= %.3fm",
                            msg.getData(Float.class)));
                }
            });
            bmp280Module.enableAltitudeSampling();
            bmp280Module.start();
        }
    });