>> PMS7003M + 아두이노 메가2560 시리얼3 연결
/*
* pms7003
* 메가2560 사용하는 경우 Serial3 사용.
*/
#define START_1 0x42
#define START_2 0x4d
#define DATA_LENGTH_H 0
#define DATA_LENGTH_L 1
#define PM1_0_ATMOSPHERE_H 8
#define PM1_0_ATMOSPHERE_L 9
#define PM2_5_ATMOSPHERE_H 10
#define PM2_5_ATMOSPHERE_L 11
#define PM10_ATMOSPHERE_H 12
#define PM10_ATMOSPHERE_L 13
#define PM2_5_PARTICLE_H 16
#define PM2_5_PARTICLE_L 17
#define VERSION 26
#define ERROR_CODE 27
#define CHECKSUM 29
byte bytCount1 = 0;
byte bytCount2 = 0;
unsigned char chrRecv;
unsigned char chrData[30];
int PM01;
int PM25;
int PM10;
bool g_bIsEnableDutSensor = false;
bool isEnableDustSensor()
{
return g_bIsEnableDutSensor;
}
int getPM01()
{
return PM01;
}
int getPM25()
{
return PM25;
}
int getPM10()
{
return PM25;
}
unsigned int GetPM_Data(unsigned char chrSrc[], byte bytHigh, byte bytLow)
{
return (chrSrc[bytHigh] << 8) + chrSrc[bytLow];
}
void init_pms7003m()
{
Serial.println("PMS7003 Ready ");
Serial3.begin(9600);
g_bIsEnableDutSensor=true;
}
void update_pms7003m()
{
if (Serial3.available())
{
for(int i = 0; i < 32; i++) {
chrRecv = Serial3.read();
if (chrRecv == START_2 ) {
bytCount1 = 2;
break;
}
}
if (bytCount1 == 2)
{
bytCount1 = 0;
for(int i = 0; i < 30; i++){
chrData[i] = Serial3.read();
}
if ( (unsigned int) chrData[ERROR_CODE] == 0 )
{
PM01 = GetPM_Data(chrData, PM1_0_ATMOSPHERE_H, PM1_0_ATMOSPHERE_L);
PM25 = GetPM_Data(chrData, PM2_5_ATMOSPHERE_H, PM2_5_ATMOSPHERE_L);
PM10 = GetPM_Data(chrData, PM10_ATMOSPHERE_H, PM10_ATMOSPHERE_L);
//
Serial.print("PM1.0=");
Serial.print(PM01);
Serial.print(",PM2.5=");
Serial.print(PM25);
Serial.print(",PM10=");
Serial.println(PM10);
}
else
{
Serial.println("PMS7003 ERROR"); // 잦은 요청때문에 발생됨. 무시됨.
g_bIsEnableDutSensor = false;
}
}
}
else
{
//Serial.println("PMS7003 NOT available");
//g_bIsEnableDutSensor = false;
}
}
댓글 없음:
댓글 쓰기