Example Code for Arduino-SPI Continuous Data Reading
Last revision 2026/02/05
This article offers a comprehensive guide on using Arduino SPI communication to continuously read data from the BMP581 barometric pressure 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 the ESP32-E as illustrated, with the key wiring correspondences as follows:
- Sensor Pin "3V3" → ESP32-E 3.3V
- Sensor Pin "GND" → ESP32-E GND
- Sensor SPI Pin "SCK" → ESP32-E SCK (default GPIO18)
- Sensor SPI Pin "SDI" → ESP32-E MOSI (default GPIO23)
- Sensor SPI Pin "SDO" → ESP32-E MISO (default GPIO19)
- Sensor SPI Pin "CSB" → ESP32-E D3 (default GPIO26)
Sample Code
#include "DFRobot_BMP58X.h"
#define BMP5_COMM_SPI
#define CALIBRATE_ABSOLUTE_DIFFERENCE
//Chip Select (CS) pin definition of //SPI communication (can be modified according to actual wiring)
#define BMP5_CS_PIN D3
DFRobot_BMP58X_SPI bmp58x(&SPI, BMP5_CS_PIN);
void setup() {
Serial.begin(115200);
while(!bmp58x.begin()){
Serial.println("Sensor init fail!");
delay(1000);
}
Serial.println("Sensor init success!");
//Calibrate absolute error (modify parameters according to actual height)
#if defined(CALIBRATE_ABSOLUTE_DIFFERENCE)
/* The example uses an elevation of 540 meters in Wenjiang District, Chengdu. Please use the local elevation instead. */
bmp58x.calibratedAbsoluteDifference(540.0);
#endif
//Set the measurement mode to normal mode.
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?
