Skip to content

Commit

Permalink
Sent from my oven.
Browse files Browse the repository at this point in the history
  • Loading branch information
fu-hsi committed Oct 3, 2017
1 parent 6792921 commit 75f011f
Show file tree
Hide file tree
Showing 11 changed files with 493 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -301,3 +301,8 @@ $RECYCLE.BIN/

# Windows shortcuts
*.lnk
*.xml
*.filters
*.vcxproj
examples/Basic/__vm/.Basic.vsarduino.h
examples/Advanced/__vm/.Advanced.vsarduino.h
21 changes: 21 additions & 0 deletions LICENSE
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
The MIT License (MIT)

Copyright (c) 2017 Mariusz Kacki

Permission is hereby granted, free of charge, to any person obtaining a copy
of this software and associated documentation files (the "Software"), to deal
in the Software without restriction, including without limitation the rights
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
copies of the Software, and to permit persons to whom the Software is
furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
146 changes: 146 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,146 @@
# PMS Library
Arduino library for Plantower PMS sensors.
Supports PMS x003 sensors (1003, 3003, 5003, 6003, 7003).
## Installation
Just use Arduino Library Manager and search "PMS Library" in Sensors category.
## Main assumptions
- easy as possible,
- minimal memory consumption,
- non-blocking functions,
- supporting a wide range of PMS sensors from Plantower,
- supporting additional modes e.g.: sleeping, passive, active (depends on the sensor model).

As a data source you can use **any object** that implements the **Stream class**, such as Wire, Serial, EthernetClient, e.t.c.
## Basic example
Read in active mode.
> Default mode is active after power up. In this mode sensor would send serial data to the host automatically. The active mode is divided into two sub-modes: stable mode and fast mode. If the concentration change is small the sensor would run at stable mode with the real interval of 2.3s. And if the change is big the sensor would be changed to fast mode automatically with the interval of 200~800ms, the higher of the concentration, the shorter of the interval.
```cpp
#include "PMS.h"

PMS pms(Serial);
PMS::DATA data;

void setup()
{
Serial.begin(9600); // GPIO1, GPIO3 (TX/RX pin on ESP-12E Development Board)
Serial1.begin(9600); // GPIO2 (D4 pin on ESP-12E Development Board)
}

void loop()
{
// Non-blocking function
if (pms.read(data))
{
Serial1.println("Data:");

Serial1.print("PM 1.0 (ug/m3): ");
Serial1.println(data.PM_AE_UG_1_0);

Serial1.print("PM 2.5 (ug/m3): ");
Serial1.println(data.PM_AE_UG_2_5);

Serial1.print("PM 10.0 (ug/m3): ");
Serial1.println(data.PM_AE_UG_10_0);

Serial1.println();
}
}
```
## Output
```
Data:
PM 1.0 (ug/m3): 13
PM 2.5 (ug/m3): 18
PM 10.0 (ug/m3): 23

Data:
PM 1.0 (ug/m3): 13
PM 2.5 (ug/m3): 18
PM 10.0 (ug/m3): 23

Data:
PM 1.0 (ug/m3): 12
PM 2.5 (ug/m3): 19
PM 10.0 (ug/m3): 24
```
## Advanced example
Read in passive mode but not the best way (see additional remarks).
```cpp
#include "PMS.h"
PMS pms(Serial);
PMS::DATA data;
void setup()
{
Serial.begin(9600); // GPIO1, GPIO3 (TX/RX pin on ESP-12E Development Board)
Serial1.begin(9600); // GPIO2 (D4 pin on ESP-12E Development Board)
pms.passiveMode(); // Switch to passive mode
}
void loop()
{
Serial1.println("Wake up and wait 30 seconds for stable readings...");
pms.wakeUp();
delay(30000);
Serial1.println("Send request read...");
pms.requestRead();
Serial1.println("Wait max. 10 seconds for read (blocking function)...");
if (pms.read(data, 10000))
{
Serial1.println("Data:");
Serial1.print("PM 1.0 (ug/m3): ");
Serial1.println(data.PM_AE_UG_1_0);
Serial1.print("PM 2.5 (ug/m3): ");
Serial1.println(data.PM_AE_UG_2_5);
Serial1.print("PM 10.0 (ug/m3): ");
Serial1.println(data.PM_AE_UG_10_0);
Serial1.println();
}
else
{
Serial1.println("No data.");
}
Serial1.println("Going to sleep for 60 seconds.");
pms.sleep();
delay(60000);
}
```
## Output
```
Wake up, wait 30 seconds for stable readings...
Send request read...
Wait max. 10 seconds for read...
Data:
PM 1.0 (ug/m3): 18
PM 2.5 (ug/m3): 24
PM 10.0 (ug/m3): 24
Going to sleep for 60 seconds.
Wake up, wait 30 seconds for stable readings...
Send request read...
Wait max. 10 seconds for read...
Data:
PM 1.0 (ug/m3): 20
PM 2.5 (ug/m3): 30
PM 10.0 (ug/m3): 40
Going to sleep for 60 seconds.
```
## Additional remarks
Tested with PMS 7003 and ESP-12E Development Board.
All Plantower PMS sensors uses the same protocol (let me know if you have any problems).

Please consider, that delay() function in examples is a blocking function.
Try to avoid such a solution if your project requires it.

For more accurate measurements, you can read several samples (in passive or active mode) and calculate the average.
> Stable data should be got at least 30 seconds after the sensor wakeup from the sleep mode because of the fan's performance.
> I got nice resuylt in active mode.
Personally, I get more repeatable measurements in active mode (Basic example).
44 changes: 44 additions & 0 deletions examples/Advanced/Advanced.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#include "PMS.h"

PMS pms(Serial);
PMS::DATA data;

void setup()
{
Serial.begin(9600); // GPIO1, GPIO3 (TX/RX pin on ESP-12E Development Board)
Serial1.begin(9600); // GPIO2 (D4 pin on ESP-12E Development Board)
pms.passiveMode(); // Switch to passive mode
}

void loop()
{
Serial1.println("Wake up, wait 30 seconds for stable readings...");
pms.wakeUp();
delay(30000);

Serial1.println("Send request read...");
pms.requestRead();

Serial1.println("Wait max. 10 seconds for read...");
if (pms.read(data, 10000))
{
Serial1.println("Data:");

Serial1.print("PM 1.0 (ug/m3): ");
Serial1.println(data.PM_AE_UG_1_0);

Serial1.print("PM 2.5 (ug/m3): ");
Serial1.println(data.PM_AE_UG_2_5);

Serial1.print("PM 10.0 (ug/m3): ");
Serial1.println(data.PM_AE_UG_10_0);
}
else
{
Serial1.println("No data.");
}

Serial1.println("Going to sleep for 60 seconds.");
pms.sleep();
delay(60000);
}
29 changes: 29 additions & 0 deletions examples/Basic/Basic.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
#include "PMS.h"

PMS pms(Serial);
PMS::DATA data;

void setup()
{
Serial.begin(9600); // GPIO1, GPIO3 (TX/RX pin on ESP-12E Development Board)
Serial1.begin(9600); // GPIO2 (D4 pin on ESP-12E Development Board)
}

void loop()
{
if (pms.read(data))
{
Serial1.println("Data:");

Serial1.print("PM 1.0 (ug/m3): ");
Serial1.println(data.PM_AE_UG_1_0);

Serial1.print("PM 2.5 (ug/m3): ");
Serial1.println(data.PM_AE_UG_2_5);

Serial1.print("PM 10.0 (ug/m3): ");
Serial1.println(data.PM_AE_UG_10_0);

Serial1.println();
}
}
Binary file added extras/ESP-12E.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added extras/Schematic.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
34 changes: 34 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
#######################################
# Syntax Coloring Map For PMS Library
#######################################

#######################################
# Datatypes (KEYWORD1)
#######################################

PMS KEYWORD1

#######################################
# Methods and Functions (KEYWORD2)
#######################################

sleep KEYWORD2
wakeUp KEYWORD2
activeMode KEYWORD2
passiveMode KEYWORD2
requestRead KEYWORD2
read KEYWORD2
loop KEYWORD2

#######################################
# Instances (KEYWORD2)
#######################################

#######################################
# Constants (LITERAL1)
#######################################

STATUS_WAITING LITERAL1
STATUS_OK LITERAL1
MODE_ACTIVE LITERAL1
MODE_PASSIVE LITERAL1
9 changes: 9 additions & 0 deletions library.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
name=PMS Library
version=1.0.0
author=Mariusz Kacki <[email protected]>
maintainer=Mariusz Kacki <[email protected]>
sentence=Arduino library for Plantower PMS sensors.
paragraph=Supports PMS x003 sensors (1003, 3003, 5003, 6003, 7003).
category=Sensors
url=https://github.com/fu-hsi/pms
architectures=*
Loading

0 comments on commit 75f011f

Please sign in to comment.