bertmelis / SDS011

Non blocking SDS011 sensor library for ESP8266
MIT License
16 stars 8 forks source link

not working on esp32 with arduino #7

Closed zen85 closed 2 years ago

zen85 commented 2 years ago

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();
}
bertmelis commented 2 years ago

I can't think of a reason, the lib really doesn't do anything special.

Although, why are you defining sds011Serial? By default, all the hardware serial objects are already defined as Serial, Serial1 and Serial2.

zen85 commented 2 years ago

I can't think of a reason, the lib really doesn't do anything special.

Although, why are you defining sds011Serial? By default, all the hardware serial objects are already defined as Serial, Serial1 and Serial2.

i did this because in the esp32 example in the main.cpp it is also done like this. I tried to take the example and rewrite it for arduino IDE. actually i did not really write anything.... just copied the code together since it looked quite straight-forward.

bertmelis commented 2 years ago

Oh, you're right. I wonder why I did it...

You're using the latest Arduino core, right? Because Platformio is lagging a few version behind and Hardware serial has been completely refactored.

zen85 commented 2 years ago

Oh, you're right. I wonder why I did it...

You're using the latest Arduino core, right? Because Platformio is lagging a few version behind and Hardware serial has been completely refactored.

yes i am using the latest version - i try to stay up do date :)

is this maybe correlated to my problem?

zen85 commented 2 years ago

I changed the sketch as i could not identify any other dealbreakers in the library itself.... unfortunatly no change... :(


#include <SDS011.h>

SDS011 sds011;

void setup() {

  Serial.begin(115200);
  sds011.setup(&Serial1, 15, 2);  // Rx on GPIO14; Tx on GPIO12

  sds011.onData([](float pm25Value, float pm10Value) {
    Serial.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) {
    Serial.println("Response to command 0x" + String(command, HEX) + " received: 0x" + String(result, HEX));
  });

  sds011.onError([](int8_t error) {
    Serial.println("Error occurred: 0x" + String(error, HEX));
  });

  sds011.setWorkingPeriod(1);
  Serial.println("Data should appear on the default serial port in less than a minute");
}

void loop() {

  sds011.loop();
}

`
bertmelis commented 2 years ago

And you are sure the pins you assign are correct? Because your comment gives the gpio numbers but in the code you use other numbers.

Are you using a premade board or your own design?

zen85 commented 2 years ago

i am using an esp32 from az-delivery. - yes i am aware of the different gpio numbers i am using. the wiring works. with different libraries i can measure without any problem... but i did not find any non-blocking libraries that work - therefor yours is so interesting to me.

bertmelis commented 2 years ago

I'll start my setup but I can only test with an esp8266. I only got one device and it is soldered.

Now, there should be no difference between 32 and 8266.

zen85 commented 2 years ago

this would be so great... in case i can help by ordering a device for you i will gladly do that and i am keen on testing whatever you find out :) thank you so much!

zen85 commented 2 years ago

i am terribly sorry...

i just rewired everything again after another library failed too... and apparently one of the pins was loose and kind of fiddly... i fixed that and it started working... sorry if this occupied your time.

bertmelis commented 2 years ago

No worries. I'm happy it works.