Reading data from an SDS011 Air Quality Sensor via Serial

Hey folks,

I’m trying to hook up an SDS011 Air Quality Sensor to an ExpLoRer via the Serial port.

All of the libraries available require SoftwareSerial or don’t support the ExpLoRer, so I’ve had to resort to some code I’ve found which reads the serial port directly.

If I plug the SDS011 into my laptop via the provided FTDI adaptor, I can read the measurements fine, however for some reason the following code doesn’t work:

void ProcessSerialData()
{
  uint8_t mData = 0;
  uint8_t i = 0;
  uint8_t mPkt[10] = {0};
  uint8_t mCheck = 0;
  while (Serial.available() > 0)
  {
    // from www.inovafitness.com
    // 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
        {
          Serial.flush();
          //Serial.write(mPkt,10);

          Pm25 = (uint16_t)mPkt[2] | (uint16_t)(mPkt[3] << 8);
          Pm10 = (uint16_t)mPkt[4] | (uint16_t)(mPkt[5] << 8);
          if (Pm25 > 9999)
            Pm25 = 9999;
          if (Pm10 > 9999)
            Pm10 = 9999;
          //            Serial.println(Pm25);
          //          Serial.println(Pm10);
          //get one good packet
          return;
        }
      }
    }
  }
}

The data simply never arrives at the ExpLoRa device.

My connections are as follows:

ExpLoRa         SDS011
   5v     ->      5v
  GND     ->      GND
  TX (D1) ->      RX
  RX (D0) ->      TX

The function is called in the loop(), but the only values that are ever returned are 0 for both metrics, and if I add in debug SerialUSB.println("Packet Received") statements into the while Serial.available() loop, they never get printed.

What am I missing?