Skip to content

Configuration

Everything you can set: the address, the part, the gas, the averaging, and the build options.

The driver has no configuration struct: each setting is a constructor argument or one call. Snippets are compiled from tests/docs/configuration.cpp.

Settings

Setting How Default
I2C address Constructor, SetAddress() 0x2A; must match the ADDR strap (Hardware)
Part family Constructor family Sf06; replaced once the variant is known
Variant ReadProductIdentifier(), AssumeVariant() Unknown: O2 and air only
Gas StartContinuous(gas) None; set per measurement
O2 fraction StartContinuous(mix, o2), UpdateConcentration() 0 ‰; mixtures only, 0 to 1000 ‰
Averaging ConfigureAveraging(n) 0, average-until-read; idle only; a reset restores it

Several sensors on one bus

// Two SFM4300 on one bus: ADDR to GND (0x2A) and ADDR to GND through 1.2 kOhm (0x2B).
sfm::Driver<MyI2c> inlet(i2c, sfm::addr::kSfm4300Default);
sfm::Driver<MyI2c> outlet(i2c, sfm::addr::kSfm4300Alt1);

Up to four SFM4300 share a bus, one per ADDR strap. Each driver object only holds a reference to the port, so they can share one port object. A soft reset is a general call: it resets every sensor on the bus at once.

Tell the driver which part is fitted

// The sensor is already measuring (the identifier is idle-only), and the board fits an SFM4300-20-P.
sfm::Driver<MyI2c> flow(i2c, sfm::addr::kSfm4300Default);
flow.AssumeVariant(sfm::Variant::Sfm4300_20_P);  // also sets the family (SF06)
if (!flow.Stop()) {                              // this driver did not start it, so stop it here
  return false;
}
return flow.StartContinuous(sfm::Gas::CO2).ok();

Use AssumeVariant() when the product identifier cannot be read, for example after an MCU reset while the sensor kept measuring. It sets the family too. Assume only the part the board really carries: the gas check is the only protection against reading CO2 with a table the sensor does not have.

Compile-time constants

These live in inc/sfm_commands.hpp and follow the datasheet; you do not normally change them.

Constant Value Use
sfm::timing::kFirstResultAfterStartMs 12 Wait in StartContinuous()
sfm::timing::kStopToIdleMs 1 Wait in Stop() (the sensor needs up to 0.5 ms)
sfm::timing::kAccuracySettleAfterStartMs 30 Readings before this are a few percent off
sfm::timing::kSoftResetMs 20 Wait after an SF06 soft reset (16 ms typical)
sfm::timing::kSfx6000SoftResetMs 30 Wait after an SFx6000 soft reset
sfm::timing::kMeasurementPeriodUs 500 SF06 sample period
sfm::timing::kMaxAveragingWindow 128 Largest fixed-N window
sfm::kTemperatureScalePerC 200 Temperature counts per °C
sfm::kFlowUnitSlm20C 0x0148 The SFM4300's flow unit code

Build options

Option Default Effect
HF_SFM_ENABLE_WARNINGS OFF -Wall -Wextra -Wpedantic on targets that link hf::sfm
HF_SFM_BUILD_TESTS OFF Host unit tests and documentation snippets (Testing and CI)

Next: Porting.