MultiChannel Temperature

The MultiChannelTemperature class interacts with the various temperature sources on the MetaWear board. This class improves upon the older temperature module by enabling users to read temperatures from multiple sources simultaneously and is only available on firmware v1.0.4 or later.

Like the GPIO module, the temp module does not have a built in sampling function for reading temperature data, thus you will need to use the Timer module to schedule periodic reads.

Source

A temperature source is a creator of temperature data. The older MetaWear R boards have two sources: the on-die sensor from the NRF soc and an optional external thermistor that can be connected to the GPIO pins. The newer R Pro boards have an additional two sources: an internal thermistor and the sensor from the BMP280 barometer chip. You can retrieve a list of available sources on the board by calling getSources. Constants are provided in the MetaWearProChannel and MetaWearRChannel classes to index the source list returned from getSources.

Some temperature sources have some additional settings that must be configured before reading temperature data. The external thermistor source requires setting the analog read pin, pulldown pin, and active state before temperature data can be read.

import com.mbientlab.metawear.MultiChannelTemperature;
import com.mbientlab.metawear.MultiChannelTemperature.*;

import java.util.List;

MultiChannelTemperature mcTempModule= mwBoard.getModule(MultiChannelTemperature.class);
List<Source> tempSources= mcTempModule.getSources();

// configure the external thermistor settings
// read data from pin 0, pulldown on pin 1, active low
ExtThermistor extTherm= (ExtThermistor) tempSources.get(MetaWearRChannel.EXT_THERMISTOR);
extTherm.configure((byte) 0, (byte) 1, false);

Reading Temperature

To read temperature from the board, call the readTemperature method. You will need to pass in a temperature source, which can be selected from the sources provided by the getSources method. Data is interpreted as a float and reported in degrees Celsius.

// Route data from the nrf soc temperature sensor
mcTempModule.routeData()
    .fromSource(tempSources.get(MetaWearRChannel.NRF_DIE)).stream("temp_nrf_stream")
.commit().onComplete(new CompletionHandler<RouteManager>() {
    @Override
    public void sucess(RouteManager result) {
        result.subscribe("temp_nrf_stream", new MessageHandler() {
            @Override
            public void process() {
                Log.i("MainActivity", String.format("Ext thermistor: %.3fC",
                        msg.getData(Float.class)));
            }
        });

        // Read temperature from the NRF soc chip
        mcTempModule.readTemperature(tempSources.get(MetaWearRChannel.NRF_DIE));
    }
});