-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPMS5003.h
More file actions
65 lines (55 loc) · 2.72 KB
/
PMS5003.h
File metadata and controls
65 lines (55 loc) · 2.72 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/*
* Library to work with Plantower PMS5003 dust sensor via UART
* http://www.plantower.com/en/content/?108.html
* http://www.aqmd.gov/docs/default-source/aq-spec/resources-page/plantower-pms5003-manual_v2-3.pdf
* https://publiclab.org/questions/samr/04-07-2019/how-to-interpret-pms5003-sensor-values
* It is assumed that the sensor works in active mode.
* So [Sensor TX] --> [MCU RX] connection used only.
*
* Written by Sergey Trofimov
* https://github.com/tms320/PMS5003
*
* GNU General Public License v3.0
*/
#pragma once
#include <Arduino.h>
#include <SoftwareSerial.h>
class PMS5003
{
public:
PMS5003();
PMS5003(HardwareSerial &hwSerial, int8_t sleepPin = -1, bool sleep = false); // use for hardware UART
PMS5003(uint8_t rxPin, bool invert = false, int8_t sleepPin = -1, bool sleep = false); // use for software UART
~PMS5003();
bool init(HardwareSerial &hwSerial, int8_t sleepPin = -1, bool sleep = false); // use for hardware UART
bool init(uint8_t rxPin, bool invert = false, int8_t sleepPin = -1, bool sleep = false); // use for software UART
bool isReady(); // returns 'true' when preheat timed out (after startup or wake up)
bool isSleeping(); // returns 'true' if sensor is in sleeping state
bool Sleep(); // returns 'true' on success
bool WakeUp(); // returns 'true' on success
int getData(); // negative value is seconds left to preheat; 0 - error; 1 - success
// Data:
uint16_t pm1p0std; // PM1.0 concentration, ug/m3 (standard particle, factory environment)
uint16_t pm2p5std; // PM2.5 concentration, ug/m3 (standard particle, factory environment)
uint16_t pm10std; // PM10 concentration, ug/m3 (standard particle, factory environment)
uint16_t pm1p0atm; // PM1.0 concentration, ug/m3 (under atmospheric environment)
uint16_t pm2p5atm; // PM2.5 concentration, ug/m3 (under atmospheric environment)
uint16_t pm10atm; // PM10 concentration, ug/m3 (under atmospheric environment)
uint16_t nc0p3um; // number of particles with diameter beyond 0.3um in 0.1 litre of air
uint16_t nc0p5um; // number of particles with diameter beyond 0.5um in 0.1 litre of air
uint16_t nc1p0um; // number of particles with diameter beyond 1.0um in 0.1 litre of air
uint16_t nc2p5um; // number of particles with diameter beyond 2.5um in 0.1 litre of air
uint16_t nc5p0um; // number of particles with diameter beyond 5.0um in 0.1 litre of air
uint16_t nc10um; // number of particles with diameter beyond 10um in 0.1 litre of air
private:
static const int64_t PREHEAT_TIME = 60000; // ms
bool _isReady;
bool _isSleeping;
HardwareSerial* _hwSerial;
SoftwareSerial* _swSerial;
Stream* _uart;
int64_t _wakeUpTime;
int8_t _sleepPin, _resetPin;
void initSleepPin(int8_t sleepPin, bool sleep);
int getDataInternal(int64_t startTime);
};