You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: README.md
+20-13Lines changed: 20 additions & 13 deletions
Original file line number
Diff line number
Diff line change
@@ -1,16 +1,17 @@
1
1
# Nova Fitness SDS dust sensors arduino library
2
2
Supports Nova Fitness SDS011, SDS021 however should work for other Nova Fitness SDS sensors as well.
3
-
This library attempts to provide easy-to-use abstraction over [Laser Dust Sensor Control Protocol V1.3](https://cdn.sparkfun.com/assets/parts/1/2/2/7/5/Laser_Dust_Sensor_Control_Protocol_V1.3.pdf).
4
-
Each response coming from sensor is validated whether it has correct head, command id, checksum and tail.
3
+
This library attempts to provide easy-to-use abstraction over [Laser Dust Sensor Control Protocol V1.3](https://cdn.sparkfun.com/assets/parts/1/2/2/7/5/Laser_Dust_Sensor_Control_Protocol_V1.3.pdf).
4
+
Each response coming from sensor is validated whether it has correct head, command id, checksum and tail.
5
5
Library also handles automatic retries in case of not available / failed response from sensor.
6
6
7
7
## Quickstart
8
-
```
8
+
```arduino
9
9
#include "SdsDustSensor.h"
10
10
11
11
int rxPin = D1;
12
12
int txPin = D2;
13
13
SdsDustSensor sds(rxPin, txPin);
14
+
// SdsDustSensor sds(Serial1); // if you are on a SAMD based board
14
15
15
16
void setup() {
16
17
Serial.begin(9600);
@@ -46,24 +47,30 @@ Communication with sensor can be handled by SoftwareSerial or HardwareSerial. Yo
46
47
47
48
### Using tx and rx pins
48
49
Communication will be implicitly handled by SoftwareSerial.
49
-
```
50
+
```arduino
50
51
int rxPin = D1;
51
52
int txPin = D2;
52
53
SdsDustSensor sds(rxPin, txPin); // you can tune retry mechanism with additional parameters: retryDelayMs and maxRetriesNotAvailable
53
54
sds.begin(); // you can pass custom baud rate as parameter (9600 by default)
54
55
```
55
56
57
+
> This constructor is not available on SAMD based boards.
58
+
> SAMD boards should provide more than enough HardwareSerial ports / SERCOM ports.
59
+
56
60
### Explicit SoftwareSerial
57
-
```
61
+
```arduino
58
62
int rxPin = D1;
59
63
int txPin = D2;
60
64
SoftwareSerial softwareSerial(rxPin, txPin);
61
65
SdsDustSensor sds(softwareSerial); // you can tune retry mechanism with additional parameters: retryDelayMs and maxRetriesNotAvailable
62
66
sds.begin(); // you can pass custom baud rate as parameter (9600 by default)
63
67
```
64
68
69
+
> This constructor is not available on SAMD based boards.
70
+
> SAMD boards should provide more than enough HardwareSerial ports / SERCOM ports.
71
+
65
72
### Explicit HardwareSerial
66
-
```
73
+
```arduino
67
74
SdsDustSensor sds(Serial1); // passing HardwareSerial as parameter, you can tune retry mechanism with additional parameters: retryDelayMs and maxRetriesNotAvailable
68
75
sds.begin(); // you can pass custom baud rate as parameter (9600 by default)
69
76
```
@@ -88,23 +95,23 @@ Additionally you can read device id from every sensor response.
88
95
89
96
### Reading PM2.5 and PM10 values
90
97
The following function (readPm()) checks whether there is available data sent from sensor, it does not send any request to sensor so it has to be in 'active' reporting mode.
91
-
```
98
+
```arduino
92
99
PmResult result = sds.readPm();
93
100
result.pm25; // float
94
101
result.pm10; // float
95
102
```
96
103
97
104
### Querying PM2.5 and PM10 values
98
105
In opposite to above function, this one sends request to sensor and expects the response. Sensor should be in 'query' reporting mode.
99
-
```
106
+
```arduino
100
107
PmResult result = sds.queryPm();
101
108
result.pm25; // float
102
109
result.pm10; // float
103
110
```
104
111
105
112
### Setting custom working period - recommended over continuous
106
113
In order to set custom working period you need to specify single argument - duration (minutes) of the cycle. One cycle means working 30 sec, doing measurement and sleeping for ```duration-30 [sec]```. This setting is recommended when using 'active' reporting mode.
107
-
```
114
+
```arduino
108
115
int cycleMinutes = 4;
109
116
WorkingPeriodResult result = sds.setCustomWorkingPeriod(cycleMinutes);
110
117
result.period; // 4
@@ -114,13 +121,13 @@ result.toString();
114
121
115
122
### Setting reporting mode to 'query'
116
123
When 'query' mode is active the sensor will not send data automatically, you need to send `sds.queryPm()` command on order to measure PM values.
117
-
```
124
+
```arduino
118
125
ReportingModeResult result = sds.setQueryReportingMode();
119
126
result.mode; // MODE::QUERY
120
127
```
121
128
122
129
### Setting sensor state to 'sleeping'
123
-
```
130
+
```arduino
124
131
WorkingStateResult result = sds.sleep();
125
132
result.isWorking(); // false
126
133
```
@@ -130,12 +137,12 @@ Safe wakeup tries to perform wakeup twice to assure proper response from sensor.
130
137
Because of the fact that sensor seems to work correctly (despite invalid response), you can use unsafe method if you don't care about the response.
0 commit comments