Hi so I'm trying to use a Arduino nano 33 IoT with a Nova PM sensor (SDS 011). I have base code:
#include <SdsDustSensor.h>
/*
Sketch generated by the Arduino IoT Cloud Thing "Untitled"
https://create.arduino.cc/cloud/things/ab25e614-5583-44ea-b164-8b0f905d4fb2
Arduino IoT Cloud Variables description
The following variables are automatically generated and updated when changes are made to the Thing
float p10;
float p25;
Variables which are marked as READ/WRITE in the Cloud Thing will also have functions
which are called when their values are changed from the Dashboard.
These functions are generated with the Thing and added at the end of this sketch.
*/
#include "thingProperties.h"
#include "SdsDustSensor.h"
SdsDustSensor sds(Serial1);
void setup() {
// Initialize serial and wait for port to open:
Serial.begin(9600);
sds.begin();
Serial.println(sds.queryFirmwareVersion().toString()); // prints firmware version
Serial.println(sds.setActiveReportingMode().toString()); // ensures sensor is in 'active' reporting mode
Serial.println(sds.setContinuousWorkingPeriod().toString()); // ensures sensor has continuous working period - default but not recommended
// Defined in thingProperties.h
initProperties();
// Connect to Arduino IoT Cloud
ArduinoCloud.begin(ArduinoIoTPreferredConnection);
/*
The following function allows you to obtain more information
related to the state of network and IoT Cloud connection and errors
the higher number the more granular information you’ll get.
The default is 0 (only errors).
Maximum is 4
*/
setDebugMessageLevel(2);
ArduinoCloud.printDebugInfo();
}
void loop() {
ArduinoCloud.update();
PmResult pm = sds.readPm();
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());
}
delay(500);
}
/*
Since P25 is READ_WRITE variable, onP25Change() is
executed every time a new value is received from IoT Cloud.
*/
void onP25Change() {
// Add your code here to act upon P25 change
}
/*
Since P10 is READ_WRITE variable, onP10Change() is
executed every time a new value is received from IoT Cloud.
*/
void onP10Change() {
// Add your code here to act upon P10 change
}
I'm wonder how exactly how I would go about getting the data and storing it as the float variable that I have defined.
Any help would be greatly appreciated thanks.