Temperature plays an import role in our every day life. We rely on it to monitor our health, food, and electronics to name a few examples. All MbientLab boards come with at least one temperature sensor, represented by the ISensor interface, and is acceesed through the ITemperature interface.

using MbientLab.MetaWear.Sensor;

ITemperature temperature = metawear.GetModule<ITemperature>();


There are 4 types of temperature sensors on the MetaWear enumerated by the SensorType enum.

Sensor Description
nRF SOC Temperature sensor on the nRF SOC
External Thermistor Separate thermistor that can be connected to the gpio pins
Bosch Env Temperature sensor from either the BMP280 or BME280 devices
Preset Thermistor Thermistor placed on the MetaWear board

All MbientLab boards, except MetaWear R, come with an NCP15XH103F03RC therimstor preset on the pcb and boards equipped with a Bosch Barometer can use the environmental unit to measure temperature as well. While the nRF SOC also has a temperature sensor, it is better use one of the other sensor types instead.

Available sensors are presented as an array returned by the Sensors property. You can also find a specific sensor using FindSensors.

using MbientLab.MetaWear.Sensor.Temperature;

// Does not work for MeteaWear R boards, use SensorType.NrfSoc
ISensor thermistor = temperature.FindSensors(SensorType.PresetThermistor)[0];

External Thermistor

Using the external thermistor requires some additional configuration before reading sensor data. After attaching the thermistor to the board, you need to tell the firmware which pins the thermistor is connected to and whether the thermistor is active high or low.

using MbientLab.MetaWear.Sensor.Temperature;

// Read data from pin 0, pulldown resistor is on pin 1, active low
(temperature.FindSensors(SensorType.ExtThermistor)[0] as IExternalThermistor).Configure(0, 1, false);

Bosch Env

There is no extra configuration needed for using the temperature sensors on the BMP280 and BME280; the only thing you need to do is start the the devices.

// only for RPro, CPro, Env, and Motion boards

Temperature Data

Temperature data is reported in Celsius and interepreted as a float value. It is represented as a forced data producer.

await temperature.Sensors[0].AddRouteAsync(source =>
    source.Stream(data => Console.WriteLine("Temperature (C) = " + data.Value<float>()))