Temperature

All boards come with various temperature sensors that measure ambient temperature. Functions communicating with the on-board temperature sensors are defined in the multichanneltemperature.h header file.

Source Types

There are four types temperature sources providing data:

Source Description
nRF SOC Temperature sensor on the nRF SOC
External Thermistor Separate thermistor that can be connected to the gpio pins
Bosch Barometer Temperature sensor from either the BMP280 or BME280 barometers
On-board Thermistor Thermistor on the MetaWear board

The MblMwMetaWearRChannel and MblMwMetaWearRProChannel enums map the channel ids to temperature sources providing a quick way to interact with the specific temperature source if you know specifically what board you are using. The RProChannel enum can be used with all boards except the MetaWear R.

Users can also programatically check which source corresponds to each channel using the mbl_mw_multi_chnl_temp_get_source function.

#include "metawear/sensor/multichanneltemperature.h"

void list_sources(MblMwMetaWearBoard* board) {
    // print out the available temperature sources
    for (uint8_t i = 0; i < mbl_mw_multi_chnl_temp_get_num_channels(board); i++) {
        printf("channel %d -> source %d\n", i, mbl_mw_multi_chnl_temp_get_source(board, i));
    }
}

External Thermistor

External thermistors require additional configuration before they can produce reliable data. Call mbl_mw_multi_chnl_temp_configure_ext_thermistor to tell the MetaWear what GPIO pins the thermistor is connected to and whether it is active high or low.

We have a blog post on our project’s page explaining how to connect an external thermistor to the gpio pins, link here.

Bosch Barometer

Both the BMP280 and BME380 chips also measure ambient temperature. To read from these temperature sources, you will need to first start the Bosch barometer.

Boards that do not have a Bosch barometer, e.g. RG, C, and Detector boards, will always report 0C from this temperature source.

Reading Temperature

Temperature reads are manually triggered by calling mbl_mw_datasignal_read. The data is represented as a float and is in units of Celsius.

#include "metawear/core/datasignal.h"

#include "metawear/sensor/multichanneltemperature.h"

void read_temperature(MblMwMetaWearBoard* board) {
    static auto temp_handler = ;

    // Retrieve data signal for on board thermistor source
    // not valid for R boards
    auto temp_signal = mbl_mw_multi_chnl_temp_get_temperature_data_signal(board,
            MBL_MW_METAWEAR_RPRO_CHANNEL_ON_BOARD_THERMISTOR);
    mbl_mw_datasignal_subscribe(temp_signal, [](const MblMwData* data) -> void {
        // cast to float*
        printf("%.3fC\n", *((float*) data->value));
    });
    mbl_mw_datasignal_read(temp_signal);
}