本帖最后由 Ketose 于 2016-1-16 13:12 编辑
使用K22F读ZE08-CH2O传感器的甲醛浓度值
1、电化学甲醛模组 ZE08-CH2O介绍 ZE 08 -CH 2 O型电化学甲醛模组是一个通用型、小型化模组。利用电化学原理对空气中存在的CH 2 O进行探测,具有良好的选择性,稳定性。内置温度传感器,可进行温度补偿;同时具有数字输出与模拟电压输出,方便使用。ZE 08 -CH 2 O是将成熟的电化学检测技术与精良的电路设计紧密结合,设计制造出的通用型气体模组。 2、通讯及管脚说明
3、代码说明 本程序使用K22F的UART2进行串口数据的读取,然后按照数据格式计算出甲醛浓度,具体计算参考下面的代码部分
代码: int main(void)
{
uint8_t rxChar, txChar;
uint32_t byteCountBuff = 0;
// Initialize variable uartState of type uart_state_t
uart_state_t uartState;
// Fill in uart config data
uart_user_config_t uartConfig = {
.bitCountPerChar = kUart8BitsPerChar,
.parityMode = kUartParityDisabled,
.stopBitCount = kUartOneStopBit,
.baudRate = 9600
};
// Enable clock for PORTs, setup board clock source, config pin
hardware_init();
// Initialize the uart module with base address and config structure
UART_DRV_Init(UART2_IDX, &uartState, &uartConfig);
uint8_t receiveBuffer[9];
uint8_t rx;
while(true)
{
rx = 0x00;
for(int i=0;i<9;i++)
receiveBuffer[i] = 0;
// Call received API
UART_DRV_ReceiveData(UART2_IDX, &rx, 1u);
// Wait until we receive a character
while (kStatus_UART_RxBusy == UART_DRV_GetReceiveStatus(UART2_IDX, NULL));
if(rx == 0xFF)
{
receiveBuffer[0] = rx;
for(int i=1;i<9;i++)
{
// Call received API
UART_DRV_ReceiveData(UART2_IDX, &rx, 1u);
// Wait until we receive a character
while (kStatus_UART_RxBusy == UART_DRV_GetReceiveStatus(UART2_IDX, NULL));
receiveBuffer[i] = rx;
}
}
// Echo received character
//txChar = rxChar;
//UART_DRV_SendData(BOARD_DEBUG_UART_INSTANCE, &txChar, 1u);
/*国家标准室内0.08mg/m3 = 833 * 0.08 = 66.64 ppb。*/
int pm25Value = receiveBuffer[4]*256 + receiveBuffer[5];
float result = pm25Value / 66.64 * 0.08;
int v1 = (int)result;
int v2 = (int)((result - v1)*1000);
PRINTF("CH2O: %d.%03d(mg/m3)\r\n",v1,v2);
}
}
4、输出结果:
实验结果是打开门窗后测得的结果,国家标准是0.08,应该还算不错。。
|