🛠 Lire température et gaz avec le BME688
Objectives
Read environment sensors from the Nicla Sense ME via the Arduino_BHY2 library. An important point, which is a source of many errors on forums and third-party datasheets: this board does not embed a BME680 but a BME688 (U6), a new-generation Bosch gas-sensitive sensor (eNose) that also measures temperature, humidity, and pressure; it is not read directly via I²C bit-banging as on a classic shield, but served by the BHI260AP sensor hub, which acts as the bus master. Therefore, we use virtual sensors identified by SENSOR_ID_TEMP (ID 128) and SENSOR_ID_GAS (ID 131), and the message pump BHY2.update, which must be called continuously.
Hardware
- Arduino Nicla Sense ME board (ABX00050) and micro-USB cable
- Arduino IDE with the "Arduino Mbed OS Nicla Boards" pack and the "Arduino_BHY2" library installed via the library manager
- >
Complete Code
#include "Arduino.h"
#include "Arduino_BHY2.h"
Sensor temp(SENSOR_ID_TEMP); // ID 128 : temperature du BME688
Sensor gas(SENSOR_ID_GAS); // ID 131 : resistance gaz du BME688
void setup {
Serial.begin(115200);
while (!Serial);
BHY2.begin; // demarre l'interface avec le hub BHI260AP
temp.begin;
gas.begin;
}
void loop {
static auto printTime = millis;
BHY2.update; // OBLIGATOIRE : pompe les donnees du hub
if (millis - printTime >= 1000) {
printTime = millis;
if (temp.dataAvailable) {
Serial.println(String("Temperature : ") + String(temp.value, 2) + " C");
temp.clearDataAvailFlag;
}
if (gas.dataAvailable) {
Serial.println(String("Gaz : ") + String(gas.value, 0) + " ohms");
gas.clearDataAvailFlag;
}
}
}
Expected Verification
One temperature line and one gas resistance line are displayed every second. Blow on the board or bring it close to a heat source: the temperature changes within a few seconds. The gas resistance takes several minutes to stabilize upon startup (conditioning of the metal oxide layer, typical measurement cycle 10.8 s); very high values at the beginning are normal.
Common Errors
- Forgetting
BHY2.updatein loop: no virtual sensor ever receives data,dataAvailableremains false indefinitely. - Expecting a BME680 sensor and looking for an I²C address 0x76/0x77: the BME688 is not exposed directly; it is a slave of the BHI260AP.
- A too verbose reading loop without timing: the serial monitor saturates; we limit the display to 1 Hz as shown above.
- Confusing gas resistance with air quality index: for a usable IAQ, you need the SensorBSEC class (see advanced tutorials) rather than the raw resistance.
Other tutorials for this board
Code examples for this board
led_rgb.inoArduinoimu_bhi260.inoArduinorotation_fusion.inoArduinopression_bmp390.inoArduinonose_electronique.inoArduinoboussole_bmm150.inoArduino