RobertoPasic
Newbie level 6
Hi there,
I have this part of code for read data from PM sensor (model SDS011 from Inova) via UART, according UART communication protocol from SDS011 manual (attach no:1):
Code work OK,
Can somebody help with advice about code arrange for read other sensor (exactly ZE07-CO gas sensor), according UART communication protocol from ZE07 manual (attach no:2)
thanks in advance
best regards
I have this part of code for read data from PM sensor (model SDS011 from Inova) via UART, according UART communication protocol from SDS011 manual (attach no:1):
Code:
void ProcessSerialData(){
uint8_t mData = 0;
uint8_t i = 0;
uint8_t mPkt[10] = {0};
uint8_t mCheck = 0;
while (Serial.available() > 0){
// packet format: AA C0 PM25_Low PM25_High PM10_Low PM10_High 0 0 CRC AB
mData = Serial.read();
delay(2); // wait until packet is received
if (mData == 0xAA){ // head1 ok
mPkt[0] = mData;
mData = Serial.read();
if (mData == 0xc0){ // head2 ok
mPkt[1] = mData;
mCheck = 0;
for (i = 0; i < 6; i++){ // data recv and crc calc
mPkt[i + 2] = Serial.read();
delay(2);
mCheck += mPkt[i + 2];
}
mPkt[8] = Serial.read();
delay(1);
mPkt[9] = Serial.read();
if (mCheck == mPkt[8]){ // crc ok
Serial2.flush();
Pm25 = (uint16_t)mPkt[2] | (uint16_t)(mPkt[3] << 8);
Pm10 = (uint16_t)mPkt[4] | (uint16_t)(mPkt[5] << 8);
return;
}
}
}
}
}
Code work OK,
Can somebody help with advice about code arrange for read other sensor (exactly ZE07-CO gas sensor), according UART communication protocol from ZE07 manual (attach no:2)
thanks in advance
best regards