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接线与程序

BMP388 SPI接线方式 IIC接线方式
SCK D13 A5
SDI D11 A4
SDO D12 /
CS D10 /

IIC接线方式
在这里插入图片描述
Arduino IDE库管理器安装 Adafruit_BME680 library
在这里插入图片描述
Arduino IDE库管理器安装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");

  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
    Serial.println("Could not find a valid BMP3 sensor, check wiring!");
    while (1);
  }

  // Set up oversampling and filter initialization
  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传感器的基本使用,测量出温度、气压、高度基本数据。

猜你喜欢

转载自blog.csdn.net/qq_42250136/article/details/122301966