Example Code for Arduino-I2C Continuous Data Reading
Last revision 2026/02/05
The article outlines the process of setting up and programming an Arduino board to continuously read atmospheric pressure, temperature, and altitude using a BMP581 sensor.
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)
Other Preparation Work
- Sensor Functional Pad Configuration: I2C 0x47 (default mode, no need to modify the factory configuration)
Sample Code
#include "DFRobot_BMP58X.h"
#define BMP5_COMM_I2C
#define CALIBRATE_ABSOLUTE_DIFFERENCE
const uint8_t ADDR = 0x47;
DFRobot_BMP58X_I2C bmp58x(&Wire, ADDR);
void setup() {
Serial.begin(115200);
while(!bmp58x.begin()){
Serial.println("Sensor init fail!");
delay(1000);
}
Serial.println("Sensor init success!");
// Calibrate absolute difference (modify parameters according to actual local altitude)
#if defined(CALIBRATE_ABSOLUTE_DIFFERENCE)
/* Example uses the altitude of 540 meters in Wenjiang District, Chengdu.
Replace with your local actual altitude when deploying. */
bmp58x.calibratedAbsoluteDifference(540.0);
#endif
// Set measurement mode to Normal mode (periodic data output based on configured ODR)
bmp58x.setMeasureMode(bmp58x.eNormal);
}
void loop() {
delay(1000);
Serial.print("Temperature: ");
Serial.print(bmp58x.readTempC());
Serial.println(" °C");
Serial.print("Atmospheric Pressure: ");
Serial.print(bmp58x.readPressPa());
Serial.println(" Pa");
Serial.print("Altitude: ");
Serial.print(bmp58x.readAltitudeM());
Serial.println(" m");
Serial.println("=================================");
}
Result

Was this article helpful?
