lewapek / sds-dust-sensors-arduino-library

Library for Nova Fitness SDS dust sensors family (SDS011, SDS021)
MIT License
64 stars 19 forks source link

Query mode example missing evry other reading #17

Closed artkrz closed 4 years ago

artkrz commented 4 years ago

No idea why but I want to get a reading every minute and it seems like I'm geting one evry 5 minutes and failures in beetwen:

I'm using NodeMCU 1.0 board, It's actually Amica v2 and latest release of your library.

14:51:48.941 -> ⸮ ⸮-⸮⸮⸮Firmware version [year.month.day]: 18.11.16
14:51:50.074 -> Mode: query
14:52:21.621 -> Could not read values from sensor, reason: Not available
14:52:22.650 -> Sensor is sleeping
14:53:55.226 -> PM2.5 = 1.90, PM10 = 3.40
14:53:55.261 -> pm25: 1.90, pm10: 3.40
14:53:55.743 -> Sensor is sleeping
14:55:27.314 -> Could not read values from sensor, reason: Not available
14:55:28.341 -> Sensor is sleeping
14:57:00.915 -> PM2.5 = 2.00, PM10 = 2.80
14:57:00.950 -> pm25: 2.00, pm10: 2.80
14:57:01.428 -> Sensor is sleeping
14:58:32.991 -> Could not read values from sensor, reason: Not available
14:58:34.026 -> Sensor is sleeping
15:00:06.609 -> PM2.5 = 2.00, PM10 = 3.70
15:00:06.609 -> pm25: 2.00, pm10: 3.70
15:00:07.124 -> Sensor is sleeping
15:01:38.674 -> Could not read values from sensor, reason: Not available
15:01:39.708 -> Sensor is sleeping
15:03:12.275 -> PM2.5 = 2.40, PM10 = 5.00
15:03:12.310 -> pm25: 2.40, pm10: 5.00
15:03:12.824 -> Sensor is sleeping
15:04:44.375 -> Could not read values from sensor, reason: Not available
15:04:45.402 -> Sensor is sleeping

Uploaded example code:

#include "SdsDustSensor.h"

int rxPin = D1;
int txPin = D2;
SdsDustSensor sds(rxPin, txPin);

void setup() {
  Serial.begin(9600);
  sds.begin();

  Serial.println(sds.queryFirmwareVersion().toString()); // prints firmware version
  Serial.println(sds.setQueryReportingMode().toString()); // ensures sensor is in 'query' reporting mode
}

void loop() {
  sds.wakeup();
  delay(30000); // working 30 seconds

  PmResult pm = sds.queryPm();
  if (pm.isOk()) {
    Serial.print("PM2.5 = ");
    Serial.print(pm.pm25);
    Serial.print(", PM10 = ");
    Serial.println(pm.pm10);

    // if you want to just print the measured values, you can use toString() method as well
    Serial.println(pm.toString());
  } else {
    Serial.print("Could not read values from sensor, reason: ");
    Serial.println(pm.statusToString());
  }

  WorkingStateResult state = sds.sleep();
  if (state.isWorking()) {
    Serial.println("Problem with sleeping the sensor.");
  } else {
    Serial.println("Sensor is sleeping");
    delay(60000); // wait 1 minute
  }
}

Can You help?

artkrz commented 4 years ago

I got it working by reducing

delay(30000);

to

delay(15000);
lewapek commented 4 years ago

Hi, I think that the issue may not be connected with NodeMCU board but rather with dust sensor. Reducing working time from 30s to 15s (after wakeup) seems strange to make it working (30s is a minimum recommended amount of working time before measurement).

You can try to print also 'sds.wakeup()' status. You can also try 'wakeupUnsafe' - look at Readme or sources to see the difference.

If this will not work you can recompile sources with '#define __DEBUG_SDS_DUST_SENSOR__' - this will print you raw responses from the sensor for all commands