ESP32-S3 控制 BMP280气压传感器
ESP32-S3 BMP280气压传感器模块实验 —— 气压、温度、高度检测
本实验通过 ESP32-S3 与 BMP280模块 实现气压、温度及高度的检测,并在串口监视器输出检测结果。
一、实验名称
BMP280气压传感器模块实验
二、接线说明
| BMP280模块 | ESP32-S3 引脚 |
|---|---|
| VCC | 3V3 |
| GND | GND |
| SCK | 13 |
| SDI (MOSI) | 11 |
| SDO (MISO) | 12 |
| CSB | 10 |
三、实验现象
- 程序下载成功后,串口监视器会周期性输出 BMP280 检测到的 温度 (°C)、气压 (Pa) 和高度 (m) 值。
四、注意事项
-
需要导入以下库:
Adafruit_BusIO-1.14.5.zipAdafruit_BMP280_Library-2.6.8.zipAdafruit_Unified_Sensor-1.1.14.zip
-
可参考压缩包解压后的 examples 使用方法。
五、完整代码示例
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_BMP280.h>
#define BMP_SCK 13
#define BMP_MISO 12
#define BMP_MOSI 11
#define BMP_CS 10
// 初始化 BMP280 模块(硬件 SPI 模式)
Adafruit_BMP280 bmp(BMP_CS, BMP_MOSI, BMP_MISO, BMP_SCK);
void setup() {
Serial.begin(9600);
while (!Serial) delay(100); // 等待串口打开
Serial.println(F("BMP280 test"));
unsigned status;
status = bmp.begin();
if (!status) {
Serial.println(F("Could not find a valid BMP280 sensor, check wiring or try a different address!"));
Serial.print("SensorID was: 0x"); Serial.println(bmp.sensorID(), 16);
while (1) delay(10);
}
// 默认采样设置
bmp.setSampling(Adafruit_BMP280::MODE_NORMAL, /* Operating Mode */
Adafruit_BMP280::SAMPLING_X2, /* Temp. oversampling */
Adafruit_BMP280::SAMPLING_X16, /* Pressure oversampling */
Adafruit_BMP280::FILTER_X16, /* Filtering */
Adafruit_BMP280::STANDBY_MS_500); /* Standby time */
}
void loop() {
Serial.print(F("Temperature = "));
Serial.print(bmp.readTemperature());
Serial.println(" *C");
Serial.print(F("Pressure = "));
Serial.print(bmp.readPressure());
Serial.println(" Pa");
Serial.print(F("Approx altitude = "));
Serial.print(bmp.readAltitude(1013.25)); // 根据本地气压调整
Serial.println(" m");
Serial.println();
delay(2000);
}

浙公网安备 33010602011771号