问小白 wenxiaobai
资讯
历史
科技
环境与自然
成长
游戏
财经
文学与艺术
美食
健康
家居
文化
情感
汽车
三农
军事
旅行
运动
教育
生活
星座命理

Arduino UNO测试BMP388温度气压传感器

创作时间:
作者:
@小白创作中心

Arduino UNO测试BMP388温度气压传感器

引用
CSDN
1.
https://blog.csdn.net/qq_42250136/article/details/122301966

BMP388是一款集温度和气压测量于一体的数字传感器,广泛应用于无人机和导航系统中。本文将详细介绍如何使用Arduino UNO与BMP388传感器进行连接和数据读取,包括硬件接线和软件编程的具体步骤。

BMP388传感器简介

BMP388是一个二合一数字传感器,可以测量温度和绝对大气压。由于气压随高度变化,可以非常精确地估计高度,因此对于无人机和导航应用来说非常方便。

参数
测量范围
精度
温度
-40 to 85 ºC
+/- 0.5 ºC(0 to 65 ºC)
气压
300 to 1250 hPa
绝对精度+/- 0.5hPa,相对精度+/- 0.08hPa
采样率
/
200Hz

接口说明

  • VIN-:供电正极3.3-5V
  • GND:供电负极
  • 3Vo:调压器3.3V输出
  • SCK:SPI/IIC模式时钟信号输入
  • SDI:SPI模式的MOSI数据信号的输入,IIC模式的数据信号的输入和输出
  • SDO:SPI模式的MISO数据信号的输出,IIC模式时为IIC器件地址设置引脚,接GND时器件地址为1110110(0x76),接VCC时器件地址为1110111(0x77)
  • CS:SPI模式的片选引脚,低有效输入
  • INT:中断输出高电平

BMP388与Arduino UNO接线与程序

SPI接线方式

BMP388
Arduino UNO
SCK
D13
SDI
D11
SDO
D12
CS
D10

IIC接线方式

BMP388
Arduino UNO
SCK
A5
SDI
A4

在Arduino IDE中,需要安装以下库:

  • Adafruit_BME680 library
  • Adafruit Unified Sensor

以下是示例代码:

/***************************************************************************
  This is a library for the BMP3XX temperature & pressure sensor
  Designed specifically to work with the Adafruit BMP388 Breakout
  ----> http://www.adafruit.com/products/3966
  These sensors use I2C or SPI to communicate, 2 or 4 pins are required
  to interface.
  Adafruit invests time and resources providing this open source code,
  please support Adafruit and open-source hardware by purchasing products
  from Adafruit!
  Written by Limor Fried & Kevin Townsend for Adafruit Industries.
  BSD license, all text above must be included in any redistribution
 ***************************************************************************/
#include <Wire.h>
#include <SPI.h>
#include <Adafruit_Sensor.h>
#include "Adafruit_BMP3XX.h"

#define BMP_SCK 13
#define BMP_MISO 12
#define BMP_MOSI 11
#define BMP_CS 10
#define SEALEVELPRESSURE_HPA (1013.25)

Adafruit_BMP3XX bmp;

void setup() {
  Serial.begin(115200);
  while (!Serial);
  Serial.println("Adafruit BMP388 / BMP390 test");

  // 选择I2C或SPI模式
  //if (! bmp.begin_I2C()) {   // hardware I2C mode, can pass in address & alt Wire
  //if (! bmp.begin_SPI(BMP_CS)) {  // hardware SPI mode  
  //if (! bmp.begin_SPI(BMP_CS, BMP_SCK, BMP_MISO, BMP_MOSI)) {  // software SPI mode
  if (! bmp.begin_I2C()) {
    Serial.println("Could not find a valid BMP3 sensor, check wiring!");
    while (1);
  }

  // 设置采样率和滤波系数
  bmp.setTemperatureOversampling(BMP3_OVERSAMPLING_8X);
  bmp.setPressureOversampling(BMP3_OVERSAMPLING_4X);
  bmp.setIIRFilterCoeff(BMP3_IIR_FILTER_COEFF_3);
  bmp.setOutputDataRate(BMP3_ODR_50_HZ);
}

void loop() {
  if (! bmp.performReading()) {
    Serial.println("Failed to perform reading :(");
    return;
  }

  Serial.print("Temperature = ");
  Serial.print(bmp.temperature);
  Serial.println(" *C");

  Serial.print("Pressure = ");
  Serial.print(bmp.pressure / 100.0);
  Serial.println(" hPa");

  Serial.print("Approx. Altitude = ");
  Serial.print(bmp.readAltitude(SEALEVELPRESSURE_HPA));
  Serial.println(" m");

  Serial.println();
  delay(2000);
}

打开串口监视器,即可看到传感器测量的数据。

总结

通过本实验,我们了解了BMP388传感器的基本使用方法,能够测量出温度、气压和高度等基本数据。这对于无人机、气象监测和导航系统等应用具有重要参考价值。

© 2023 北京元石科技有限公司 ◎ 京公网安备 11010802042949号