Hi Ron, Valentin,
This is from a few months ago, and you may have solved it, but I think that your problem is that the SDS2011 requires a serial port, also needed for Serial println. The Atmega328P in the Arduino UNO and Nano only so many of the SDS2011 libraries use a software serial port to interface to the SDS2011. The SAMD21 microcontrollers have a second on-chip serial port available, but many of the SDS2011 libraries can't use it.
I installed the Nova Fitness dust sensors libraries by Pawel Kolodziejczyk and I successfully ran his example programs.
I'm not sure if this library has been fully tested on MKR boards but it was tested on Leonardo boards, which also have a second serial port, and it worked for my MKR1500. It should work just as well with a MKR1310.
Best,
Ciaran
#include "SdsDustSensor.h"
// tested on Arduino Leonardo with Serial1
SdsDustSensor sds(Serial1); // passing HardwareSerial& as parameter
void setup() {
Serial.begin(9600);
sds.begin(); // this line will begin Serial1 with given baud rate (9600 by default)
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
}
}