Skip to main content

Read on the data-ready interrupt

What this example shows​

Instead of asking the sensor over and over, the controller waits for the BMP585's INT pin. The sensor pulses INT high each time a new reading is ready, and only then does the sketch read and print it. With the 50 Hz rate begin() sets, that is a new line about every 20 ms.

Connect the breakout over I2C as in the Quick Start, and wire the breakout's INT pin to pin 2 of your controller. To use another pin, change interruptPin.

The example code​

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

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

// Pin connected to the sensor's INT pin, change to match your wiring
int interruptPin = 2;

// Flag to know when an interrupt occurs
volatile bool interruptOccurred = false;

void bmp585InterruptHandler()
{
interruptOccurred = true;
}

void setup()
{
// Initialize serial for output
Serial.begin(115200);
Serial.println("BMP585 Example - Data Ready Interrupt");

// 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!");

// Configure the interrupt pin as push/pull, active high, pulsed
pressureSensor.configureInterrupt(BMP5_PULSED, BMP5_ACTIVE_HIGH, BMP5_INTR_PUSH_PULL, true);

// Only assert the pin on a new data-ready reading
pressureSensor.setInterruptSource(true);

// Attach the interrupt handler to the microcontroller pin wired to INT
attachInterrupt(digitalPinToInterrupt(interruptPin), bmp585InterruptHandler, RISING);
}

void loop()
{
if (interruptOccurred)
{
interruptOccurred = false;

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");
}
}
}

Expected result:

Serial MonitorAutoscrollShow timestampNewline115200 baud
Message (Enter to send message to the board)
BMP585 Example - Data Ready Interrupt
BMP585 connected!
Pressure: 101318.94 Pa Temperature: 23.44 degC
Pressure: 101314.99 Pa Temperature: 23.44 degC
Pressure: 101317.14 Pa Temperature: 23.45 degC
Pressure: 101319.16 Pa Temperature: 23.44 degC

One line arrives per interrupt: the pressure in pascals and the temperature in °C, each with two decimals. If BMP585 connected! appears but no readings follow, the controller is not seeing INT: check that wire and interruptPin.

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.configureInterrupt(enum bmp5_intr_mode mode, enum bmp5_intr_polarity pol, enum bmp5_intr_drive drive, bool enable)returns int8_t

Sets how the INT pin behaves and turns it on or off. It does not choose which event drives the pin; setInterruptSource() does that.

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

Parameters

TypeNameDescription
bmp5_intr_modemodeBMP5_PULSED or BMP5_LATCHED. The example uses pulsed.
bmp5_intr_polaritypolBMP5_ACTIVE_LOW or BMP5_ACTIVE_HIGH. The example uses active high, so the pin rises on an event.
bmp5_intr_drivedriveBMP5_INTR_PUSH_PULL or BMP5_INTR_OPEN_DRAIN.
boolenabletrue to enable the INT pin, false to disable it.
pressureSensor.setInterruptSource(bool dataReady, bool fifoFull = false, bool fifoThreshold = false, bool pressureOOR = false)returns int8_t

Chooses which events drive the INT pin. Call configureInterrupt() first.

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

Parameters

TypeNameDescription
booldataReadyA new pressure and temperature reading is ready. The example passes true.
boolfifoFullThe FIFO buffer is full. false by default.
boolfifoThresholdThe FIFO watermark is reached. false by default.
boolpressureOORPressure is out of range. false by default.
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.

digitalPinToInterrupt(pin)returns int

Checks that a controller pin can be used for an interrupt, for passing to attachInterrupt(). It is part of the Arduino core, not the BMP585 library.

ReturnsThe pin when it can be used for an interrupt, -1 when it cannot.

Parameters

TypeNameDescription
intpinThe controller pin wired to INT. The example passes interruptPin (2).
attachInterrupt(digitalPinToInterrupt(pin), ISR, mode)returns void

Runs the function ISR whenever the pin changes the way mode says. The ISR takes no parameters, returns nothing and should be short. It is part of the Arduino core, not the BMP585 library.

ReturnsNothing.

Parameters

TypeNameDescription
intdigitalPinToInterrupt(pin)The pin wired to INT, passed through digitalPinToInterrupt().
functionISRThe function to call. The example passes bmp585InterruptHandler.
constantmodeLOW, CHANGE, RISING or FALLING. The example uses RISING, since INT is set to active high.

Putting it together​

configureInterrupt() makes INT a push-pull, active-high pulse, and setInterruptSource(true) lets only the data-ready event drive it. The Arduino core's attachInterrupt() then runs bmp585InterruptHandler() on each rising edge of the controller's pin. The handler only sets a flag; loop() sees the flag, clears it and calls getSensorData(), so the I2C traffic stays out of the interrupt routine.