BME680简介
BME680是一个四合一数字环境检测传感器,可以测量所处周围环境的温度、湿度、气压、有机挥发性化合物(VOC)。其内部的金属氧化物敏感元件用于测量空气中的VOCs,不同VOCs浓度下金属氧化物表面的电导率不一样从而输出不同的电阻值。这个传感器能给到一个关于周围空气中VOCs/污染物之和的定性概念,而不是特定的气体分子。
敏感元件 | 测量范围 | 精度 |
---|---|---|
温度 | -40 to 85 ºC | +/- 1.0 ºC |
湿度 | 0 to 100 % | +/- 3 % |
气压 | 300 to 1100 hPa | +/- 1 hPa |
接口说明
VCC 供电正极3.3-5V
GND 供电负极
SCL SPI/IIC模式时钟信号输入
SDA SPI模式的MOSI数据信号的输入,IIC模式的数据信号的输入和输出
SDO SPI模式的MISO数据信号的输出,IIC模式时为IIC器件地址设置引脚,接GND时器件地址为1110110(0x76),接VCC时器件地址为1110111(0x77)
CS SPI/IIC模式的选择引脚,当接VCC时为IIC模式,当接GND时为SPI模式
BME680与Arduino UNO接线与程序
BME680 | SPI接线方式 | IIC接线方式 |
---|---|---|
SCL | D13 | A5 |
SDA | D11 | A4 |
SDO | D12 | / |
CS | D10 | / |
IIC接线方式
Arduino IDE库管理器安装 Adafruit_BME680 library
Arduino IDE库管理器安装Adafruit Unified Sensor
打开示例代码
/***************************************************************************
This is a library for the BME680 gas, humidity, temperature & pressure sensor
Designed specifically to work with the Adafruit BME680 Breakout
----> http://www.adafruit.com/products/3660
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_BME680.h"
#define BME_SCK 13
#define BME_MISO 12
#define BME_MOSI 11
#define BME_CS 10
#define SEALEVELPRESSURE_HPA (1013.25)
Adafruit_BME680 bme; // I2C
//Adafruit_BME680 bme(BME_CS); // hardware SPI
//Adafruit_BME680 bme(BME_CS, BME_MOSI, BME_MISO, BME_SCK);
void setup() {
Serial.begin(9600);
while (!Serial);
Serial.println(F("BME680 async test"));
if (!bme.begin()) {
Serial.println(F("Could not find a valid BME680 sensor, check wiring!"));
while (1);
}
// Set up oversampling and filter initialization
bme.setTemperatureOversampling(BME680_OS_8X);
bme.setHumidityOversampling(BME680_OS_2X);
bme.setPressureOversampling(BME680_OS_4X);
bme.setIIRFilterSize(BME680_FILTER_SIZE_3);
bme.setGasHeater(320, 150); // 320*C for 150 ms
}
void loop() {
// Tell BME680 to begin measurement.
unsigned long endTime = bme.beginReading();
if (endTime == 0) {
Serial.println(F("Failed to begin reading :("));
return;
}
Serial.print(F("Reading started at "));
Serial.print(millis());
Serial.print(F(" and will finish at "));
Serial.println(endTime);
Serial.println(F("You can do other work during BME680 measurement."));
delay(50); // This represents parallel work.
// There's no need to delay() until millis() >= endTime: bme.endReading()
// takes care of that. It's okay for parallel work to take longer than
// BME680's measurement time.
// Obtain measurement results from BME680. Note that this operation isn't
// instantaneous even if milli() >= endTime due to I2C/SPI latency.
if (!bme.endReading()) {
Serial.println(F("Failed to complete reading :("));
return;
}
Serial.print(F("Reading completed at "));
Serial.println(millis());
Serial.print(F("Temperature = "));
Serial.print(bme.temperature);
Serial.println(F(" *C"));
Serial.print(F("Pressure = "));
Serial.print(bme.pressure / 100.0);
Serial.println(F(" hPa"));
Serial.print(F("Humidity = "));
Serial.print(bme.humidity);
Serial.println(F(" %"));
Serial.print(F("Gas = "));
Serial.print(bme.gas_resistance / 1000.0);
Serial.println(F(" KOhms"));
Serial.print(F("Approx. Altitude = "));
Serial.print(bme.readAltitude(SEALEVELPRESSURE_HPA));
Serial.println(F(" m"));
Serial.println();
delay(2000);
}
打开串口监视器显示出传感器测量的数据
总结
首次使用传感器器时建议使其工作48小时后其测量的数据相对稳定准确,建议使传感器工作半小时后读取到的气敏电阻值相对准确。通过本实验能快速直观的使用传感器获取所处环境的参数。