Skip to content

Commit 4323d65

Browse files
authored
Merge pull request #13 from noerw/master
Support SAMD based boards
2 parents aef12e0 + 92dbc28 commit 4323d65

File tree

5 files changed

+30
-14
lines changed

5 files changed

+30
-14
lines changed

README.md

Lines changed: 20 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,17 @@
11
# Nova Fitness SDS dust sensors arduino library
22
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.
55
Library also handles automatic retries in case of not available / failed response from sensor.
66

77
## Quickstart
8-
```
8+
```arduino
99
#include "SdsDustSensor.h"
1010
1111
int rxPin = D1;
1212
int txPin = D2;
1313
SdsDustSensor sds(rxPin, txPin);
14+
// SdsDustSensor sds(Serial1); // if you are on a SAMD based board
1415
1516
void setup() {
1617
Serial.begin(9600);
@@ -46,24 +47,30 @@ Communication with sensor can be handled by SoftwareSerial or HardwareSerial. Yo
4647

4748
### Using tx and rx pins
4849
Communication will be implicitly handled by SoftwareSerial.
49-
```
50+
```arduino
5051
int rxPin = D1;
5152
int txPin = D2;
5253
SdsDustSensor sds(rxPin, txPin); // you can tune retry mechanism with additional parameters: retryDelayMs and maxRetriesNotAvailable
5354
sds.begin(); // you can pass custom baud rate as parameter (9600 by default)
5455
```
5556

57+
> This constructor is not available on SAMD based boards.
58+
> SAMD boards should provide more than enough HardwareSerial ports / SERCOM ports.
59+
5660
### Explicit SoftwareSerial
57-
```
61+
```arduino
5862
int rxPin = D1;
5963
int txPin = D2;
6064
SoftwareSerial softwareSerial(rxPin, txPin);
6165
SdsDustSensor sds(softwareSerial); // you can tune retry mechanism with additional parameters: retryDelayMs and maxRetriesNotAvailable
6266
sds.begin(); // you can pass custom baud rate as parameter (9600 by default)
6367
```
6468

69+
> This constructor is not available on SAMD based boards.
70+
> SAMD boards should provide more than enough HardwareSerial ports / SERCOM ports.
71+
6572
### Explicit HardwareSerial
66-
```
73+
```arduino
6774
SdsDustSensor sds(Serial1); // passing HardwareSerial as parameter, you can tune retry mechanism with additional parameters: retryDelayMs and maxRetriesNotAvailable
6875
sds.begin(); // you can pass custom baud rate as parameter (9600 by default)
6976
```
@@ -88,23 +95,23 @@ Additionally you can read device id from every sensor response.
8895

8996
### Reading PM2.5 and PM10 values
9097
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
9299
PmResult result = sds.readPm();
93100
result.pm25; // float
94101
result.pm10; // float
95102
```
96103

97104
### Querying PM2.5 and PM10 values
98105
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
100107
PmResult result = sds.queryPm();
101108
result.pm25; // float
102109
result.pm10; // float
103110
```
104111

105112
### Setting custom working period - recommended over continuous
106113
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
108115
int cycleMinutes = 4;
109116
WorkingPeriodResult result = sds.setCustomWorkingPeriod(cycleMinutes);
110117
result.period; // 4
@@ -114,13 +121,13 @@ result.toString();
114121

115122
### Setting reporting mode to 'query'
116123
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
118125
ReportingModeResult result = sds.setQueryReportingMode();
119126
result.mode; // MODE::QUERY
120127
```
121128

122129
### Setting sensor state to 'sleeping'
123-
```
130+
```arduino
124131
WorkingStateResult result = sds.sleep();
125132
result.isWorking(); // false
126133
```
@@ -130,12 +137,12 @@ Safe wakeup tries to perform wakeup twice to assure proper response from sensor.
130137
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.
131138

132139
#### Safe wakeup
133-
```
140+
```arduino
134141
WorkingStateResult result = sds.wakeup();
135142
result.isWorking(); // true
136143
```
137144
#### Unsafe wakeup
138-
```
145+
```arduino
139146
WorkingStateResult result = sds.wakeupUnsafe();
140147
result.isWorking(); // true
141148
```

library.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,5 @@ sentence=A high-level abstaction over Sds sensors family
66
paragraph=Supports Sds011, implements whole Laser Dust Sensor Control Protocol V1.3, should also work with other Sds sensors.
77
category=Sensors
88
url=https://github.com/lewapek/sds-dust-sensors-arduino-library
9-
architectures=avr,esp8266,sam
9+
architectures=avr,esp8266,sam,samd
1010
includes=SdsDustSensor.h

src/SdsDustSensor.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,8 @@
3535

3636
class SdsDustSensor {
3737
public:
38+
39+
#ifndef ARDUINO_SAMD_VARIANT_COMPLIANCE // there is no SoftwareSerial available (needed) on SAMD boards.
3840
SdsDustSensor(int pinRx,
3941
int pinTx,
4042
int retryDelayMs = RETRY_DELAY_MS_DEFAULT,
@@ -53,6 +55,7 @@ class SdsDustSensor {
5355
maxRetriesNotAvailable(maxRetriesNotAvailable) {
5456
sdsStream = abstractSerial->getStream();
5557
}
58+
#endif
5659

5760
SdsDustSensor(HardwareSerial &hardwareSerial,
5861
int retryDelayMs = RETRY_DELAY_MS_DEFAULT,

src/SdsDustSensorResults.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,9 @@
22
#define __SDS_DUST_SENSOR_RESULTS_H__
33

44
#include "SdsDustSensorCommands.h"
5+
#ifndef ARDUINO_SAMD_VARIANT_COMPLIANCE // there is no SoftwareSerial available (needed) on SAMD boards.
56
#include <SoftwareSerial.h>
7+
#endif
68

79
enum class Status {
810
Ok, NotAvailable, InvalidChecksum, InvalidResponseId, InvalidHead, InvalidTail

src/Serials.h

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
#ifndef __SDS_ABSTRACT_SERIAL_H__
22
#define __SDS_ABSTRACT_SERIAL_H__
33

4+
#ifndef ARDUINO_SAMD_VARIANT_COMPLIANCE // there is no SoftwareSerial available (needed) on SAMD boards.
45
#include <SoftwareSerial.h>
6+
#endif
57
#include <HardwareSerial.h>
68

79
namespace Serials {
@@ -34,6 +36,7 @@ namespace Serials {
3436
HardwareSerial &serial;
3537
};
3638

39+
#ifndef ARDUINO_SAMD_VARIANT_COMPLIANCE // there is no SoftwareSerial available (needed) on SAMD boards.
3740
struct Software: public AbstractSerial {
3841
Software(SoftwareSerial &serial): serial(serial) {}
3942

@@ -68,6 +71,7 @@ namespace Serials {
6871

6972
SoftwareSerial *serial;
7073
};
74+
#endif // ARDUINO_SAMD_VARIANT_COMPLIANCE
7175

7276
}
7377

0 commit comments

Comments
 (0)