Zum Hauptinhalt springen

Single readings in forced mode

What this example shows​

In FORCED mode the BMP585 takes one measurement when you ask for it, then goes back to sleep. That suits projects that need a reading only now and then. The sketch lowers the oversampling to 1x, bypasses the IIR filter, and then asks for one measurement per second.

Connect the breakout over I2C (3V3, GND, SDA, SCL, or a Qwiic cable). The INT pin is not needed: the sketch reads the sensor's interrupt status over I2C.

The example code​

Select Board
forcedModeCustomConfig.ino
#include <BMP585-SOLDERED.h>

// Create an instance of the BMP585 sensor
Soldered_BMP585 pressureSensor;

void setup()
{
// Initialize serial for output
Serial.begin(115200);
Serial.println("BMP585 Example - Forced Mode & Custom Config");

// Initialize I2C bus
Wire.begin();

// Check if sensor is connected and initialize it.
// Address is optional, defaults to 0x47
while (pressureSensor.begin() != BMP5_OK)
{
Serial.println("Error: BMP585 not connected, check wiring and I2C address!");
delay(1000);
}

Serial.println("BMP585 connected!");

// Lower the oversampling from the library default since forced mode is
// typically used for infrequent, quick readings. ODR is ignored in
// forced mode, but still needs to be set to a valid value
pressureSensor.setOSRODRConfig(BMP5_OVERSAMPLING_1X, BMP5_OVERSAMPLING_1X, BMP5_ODR_50_HZ);

// Bypass the IIR filter since forced mode readings aren't continuous
// enough for the filter to settle
pressureSensor.setIIRConfig(BMP5_IIR_FILTER_BYPASS, BMP5_IIR_FILTER_BYPASS);

// Trigger the first measurement
pressureSensor.setMode(BMP5_POWERMODE_FORCED);
}

void loop()
{
// Wait for the measurement to be ready
uint8_t interruptStatus = 0;
pressureSensor.getInterruptStatus(&interruptStatus);

if (interruptStatus & BMP5_INT_ASSERTED_DRDY)
{
if (pressureSensor.getSensorData() == BMP5_OK)
{
Serial.print("Pressure: ");
Serial.print(pressureSensor.pressure, 2);
Serial.print(" Pa\t");
Serial.print("Temperature: ");
Serial.print(pressureSensor.temperature, 2);
Serial.println(" degC");
}

// Trigger the next measurement
pressureSensor.setMode(BMP5_POWERMODE_FORCED);

// Only take a reading once per second
delay(1000);
}
}

Expected result:

Serial MonitorAutoscrollShow timestampNewline115200 baud
Message (Enter to send message to the board)
BMP585 Example - Forced Mode & Custom Config
BMP585 connected!
Pressure: 101308.61 Pa Temperature: 23.44 degC
Pressure: 101318.58 Pa Temperature: 23.46 degC
Pressure: 101320.98 Pa Temperature: 23.44 degC

One line arrives about every second: the pressure in pascals and the temperature in °C, each with two decimals.

Functions used​

Soldered_BMP585()returns Soldered_BMP585

Creates the sensor object. Nothing is sent to the sensor until you call begin().

ReturnsThe sensor object.

Wire.begin()returns void

Starts the Arduino Wire (I2C) library and joins the I2C bus as a controller. Call it once, before begin(). Wire comes with the Arduino core and is not part of the BMP585 library.

ReturnsNothing.

pressureSensor.begin(uint8_t address = BMP5_I2C_ADDR_SEC, TwoWire &wirePort = Wire)returns int8_t

Starts the sensor over I2C: a soft reset, a check that the BMP585 is there, then temperature oversampling 64x, pressure oversampling 4x, a 50 Hz output data rate with pressure enabled, and NORMAL power mode. The library supports I2C only.

ReturnsBMP5_OK (0) on success, a negative error code otherwise.

Parameters

TypeNameDescription
uint8_taddressI2C address. BMP5_I2C_ADDR_SEC (0x47) by default; pass BMP5_I2C_ADDR_PRIM (0x46) when the ADDRESS jumper (JP3) is moved.
TwoWire &wirePortThe I2C bus to use. Wire by default.
pressureSensor.setOSRODRConfig(uint8_t osrTemperature, uint8_t osrPressure, uint8_t odr, bool pressureEnable = true)returns int8_t

Sets the oversampling for temperature and pressure, the output data rate, and whether pressure is measured at all.

ReturnsBMP5_OK (0) on success, a negative error code otherwise.

Parameters

TypeNameDescription
uint8_tosrTemperatureTemperature oversampling, BMP5_OVERSAMPLING_1X to BMP5_OVERSAMPLING_128X.
uint8_tosrPressurePressure oversampling, BMP5_OVERSAMPLING_1X to BMP5_OVERSAMPLING_128X.
uint8_todrOutput data rate, BMP5_ODR_240_HZ down to BMP5_ODR_0_125_HZ. The example comment notes that forced mode ignores it, but it must still be a valid value.
boolpressureEnabletrue (the default) measures pressure and temperature, false temperature only.
pressureSensor.setIIRConfig(uint8_t iirTemperature, uint8_t iirPressure)returns int8_t

Sets the IIR low-pass filter coefficient for temperature and for pressure data.

ReturnsBMP5_OK (0) on success, a negative error code otherwise.

Parameters

TypeNameDescription
uint8_tiirTemperatureBMP5_IIR_FILTER_BYPASS, or BMP5_IIR_FILTER_COEFF_1 to BMP5_IIR_FILTER_COEFF_127.
uint8_tiirPressureThe same choices, for pressure.
pressureSensor.setMode(enum bmp5_powermode mode)returns int8_t

Sets the power mode. Setting BMP5_POWERMODE_FORCED starts one measurement; the sensor then returns to sleep, so set it again for the next one.

ReturnsBMP5_OK (0) on success, a negative error code otherwise.

Parameters

TypeNameDescription
bmp5_powermodemodeBMP5_POWERMODE_STANDBY, BMP5_POWERMODE_NORMAL, BMP5_POWERMODE_FORCED, BMP5_POWERMODE_CONTINUOUS or BMP5_POWERMODE_DEEP_STANDBY.
pressureSensor.getInterruptStatus(uint8_t *status)returns int8_t

Reads the sensor's interrupt status bits over I2C. Works whether or not the INT pin is wired.

ReturnsBMP5_OK (0) on success, a negative error code otherwise.

Parameters

TypeNameDescription
uint8_t *statusWhere to store the status. Test it against BMP5_INT_ASSERTED_DRDY (0x01, data ready), BMP5_INT_ASSERTED_FIFO_FULL (0x02), BMP5_INT_ASSERTED_FIFO_THRES (0x04) or BMP5_INT_ASSERTED_PRESSURE_OOR (0x08).
pressureSensor.getSensorData()returns int8_t

Reads the latest pressure and temperature from the sensor and stores them in the public members pressure (float, Pa) and temperature (float, °C).

ReturnsBMP5_OK (0) on success, a negative error code otherwise.

Putting it together​

begin() leaves the sensor in NORMAL mode with 64x and 4x oversampling. The sketch then switches to 1x oversampling with the filter bypassed and starts the first forced measurement. Each pass of loop() polls getInterruptStatus(). When the data-ready bit is set, it reads and prints the result, starts the next forced measurement with setMode(), and waits one second.