Example Code for Arduino-UART Continuous Data Reading

Last revision 2026/02/06

This article offers a comprehensive guide on using Arduino UART communication to continuously read data from the BMP585 barometric pressure sensor.

Hardware Preparation

Software Preparation

Wiring Diagram

SEN0664-UART Wiring Diagram

  • Connect the Gravity: BMP585 Barometric Pressure Sensor to the ESP32-E as illustrated, with the key wiring correspondences as follows:
    • Sensor Pin "VCC" → ESP32-E 3.3V
    • Sensor Pin "GND" → ESP32-E GND
    • Sensor UART Pin "RX" → ESP32-E D3
    • Sensor UART Pin "TX" → ESP32-E D2
    • Sensor DIP Switch Configuration: Set the communication mode to UART and the address to 0x47

Note: The setting of the communication mode DIP switch persists after power-off, and the new mode takes effect upon device restart.

Sample Code

#include "DFRobot_BMP58X.h"
#include "DFRobot_RTU.h"
#define BMP5_COMM_UART
#define CALIBRATE_ABSOLUTE_DIFFERENCE
const uint8_t ADDR = 0x47;

#if defined(BMP5_COMM_UART)
  DFRobot_BMP58X_UART bmp58x(&Serial1, 9600, ADDR, /*rx*/ D2, /*tx*/ D3);
#else
  #error "Only UART communication is supported in this configuration"
#endif

void setup() {
  Serial.begin(115200);
  while(!bmp58x.begin()){
    Serial.println("Sensor initialization failed!");
    delay(1000);
  }
// Calibrate absolute error (modify parameters according to actual altitude)
  #if defined(CALIBRATE_ABSOLUTE_DIFFERENCE)
/* This example uses an elevation of 540 meters in Wenjiang District, Chengdu. Replace it with the local elevation when in use.*/
    bmp58x.calibratedAbsoluteDifference(540.0);
  #endif

  bmp58x.setMeasureMode(bmp58x.eNormal);
}

void loop() {
  delay(1000);
  Serial.print("temp: ");
  Serial.print(bmp58x.readTempC());
  Serial.print(" (C)  press: ");
  Serial.print(bmp58x.readPressPa());
  Serial.print(" (Pa)  alt: ");
  Serial.print(bmp58x.readAltitudeM());
  Serial.println(" (M)");
}

Result

SEN0664-UART Result

Was this article helpful?

TOP