GithubHelp home page GithubHelp logo

lewapek / sds-dust-sensors-arduino-library Goto Github PK

View Code? Open in Web Editor NEW
65.0 7.0 19.0 61 KB

Library for Nova Fitness SDS dust sensors family (SDS011, SDS021)

License: MIT License

C++ 81.62% C 18.38%
sds sds011 dust-sensor arduino nodemcu nodemcu-arduino pm10 pm25 sensor esp8266

sds-dust-sensors-arduino-library's People

Contributors

cyberman54 avatar kolen avatar lewapek avatar lukamicoder avatar mellbratt avatar noerw avatar per1234 avatar sankara avatar thepotatocannon avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

sds-dust-sensors-arduino-library's Issues

sds011 stuck in custom mode

Hey, i tried the custom timing mode and now the sensor kind of seems like its stuck in it. Ofc i tried to upload other programs like the quickstart but the behaviour of the sensor doesnt change, furthermore there are quite many reading errors.

Query mode example missing evry other reading

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?

Compilation fails on Arduino Nano 33 BLE (Sense)

Hello, and first of all thanks for your great and useful library!

By compiling code containing reference to "SdsDustSensor.h" on Arduino IDE 1.8.42.0 using card "Arduino Nano 33 BLE" I get the following error:

............\Documents\Arduino\libraries\Nova_Fitness_Sds_dust_sensors_library\src/SdsDustSensorResults.h:6:10: fatal error: SoftwareSerial.h: No such file or directory

#include <SoftwareSerial.h>

I've checked the code and in "Serials.h" found the lines

#ifndef ARDUINO_SAMD_VARIANT_COMPLIANCE // there is no SoftwareSerial available (needed) on SAMD boards.
#include <SoftwareSerial.h>
#endif
#include <HardwareSerial.h>

My suspect is, the Nano 33 BLE is a different category than ARDUINO_SAMD, and as with ARDUINO_SAMD the "SoftwareSerial.h" library is missing.

Compilation fails with SoftwareSerial.h not found. Library.json version doesn't match tag 1.4.0?

When I try to install this library using the library manager, it fails saying "SoftwareSerial.h" is not found. I looked into the codebase and I clearly see that you have #ifndef statements to validate if SoftwareSerial is required before including it. So I opened up the downloaded code and found that it was different from what I saw on Github. I was able to workaround the issue then by manually downloading the codebase and installing it as zip.

I did further research and found you have specified the library version as 1.3.2 in library.json whereas the changes that has the #ifndef statements were made after v1.3.2 tag was released. The latest tag seems to be 1.4.0. I'll follow this up with a PR to change the library version (assuming my diagnosis is correct).

Library not working well with hardware serial

Trying to use the library with Adafruit's Feather m0 LoRa, a SAMD based board that has several assignable hardware serial ports but doesn't play well with the software serial library. I've tried to make some adaptations but have gotten stuck. Any plans to update the library and accommodate streams that aren't software serial?

Add esp32 to the SoftwareSerial.h #ifdef

The esp32 also doesn't have the SoftwareSerial.h library, it just works without it though.
Also you should add the esp32 to the compatibility list in the properties, at the moment there's only the esp8266.

Using hardwareserial crashing in sds.begin() on arduino-espressif32 framework

I am on arduino-espressif32 framework, thus using HardwareSerial.
I don't get the library run on top of this, it's crashing in sds.begin() with a Guru Meditation error:

17:44:31.126 > [I][main.cpp:371] setup(): init fine-dust-sensor
17:44:31.132 > Guru Meditation Error: Core  1 panic'ed (IllegalInstruction). Exception was unhandled.
17:44:31.334 >   #0  0x400d9534:0x3ffd09a0 in SdsDustSensor::execute(Command const&) at .pio/libdeps/usb/Nova Fitness Sds dust sensors library/src/SdsDustSensor.h:165
17:44:31.334 > Rebooting...

My serial initialization code is:

HardwareSerial sds_Serial(2); // use UART #2
SdsDustSensor sds(sds_Serial);

void setup {
  sds_Serial.begin(9600, SERIAL_8N1, 19, 23);
  sds.begin();
  ...
}

Any hints or suggestions what's wrong here?

WakingUp

Hi @lewapek!
I've just try to run this program.
But my sensor still set on rest mode and doesn't work. How can I set it on wakeup mode?
Sorry for the question, but I'm new with Arduino and c++ to.

Invalid firmware version

Sensor board sometimes returns incorrect firmware version with status OK.
Some of tested sds011 sensors returned 1.0.0 version [year.month.day].

Solution:
version should be checked against possible ranges (at least month and day) and result in different status (not ok - it may require new status)

Issue when waking up

Hello @lewapek,
thank you very much for your library.

I tried to use it, but run into a weird issue.
If using the continous mode without sleeping everything works fine.
But as soon as I put the sensor into sleep mode and wake it up I get weird responses, leading the sds-dust-sensors-arduino-library to return an InvalidHead response.

For debugging purposes I implemented my own "library" to investigate further.
Putting my sensor to sleep works.
Waking it up returns seemingly random 5 bytes, for example, when waking the sensor up after a 30 seconds sleep, this is what the sensor responds:

0: ad
0: 50
0: 10
0: 5e
0: dd

The 0: is indicating the index.
As the AA is missing, no new message is identified and thus the index is 0 all the time.

From this point on all communication works as specified, e.g. sending another wake up, returns the following bytes

0: aa
1: c5
2: 6
3: 1
4: 1
5: 0
6: ec
7: e1
8: d5
9: ab
=> Message received: AA C5 6 1 1 0 EC E1 D5 AB 

Did you observe a similar behaviour or do you have any idea what might be wrong with my sensor?

invalid initialization of non-const reference of type 'HardwareSerial&' , sds(rxPin, txPin);

When I try to compile the example for a ES32 board, I get this error in the Arduino IDE.

Feinstaub:33:31: error: invalid initialization of non-const reference of type 'HardwareSerial&' from an rvalue of type 'HardwareSerial'
 SdsDustSensor sds(rxPin, txPin);
                               ^
In file included from /home/kevin/.arduino15/packages/esp32/hardware/esp32/1.0.6/cores/esp32/Arduino.h:154:0,
                 from sketch/Feinstaub.ino.cpp:1:
/home/kevin/.arduino15/packages/esp32/hardware/esp32/1.0.6/cores/esp32/HardwareSerial.h:56:5: note:   after user-defined conversion: HardwareSerial::HardwareSerial(int)
     HardwareSerial(int uart_nr);
     ^
In file included from /home/kevin/Arduino/Feinstaub/Feinstaub.ino:2:0:
/home/kevin/Arduino/libraries/Nova_Fitness_Sds_dust_sensors_library/src/SdsDustSensor.h:60:3: note:   initializing argument 1 of 'SdsDustSensor::SdsDustSensor(HardwareSerial&, int, int)'
   SdsDustSensor(HardwareSerial &hardwareSerial,
   ^

Line 31-33 are the following:

int rxPin = 21;
int txPin = 22;
SdsDustSensor sds(rxPin, txPin);

Issue with The Things Uno (LoraWAN Leonardo).

First of all thanks for sharing this library which I use on an Arduino Leonardo or, te be more specific, on a The Things Uno board which is a Leonardo with integrated LoRaWAN.

Using the (unmodified) hardware.Serial.ino demo sketch, without the first measurement works fine and shows the PM10 and PM25 values in the serial monitor. Every following measurement shows bot PM values as 0.00 (zero). After a reset or boot the same issue is shown: only the first measurement is correct. The SDS011 sensor seems to be okay because it works fine in another setup with an Arduino Uno.

Is this a known issue or am I doing something wrong and can you advice me how to solve this?

Incompatibility with SD.h

Hello,

Thanks for your repository, I was able to use it to read from my sensor.

I wanted to save those readings to the microSD card attached to Arduino. However, by just including in the code #include <SD.h>, the Arduino simply doesn't work anymore (I cannot even read anything from the Serial, I'm guessing that's because setup() is executed). The constructor I'm using for the sensor is SdsDustSensor sds(10, 11);

Can you give any help trying to debug this, please? I'm guessing some part is shared across these 2 libraries... Have you ever had this problem? How do you usually save the readings from the sensor?

Thanks.

Consistent high readings using this code

Hi,

i'm just experimenting a bit with an sds011 sensor and this code. First I hooked up the sds to the accompanying usb adaptor together with this tool: https://github.com/karlchen86/SDS011 and got these readings:

Type: set mode: query
PM2.5: 2.00, PM10: 3.00
PM2.5: 1.90, PM10: 2.80
PM2.5: 1.80, PM10: 2.70
PM2.5: 1.70, PM10: 3.10
PM2.5: 1.70, PM10: 3.00
PM2.5: 1.60, PM10: 3.10

Which seem quite ok since I'm testing indoors.
However while testing this code, I'm getting consistently way higher readings:

Using example sketch:


16:18:08.071 -> pm25: 88.00, pm10: 95.00
16:18:09.035 -> PM2.5 = 91.10, PM10 = 98.30
16:18:09.068 -> pm25: 91.10, pm10: 98.30
16:18:10.031 -> PM2.5 = 92.40, PM10 = 99.70
16:18:10.065 -> pm25: 92.40, pm10: 99.70
16:18:11.027 -> PM2.5 = 93.60, PM10 = 101.00

I've got 2 SDS011 sensors and both share the same behaviour. Could you maybe explain the difference? Do you maybe use a different calculation method?

Query reporting mode

Hello,
If I don't use a serial monitor can I set the Query reporting mode without the command "Serial.println" present in the file in the examples folder? : Serial.println(sds.setQueryReportingMode().toString()); ?

I would to set the SDS011 sensor in query reporting mode, wakeup the sensor, read the PM value and sleep the sensor.

Can I use this command?

ReportingModeResult result = sds.setQueryReportingMode(); or exist a command without result?

sds.wakeup(); (like file in the example folder)

PmResult result = sds.queryPm();

WorkingStateResult result = sds.sleep(); or exist a command without result like sds.wakeup();?

In a first test, if I use the serial monitor, initially I read strange values in the serial monitor.
Thanks.

Compiling error

Trying compile an example queryReportingMode.ino there is a lots of problems:
ex.
src/SdsDustSensorResults.h:62:12: error: 'Mode' is not a class or namespace
case Mode::Active: return "Mode: active";
src/SdsDustSensorResults.h: In constructor 'WorkingStateResult::WorkingStateResult(const Status&, byte*)':

ESP32 hardware serial UART2

could someone help me how to assign GPIO pins under ESP32 to Serial2 together with this library ?
Sorry for beginners question here...
Thanks
Kai

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.