Arduino-汉王PM2.5检测模组B1

汉王PM2.5检测模组B1,接入Arduino,使用I2C1602显示屏显示

 #include <Arduino.h>
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
float pm25 = ;
#define DATALEN 7
LiquidCrystal_I2C lcd(0x3F,,); // set the LCD address to 0x27 for a 16 chars and 2 line display
void setup() {
// put your setup code here, to run once:
Serial.begin();
lcd.init(); // initialize the lcd // Print a message to the LCD.
lcd.backlight();
lcd.print("PM2.5"); }
void ProcessSerialData()//读取PM2.5的数据。
{
uint8_t mData = ;
uint8_t i = ;
uint8_t mPkt[DATALEN] = {};
int mCheck = ;
while (Serial.available() > )
{
mData = Serial.read();
delay();//wait until packet is received
if(mData == 0xAA)//head1 ok
{
mPkt[] = mData;
mData = Serial.read();
{
for(int i=;i < DATALEN;i++)//data recv and crc calc
{
mPkt[i] = Serial.read();
Serial.print(mPkt[i],HEX);
Serial.print("---");
delay();
}
delay();
Serial.println();
// Serial.println(mPkt[3]*256+mPkt[2]);
// Serial.print(mPkt[2]);
// Serial.println(" ");
// Serial.print("---");
// Serial.print(mPkt[5]);
if(mPkt[DATALEN-] == 0xFF)
{
pm25 = (mPkt[]<<)|mPkt[];
Serial.println(float(pm25/));
lcd.setCursor(,);
lcd.print(float(pm25/));
Serial.flush();
return;
}
}
}
}
} void loop() {
ProcessSerialData();
}

Arduino-汉王PM2.5检测模组B1

Arduino-汉王PM2.5检测模组B1

上一篇:ASP.NET Web API 异常日志记录


下一篇:协同过滤和简单SVD优化