Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

UART communication protocol read with Arduino

Status
Not open for further replies.

RobertoPasic

Newbie level 6
Joined
Dec 2, 2009
Messages
12
Helped
0
Reputation
0
Reaction score
0
Trophy points
1,281
Location
Macedonia
Activity points
1,390
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:
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
 

Attachments

  • attach_no1.pdf
    190.7 KB · Views: 61
  • attach_no2.pdf
    292.6 KB · Views: 80

Status
Not open for further replies.

Similar threads

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top