YW51灰尘PM2.5传感器资料
YW51传感器是PM2.5普三代灰尘传感器,利用微小颗粒物体对光的散射原理,当微小颗粒物体经过检测孔,对光线形成散射时;散射光的一部分通过光轴,经透镜聚集到感光元器件,感光元器件将光信号转换为电信号输出。经过改进取消模拟输出口,并且将内部算法进行微调。串口输出更稳定。
YW_51.c
1 /** 2 * @file YW_51.c 3 * @brief 4 * @version 0.1 5 * @date 2019-06-28 6 * 7 * @copyright Copyright (c) 2019 Chipintelli Technology Co., Ltd. 8 * 9 */ 10 /*----------------------------------------------------------------------------- 11 include 12 -----------------------------------------------------------------------------*/ 13 #include "ci_sensor.h" 14 #include "ci110x_uart.h" 15 16 /*----------------------------------------------------------------------------- 17 define 18 -----------------------------------------------------------------------------*/ 19 #define RECEIVE_DATA_UART (UART1)/*!< 接收数据串口 */ 20 21 /*----------------------------------------------------------------------------- 22 extern 23 -----------------------------------------------------------------------------*/ 24 25 /*----------------------------------------------------------------------------- 26 struct / enum / union 27 -----------------------------------------------------------------------------*/ 28 29 /*----------------------------------------------------------------------------- 30 global 31 -----------------------------------------------------------------------------*/ 32 uint8_t data_array[7] = {0};/*!< 接收数据数组 */ 33 34 /*----------------------------------------------------------------------------- 35 declare 36 -----------------------------------------------------------------------------*/ 37 38 /*----------------------------------------------------------------------------- 39 function 40 -----------------------------------------------------------------------------*/ 41 /** 42 * @brief PM2.5传感器初始化 43 * 44 * @param irq_callback 中断回调 45 * @retval RETURN_OK 46 * @retval RETURN_ERR 47 */ 48 int32_t yw51_open(void) 49 { 50 UARTInterruptConfig(RECEIVE_DATA_UART,UART_BaudRate2400); 51 return RETURN_OK; 52 } 53 54 /** 55 * @brief PM2.5传感器读数据 56 * 57 * @param data 读到的数据 58 * @retval RETURN_OK 59 * @retval RETURN_ERR 60 */ 61 int32_t yw51_read(sensor_data_t *data) 62 { 63 float data_l,data_h; 64 if(data_array[6] == 0xFF) 65 { 66 if(data_array[1]+data_array[2]+data_array[3]+data_array[4] == data_array[5]) 67 { 68 data_h = data_array[1]; 69 data_l = data_array[2]; 70 } 71 } 72 else 73 { 74 return RETURN_ERR; 75 } 76 sensor_data_inform(SENSOR_TYPE_PARTICULATES); 77 data->particulates = (data_l + (data_h * 256)) * 6.25; 78 return RETURN_OK; 79 } 80 81 /** 82 * @brief PM2.5传感器ops 83 * 84 */ 85 sensor_ops_t yw51_ops = 86 { 87 yw51_open, 88 yw51_read, 89 }; 90 91 /*----------------------------------------------------------------------------- 92 end of the file 93 -----------------------------------------------------------------------------*/
YW_51.h
/** * @file YW_51.h * @brief YW_51传感器的头文件 * @version 0.1 * @date 2019-07-02 * * @copyright Copyright (c) 2019 Chipintelli Technology Co., Ltd. * */ #ifndef __YW_51_H__ #define __YW_51_H__ /** * @ingroup third_device_driver * @defgroup YW51 * @brief YW51传感器驱动 * @{ */ #ifdef __cplusplus extern "C" { #endif /*----------------------------------------------------------------------------- include -----------------------------------------------------------------------------*/ #include "ci_sensor.h" /*----------------------------------------------------------------------------- define -----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------- extern -----------------------------------------------------------------------------*/ extern sensor_ops_t yw51_ops; /*----------------------------------------------------------------------------- struct / enum / union -----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------- global -----------------------------------------------------------------------------*/ /*----------------------------------------------------------------------------- function declare -----------------------------------------------------------------------------*/ void yw51_uart_handler(void); #ifdef __cplusplus } #endif /** * @} */ #endif /*----------------------------------------------------------------------------- end of the file -----------------------------------------------------------------------------*/