|
本帖最后由 零知实验室-roc 于 2019-7-24 11:08 编辑
空气质量监测-SGP30模块VOC CO2
http://www.lingzhilab.com/forum. ... d&tid=485&fromuid=2
(出处: 零知实验室)
使用SGP30模块对空气中的VOC和CO2进行监测,获取空气质量状况。
1、硬件:
注意:模块的供电标准为1.8V,所以使用时需要接电平转换才可以接到开发板中。
2、测试demo:
[mw_shl_code=cpp,true]/*
* 空气质量:VOC,CO2测量
* 零知开源-www.lingzhilab.com
*/
#include "Adafruit_SGP30.h"
Adafruit_SGP30 sgp;
/* return absolute humidity [mg/m^3] with approximation formula
* @param temperature [°C]
* @param humidity [%RH]
*/
uint32_t getAbsoluteHumidity(float temperature, float humidity) {
// approximation formula from Sensirion SGP30 Driver Integration chapter 3.15
const float absoluteHumidity = 216.7f * ((humidity / 100.0f) * 6.112f * exp((17.62f * temperature) / (243.12f + temperature)) / (273.15f + temperature)); // [g/m^3]
const uint32_t absoluteHumidityScaled = static_cast<uint32_t>(1000.0f * absoluteHumidity); // [mg/m^3]
return absoluteHumidityScaled;
}
void setup() {
Serial.begin(9600);
Serial.println("SGP30 test");
if (! sgp.begin()){
Serial.println("Sensor not found ");
while (1);
}
Serial.print("Found SGP30 serial #");
Serial.print(sgp.serialnumber[0], HEX);
Serial.print(sgp.serialnumber[1], HEX);
Serial.println(sgp.serialnumber[2], HEX);
// If you have a baseline measurement from before you can assign it to start, to 'self-calibrate'
//sgp.setIAQBaseline(0x8E68, 0x8F41); // Will vary for each sensor!
}
int counter = 0;
void loop() {
// If you have a temperature / humidity sensor, you can set the absolute humidity to enable the humditiy compensation for the air quality signals
//float temperature = 22.1; // [°C]
//float humidity = 45.2; // [%RH]
//sgp.setHumidity(getAbsoluteHumidity(temperature, humidity));
if (! sgp.IAQmeasure()) {
Serial.println("Measurement failed");
return;
}
Serial.print("TVOC "); Serial.print(sgp.TVOC); Serial.print(" ppb\t");
Serial.print("eCO2 "); Serial.print(sgp.eCO2); Serial.println(" ppm");
delay(1000);
counter++;
if (counter == 30) {
counter = 0;
uint16_t TVOC_base, eCO2_base;
if (! sgp.getIAQBaseline(&eCO2_base, &TVOC_base)) {
Serial.println("Failed to get baseline readings");
return;
}
Serial.print("****Baseline values: eCO2: 0x"); Serial.print(eCO2_base, HEX);
Serial.print(" & TVOC: 0x"); Serial.println(TVOC_base, HEX);
}
}[/mw_shl_code]
3、测试结果:
4、完整的工程源码请看这里:工程源码。
5、需要模块的,模块购买渠道:http://www.lingzhilab.com/index.php/home/goods/introduction?gid=550
芯片购买渠道:在芯间官方-http://www.zaixinjian.com/search?keyword=sgp30&value=product&page=1更多详细资料可到零知实验室官网免费获取。
|
|