中文 WIKI - lbx-8023/DFRobot_BMV080 GitHub Wiki
- C++/Aduino示例教程
-
参考
- begin
- openBmv080
- closeBmv080
- resetBmv080
- stopBmv080
- getBmv080DV
- getBmv080ID
- getBmv080Data
- setBmv080Mode
- setIntegrationTime
- getIntegrationTime
- setDutyCyclingPeriod
- getDutyCyclingPeriod
- setObstructionDetection
- getObstructionDetection
- setDoVibrationFiltering
- getDoVibrationFiltering
- setMeasurementAlgorithm
- getMeasurementAlgorithm
- DFRobot_BMV080_I2C
#include "DFRobot_BMV080.h"
#include <string>
SET_LOOP_TASK_STACK_SIZE(60 * 1024); // 60KB
DFRobot_BMV080_I2C sensor(&Wire);
void setup() {
// put your setup code here, to run once:
char id[13];
Serial.begin(115200);
delay(500);
while(sensor.begin() != 0){
Serial.println("初始化芯片失败,请确认芯片连接是否正确");
delay(1000);
}
delay(500);
Serial.println("初始化芯片成功");
while(sensor.openBmv080())
{
Serial.println("open失败");
delay(1000);
}
Serial.println("open成功");
delay(100);
sensor.getBmv080ID(id);
Serial.println("id is:" + String(id));
delay(100);
if(sensor.setBmv080Mode(0))
Serial.println("模式设置成功");
}
float pm1,pm2_5,pm10;
void loop() {
// put your main code here, to run repeatedly:
if(sensor.getBmv080Data(&pm1,&pm2_5,&pm10))
{
Serial.println("读取成功");
Serial.println("pm1:");
Serial.println(pm1);
Serial.println("pm2_5:");
Serial.println(pm2_5);
Serial.println("pm10:");
Serial.println(pm10);
}
delay(1000);
//Serial.println("读取失败");
}
- C++/Arduino原型:
int DFRobot_BMV080_I2C::begin(void)
- 说明: 初始化通信总线。
- 参数: 无
- 返回值: 无
- C++/Arduino原型:
uint8_t DFRobot_BMV080::openBmv080(void)
- 说明: 将bmv080句柄、写回调、读回调、延时回调函数传给bmv080 SDK,需要优先调用此函数再进行后续操作。
- 参数: 无
-
返回值:
-
0
:成功。 -
其他值
:失败状态码。
-
- C++/Arduino原型:
bool DFRobot_BMV080::closeBmv080(void)
- 说明: 关闭BMV080。
- 参数: 无
-
返回值:
-
1
:成功。 -
0
:失败。
-
- C++/Arduino原型:
bool DFRobot_BMV080::resetBmv080(void)
- 说明: 重置传感器单元,包括先前的配置都将恢复默认值。
- 参数: 无
-
返回值:
-
1
:成功。 -
0
:失败。
-
- C++/Arduino原型:
bool DFRobot_BMV080::stopBmv080(void)
- 说明: 停止传感器测量。
- 参数: 无
-
返回值:
-
1
:成功。 -
0
:失败。
-
- C++/Arduino原型:
bool DFRobot_BMV080::getBmv080DV(uint16_t &major, uint16_t &minor, uint16_t &patch)
- 说明: 获得传感器的驱动版本。
-
参数:
-
major
:主要版本号。 -
minor
:次要版本号。 -
patch
:补丁版本号。
-
-
返回值:
-
1
:成功。 -
0
:失败。
-
- C++/Arduino原型:
bool DFRobot_BMV080::getBmv080ID(char *id)
- 说明: 获取传感器的ID。
-
参数:
-
id
:用于存储ID的数组。
-
-
返回值:
-
1
:成功。 -
0
:失败。
-
- C++/Arduino原型:
bool DFRobot_BMV080::getBmv080Data(float *PM1, float *PM2_5, float *PM10)
- 说明: 获取传感器的输出数据。
-
参数:
-
PM1
:用来存放PM1数据。 -
PM2_5
:用来存放PM2.5数据。 -
PM10
:用来存放PM10数据。
-
-
返回值:
-
1
:成功。 -
0
:失败。
-
- C++/Arduino原型:
bool DFRobot_BMV080::setBmv080Mode(uint8_t mode)
-
说明: 设置传感器的测量模式。
-
参数:
-
mode
:0:持续测量 1:按照指定时间间隔测量
-
-
返回值:
-
1
:成功。 -
0
:失败。
-
- C++/Arduino原型:
bool DFRobot_BMV080::setIntegrationTime(float integration_time)
-
说明: 间隔测量模式下设置间隔测量时间。
-
参数:
-
integration_time
:设置的间隔测量时间
-
-
返回值:
-
1
:成功。 -
0
:失败。
-
- C++/Arduino原型:
bool DFRobot_BMV080::getIntegrationTime(float integration_time)
-
说明: 间隔测量模式下获取间隔测量时间。
-
参数:
-
integration_time
:获取的间隔测量时间
-
-
返回值:
-
1
:成功。 -
0
:失败。
-
- C++/Arduino原型:
bool DFRobot_BMV080::setDutyCyclingPeriod(uint16_t duty_cycling_period)
-
说明: 设置工作周期。
-
参数:
-
integration_time
:设置工作周期时间
-
-
返回值:
-
1
:成功。 -
0
:失败。
-
- C++/Arduino原型:
bool DFRobot_BMV080::getDutyCyclingPeriod(uint16_t *duty_cycling_period)
-
说明: 设置工作周期。
-
参数:
-
integration_time
:设置工作周期时间
-
-
返回值:
-
1
:成功。 -
0
:失败。
-
- C++/Arduino原型:
bool DFRobot_BMV080::setObstructionDetection(bool obstructed)
-
说明: 设置是否开启障碍物检测。
-
参数:
-
obstructed
: 0:关闭, 1:开启
-
-
返回值:
-
1
:成功。 -
0
:失败。
-
- C++/Arduino原型:
bool DFRobot_BMV080::getObstructionDetection(void)
-
说明: 获取障碍物检测开启/关闭状态。
-
参数: 无
-
返回值:
-
1
:开启。 -
0
:关闭。
-
- C++/Arduino原型:
bool DFRobot_BMV080::setDoVibrationFiltering(bool do_vibration_filtering)
-
说明: 是否启动震动过滤功能。
-
参数:
-
do_vibration_filtering
: 0:关闭, 1:开启
-
-
返回值:
-
1
:成功。 -
0
:失败。
-
- C++/Arduino原型:
bool DFRobot_BMV080::getDoVibrationFiltering(void)
-
说明: 获取震动过滤功能开启/关闭状态。
-
参数: 无
-
返回值:
-
1
:开启。 -
0
:关闭。
-
- C++/Arduino原型:
bool DFRobot_BMV080::setMeasurementAlgorithm(uint8_t measurement_algorithm)
-
说明: 设置传感器测量算法。
-
参数:
-
measurement_algorithm
:1:快速响应算法,2:平衡算法,3:高精度算法。
-
-
返回值:
-
1
:成功。 -
0
:失败。
-
- C++/Arduino原型:
uint8_t DFRobot_BMV080::getMeasurementAlgorithm(void)
-
说明: 获取当前算法模式。
-
参数: 无
-
返回值:
-
1
:快速响应算法。 -
2
:平衡算法。 -
3
:高精度算法。
-
- 说明: IIC通信模式下BMV080的构造函数。
- 用法:
DFRobot_BMV080_I2C sensor(&Wire);