bertmelis / sds011 Goto Github PK
View Code? Open in Web Editor NEWNon blocking SDS011 sensor library for ESP8266
License: MIT License
Non blocking SDS011 sensor library for ESP8266
License: MIT License
Unfortunatly it does not really work with the arduino IDE...
The sketch below compiles and it starts running without errors when i upload via ArduinoIDE. But it never delivers any values and is stuck at "Data should appear on the default serial port in less than a minute".
I know the hardware and wiring works since everything works as expected with esp_sds011 library.
Do you have any idea what might be the issue here?
#include <SDS011.h>
HardwareSerial usbSerial(0);
HardwareSerial sds011Serial(1);
SDS011 sds011;
void setup() {
usbSerial.begin(115200);
sds011.setup(&sds011Serial, 15, 2); // Rx on GPIO14; Tx on GPIO12
sds011.onData([](float pm25Value, float pm10Value) {
usbSerial.println("Data arrived: PM2.5 = " + String(pm25Value, 1) + " μg/m³; PM10 = " + String(pm10Value, 1) + " μg/m³");
});
sds011.onResponse([](uint8_t command, uint8_t set, uint8_t result) {
usbSerial.println("Response to command 0x" + String(command, HEX) + " received: 0x" + String(result, HEX));
});
sds011.onError([](int8_t error) {
usbSerial.println("Error occurred: 0x" + String(error, HEX));
});
sds011.setWorkingPeriod(1);
usbSerial.println("Data should appear on the default serial port in less than a minute");
}
void loop() {
sds011.loop();
}
I have had so much trouble with this sensor and the esp8266. esp32 works and then I have more issues in other areas with that device. Specifically with my home automation setup.
Could you add software serial or maybe hint to how I could use it instead or hardware? I have successfully been able to use software serial with the espsoftwareserial library and the sdsdustsensor library. Allowing serial debugging while I build out the code.
The problem is that the sdsdustsensor library is blocking the entire time it sleeps the sds sensor. I find your library and it seems to be the godsend I am after. I just cannot understand how to add a different port, softwareserial port, to the example myself.
I looked through the library to see the references used and I cannot figure out how to modify it so that I can use something other than hardware serial.
can I somehow change the sds011.setup line to use softwareserial?
I'm trying to use yr example but unfortunatley it keeps coming up with the following error at 👍
sds011.onResponse({
// command has been executed
});
error: no matching function for call to 'SDS011::onResponse(setup()::__lambda5)'
Moreover, my MQTT broker uses an mqttusername and mqttpassword, could that be implemented.
Thnks in advance.
Hi,
I wanted to give a try with your non blocking library,
But I can't successfully compile it with arduino IDE 2.3.2.
The board I use is a ESP32 developpement board with 38 yellow pins https://arduino-projekte.info/wp-content/uploads/2021/08/Node_MCU_ESP32_38Pin_pinout.webp https://raw.githubusercontent.com/AchimPieters/esp32-homekit-camera/master/Images/ESP32-38%20PIN-DEVBOARD.png
I cloned the library this way:
cd Arduino/libraries
git clone https://github.com/bertmelis/SDS011.git
I modified the example this way:
#include <HardwareSerial.h>
#include <SDS011.h>//librairie clonee manuellement 1.0.0 du 14/09/2018 mais fichiers plus récents https://github.com/bertmelis/SDS011
#define RXD2 16
#define TXD2 17
HardwareSerial usbSerial(0);
HardwareSerial sds011Serial(2);
//HardwareSerial sds011Serial(Serial2);
SDS011 sds011;
void setup() {
usbSerial.begin(115200);
//Serial2.begin(9600, SERIAL_8N1, RXD2, TXD2);//SDS011
sds011.setup(&sds011Serial, RXD2, TXD2); // Rx on GPIO14; Tx on GPIO12
//sds011.setup(&Serial2, RXD2, TXD2); // Rx on GPIO14; Tx on GPIO12
sds011.onData([](float pm25Value, float pm10Value) {
usbSerial.println("Data arrived: PM2.5 = " + String(pm25Value, 1) + " μg/m³; PM10 = " + String(pm10Value, 1) + " μg/m³");
});
sds011.onResponse([](uint8_t command, uint8_t set, uint8_t result) {
usbSerial.println("Response to command 0x" + String(command, HEX) + " received: 0x" + String(result, HEX));
});
sds011.onError([](int8_t error) {
usbSerial.println("Error occurred: 0x" + String(error, HEX));
});
sds011.setWorkingPeriod(1);
usbSerial.println("Data should appear on the default serial port in less than a minute");
}
void loop() {
sds011.loop();
}
But I get this error:
WARNING: library SDS011 claims to run on esp8266 architecture(s) and may be incompatible with your current board which runs on esp32 architecture(s).
Arduino/libraries/SDS011/src/SDS011.cpp: In member function 'void SDS011::setup(HardwareSerial*, uint8_t, uint8_t)':
Arduino/libraries/SDS011/src/SDS011.cpp:58:12: error: 'class Stream' has no member named 'begin'
_serial->begin(9600, SERIAL_8N1, rx_pin, tx_pin);
^~~~~
exit status 1
Compilation error: exit status 1
I previously could use my sds011 with this other library https://github.com/lewapek/sds-dust-sensors-arduino-library/tree/master with this code:
#include "SdsDustSensor.h" //Nova Fitness Sds dust sensors library by Paweł Kołodziejczyk 1.5.1 du 14/02/2022 https://github.com/lewapek/sds-dust-sensors-arduino-library/tree/master
// tested on Arduino Leonardo with Serial1
SdsDustSensor sds(Serial2); // passing HardwareSerial& as parameter
#define RXD2 16
#define TXD2 17
void setup() {
Serial.begin(115200);
Serial2.begin(9600, SERIAL_8N1, RXD2, TXD2);//SDS011
sds.begin(9600); // 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(10000); // 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(10000); // wait 1 minute
}
}
Could you please help me to find what I am missing?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.