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
#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:
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_BMP585Creates the sensor object. Nothing is sent to the sensor until you call begin().
ReturnsThe sensor object.
Wire.begin()returns voidStarts 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_tStarts 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
| Type | Name | Description |
|---|---|---|
uint8_t | address | I2C address. BMP5_I2C_ADDR_SEC (0x47) by default; pass BMP5_I2C_ADDR_PRIM (0x46) when the ADDRESS jumper (JP3) is moved. |
TwoWire & | wirePort | The I2C bus to use. Wire by default. |
pressureSensor.setOSRODRConfig(uint8_t osrTemperature, uint8_t osrPressure, uint8_t odr, bool pressureEnable = true)returns int8_tSets 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
| Type | Name | Description |
|---|---|---|
uint8_t | osrTemperature | Temperature oversampling, BMP5_OVERSAMPLING_1X to BMP5_OVERSAMPLING_128X. |
uint8_t | osrPressure | Pressure oversampling, BMP5_OVERSAMPLING_1X to BMP5_OVERSAMPLING_128X. |
uint8_t | odr | Output 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. |
bool | pressureEnable | true (the default) measures pressure and temperature, false temperature only. |
pressureSensor.setIIRConfig(uint8_t iirTemperature, uint8_t iirPressure)returns int8_tSets the IIR low-pass filter coefficient for temperature and for pressure data.
ReturnsBMP5_OK (0) on success, a negative error code otherwise.
Parameters
| Type | Name | Description |
|---|---|---|
uint8_t | iirTemperature | BMP5_IIR_FILTER_BYPASS, or BMP5_IIR_FILTER_COEFF_1 to BMP5_IIR_FILTER_COEFF_127. |
uint8_t | iirPressure | The same choices, for pressure. |
pressureSensor.setMode(enum bmp5_powermode mode)returns int8_tSets 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
| Type | Name | Description |
|---|---|---|
bmp5_powermode | mode | BMP5_POWERMODE_STANDBY, BMP5_POWERMODE_NORMAL, BMP5_POWERMODE_FORCED, BMP5_POWERMODE_CONTINUOUS or BMP5_POWERMODE_DEEP_STANDBY. |
pressureSensor.getInterruptStatus(uint8_t *status)returns int8_tReads 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
| Type | Name | Description |
|---|---|---|
uint8_t * | status | Where 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_tReads 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.