Example Code for Arduino-FIFO & Interrupt Data Reading
Last revision 2026/02/05
This guide focuses on using FIFO and interrupt read techniques in Arduino to optimize sensor data handling, covering setup, wiring, and sample code for the BMP581 barometric sensor.
FIFO Introduction
FIFO (First In, First Out) is an integrated data buffering mechanism inside the sensor. Its core feature is that data is temporarily stored here and retrieved all at once when needed, ensuring data timing consistency.
In barometric pressure sensors, FIFO serves as a temporary data storage unit, responsible for data buffering and batch processing: Temperature and pressure data collected by the sensor at the set frequency are first written to FIFO in order instead of being transmitted to the external host in real time; when data is required, the host can read all cached data in FIFO with a single operation, enabling batch acquisition.
Compared with systems without a buffering mechanism, FIFO offers significant advantages:
- Avoids bus resource occupation caused by high-frequency real-time communication, reducing system interaction overhead.
- Prevents transient data loss due to host processing delays, ensuring data integrity.
- Supports on-demand batch reading, adapting to data analysis rhythms in different scenarios.
In short, FIFO acts as a data coordination unit between the sensor and the host, optimizing data interaction efficiency and reliability through ordered buffering and batch transmission.
Continuously read pressure and temperature data using FIFO.
Hardware Preparation
- SEN0667 Fermion: BMP581 Barometric Pressure Sensor × 1
- DFR0654 FireBeetle 2 ESP32-E × 1
- Several Dupont wires
Software Preparation
- Download and install Arduino IDE: Download Link
- Download DFRobot_BMP58X Library: DFRobot_BMP58X Library
- Library Installation Guide: View Installation Tutorial
Wiring Diagram

- Connect the Fermion: BMP581 Barometric Pressure Sensor to ESP32-E as shown in the diagram. The core wiring correspondence is as follows:
- Sensor Pin "3V3" → ESP32-E 3.3V
- Sensor Pin "GND" → ESP32-E GND
- Sensor I2C Pin "SCL" → ESP32-E SCL (default GPIO22)
- Sensor I2C Pin "SDA" → ESP32-E SDA (default GPIO21)
- Sensor Pin "INT" → ESP32-E D6 (default GPIO14)
Other Preparation Work
- Sensor Functional Pad Configuration: I2C 0x47 (default mode, no need to modify the factory configuration)
Sample Code
#include "DFRobot_BMP58X.h"
#include "DFRobot_RTU.h"
#define BMP5_COMM_I2C
/* Uncomment this line if you don't need to eliminate absolute measurement error */
#define CALIBRATE_ABSOLUTE_DIFFERENCE
/**
* Configure interrupt mode: Uncomment the following macro to use latched interrupt;
* otherwise, pulsed interrupt is used.
*/
// #define BMP5_INT_MODE_LATCHED
const uint8_t ADDR = 0x47;
DFRobot_BMP58X_I2C bmp58x(&Wire, ADDR);
volatile uint8_t flag = 0;
/* Interrupt Service Routine: Set flag when triggered */
void interrupt() {
if (flag == 0) {
flag = 1;
}
}
void setup() {
Serial.begin(115200);
Serial.println("Starting..");
while (!bmp58x.begin()) {
Serial.println("Sensor initialization failed!");
delay(1000);
}
Serial.println("Sensor initialization succeeded!");
/**
* Configure FIFO parameters:
* - Data Type: Pressure + Temperature
* - Downsampling: None
* - Mode: Overwrite old data when full
* - Threshold: 2 frames (triggers interrupt when reached)
*/
bmp58x.configFIFO(
bmp58x.eFIFOPressAndTempData, // Store both pressure and temperature data
bmp58x.eNoDownSampling, // Disable downsampling (store every sample)
bmp58x.eFIFOOverwriteMode, // Overwrite mode (replace oldest data when FIFO is full)
0x02 // FIFO threshold: Trigger interrupt when 2 frames are stored
);
/**
* Configure interrupt parameters:
* - Trigger Mode: Pulsed/Latched (depends on macro definition)
* - Polarity: Active High
* - Output Type: Push-Pull
*/
#if defined(BMP5_INT_MODE_LATCHED)
bmp58x.configInterrupt(bmp58x.eIntModeLatched, bmp58x.eIntHighActive, bmp58x.eIntPushPull);
#else
bmp58x.configInterrupt(bmp58x.eIntModePulsed, bmp58x.eIntHighActive, bmp58x.eIntPushPull);
#endif
/* Set interrupt source: Trigger when FIFO reaches the threshold */
bmp58x.setIntSource(bmp58x.eIntFIFOThres);
#if defined(CALIBRATE_ABSOLUTE_DIFFERENCE)
/**
* Calibrate absolute difference using 540 meters as the reference altitude
* (Replace with your local actual altitude in practical use)
*/
bmp58x.calibratedAbsoluteDifference(540.0);
#endif
/* Set measurement mode: Normal mode (continuous measurement) */
bmp58x.setMeasureMode(bmp58x.eNormal);
/* Attach interrupt to ESP32's D6 pin (trigger on rising edge) */
attachInterrupt(digitalPinToInterrupt(D6), interrupt, RISING);
}
void loop() {
/* Latched interrupt requires reading the status register to clear the flag */
#if defined(BMP5_INT_MODE_LATCHED)
bmp58x.getIntStatus();
#endif
/* When interrupt flag is detected, read FIFO data and print */
if (flag == 1) {
DFRobot_BMP58X::sFIFOData_t data = bmp58x.getFIFOData();
Serial.print("FIFO length: ");
Serial.println(data.len);
/* Loop through and print all data in FIFO */
for(int i = 0; i < data.len; ++i){
Serial.print("Temperature: ");
Serial.print(data.fifoTempC[i]);
Serial.print(" (°C) Pressure: ");
Serial.print(data.fifoPressPa[i]);
Serial.println(" (Pa)");
}
flag = 0; // Clear the flag to wait for the next interrupt
}
}
Result

Was this article helpful?
