Still Nicla Sense ME BSEQ data problems

There are already answers about how to get BSEQ IAQ values by increasing SENSOR_DATA_FIXED_LENGTH in SensorTypes.h.

Unfortunately this only works for the LEGACY ID (115) and only for IAQ but not for the current one (171).

Is there any update on how to get the BSEQ data working with all values (including CO2)?

Here's the code i am using with the latest Arduino_BHY2 library (1.0.6):

#include "Arduino.h"
#include "Arduino_BHY2.h"

Sensor gas(SENSOR_ID_GAS);
SensorBSEC bsec(SENSOR_ID_BSEC);  //_LEGACY);

void setup() {
  Serial.begin(115200);
  while (!Serial)
    ;

  BHY2.begin();
  gas.begin();
  bsec.begin();
}

void loop() {
  static auto printTime = millis();

  // Update function should be continuously polled
  BHY2.update();

  if (millis() - printTime >= 1000) {
    printTime = millis();
    Serial.println(String("gas: ") + String(gas.value(), 3));
    Serial.println(String("bseq: ") + String(bsec.toString()));
  }
}

Console output:

14:54:58.375 -> gas: 10121.000
14:54:58.375 -> bseq: BSEC output values - iaq: 0   iaq_s: 0   b_voc_eq: 0.00   co2_eq: 0   accuracy: 0   comp_t: 0.00   comp_h: 0.00   comp_g: 0
14:54:58.407 -> 
14:54:59.398 -> gas: 10273.000
14:54:59.398 -> bseq: BSEC output values - iaq: 0   iaq_s: 0   b_voc_eq: 0.00   co2_eq: 0   accuracy: 0   comp_t: 0.00   comp_h: 0.00   comp_g: 0
14:54:59.398 -> 

I finally got it working. There were some details missing in the previous suggestions.

Solution:

  1. Open the file /libraries/Arduino_BHY2/src/sensors/SensorTypes.h in a text editor.
  2. Change both following values to 30
    #define SENSOR_DATA_FIXED_LENGTH (30)
    #define SENSOR_LONG_DATA_FIXED_LENGTH (30)
  3. Initialize the BSEC sensor in your Arduino code via the legacy ID
    SensorBSEC bsec(SENSOR_ID_BSEC_LEGACY);

Code:

#include "Arduino.h"
#include "Arduino_BHY2.h"

Sensor gas(SENSOR_ID_GAS);
SensorBSEC bsec(SENSOR_ID_BSEC_LEGACY);

void setup() {
  Serial.begin(115200);
  while (!Serial)
    ;

  BHY2.begin();
  gas.begin();
  bsec.begin();
}

void loop() {
  static auto printTime = millis();

  // Update function should be continuously polled
  BHY2.update();

  if (millis() - printTime >= 1000) {
    printTime = millis();
    Serial.println(String("gas: ") + String(gas.value(), 3));
    Serial.println(String("bseq: ") + String(bsec.toString()));
  }
}

Output:

21:55:54.075 -> gas: 11170.000
21:55:54.075 -> bseq: BSEC output values - iaq: 64   iaq_s: 42   b_voc_eq: 0.65   co2_eq: 568   accuracy: 1   comp_t: 27.25   comp_h: 29.08   comp_g: 4