Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for particle counts, backwards compatible with PMSx003 #27

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 17 additions & 1 deletion examples/Advanced/Advanced.ino
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,22 @@ void loop()

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

if (data.hasParticles)
{
Serial1.print("Particles > 0.3um: ");
Serial1.println(data.PM_TOTALPARTICLES_0_3);
Serial1.print("Particles > 0.5um: ");
Serial1.println(data.PM_TOTALPARTICLES_0_5);
Serial1.print("Particles > 1.0um: ");
Serial1.println(data.PM_TOTALPARTICLES_1_0);
Serial1.print("Particles > 2.5um: ");
Serial1.println(data.PM_TOTALPARTICLES_2_5);
Serial1.print("Particles > 5.0um: ");
Serial1.println(data.PM_TOTALPARTICLES_5_0);
Serial1.print("Particles > 10.0um: ");
Serial1.println(data.PM_TOTALPARTICLES_10_0);
}
}
else
{
Expand All @@ -39,4 +55,4 @@ void loop()
Serial1.println("Going to sleep for 60 seconds.");
pms.sleep();
delay(60000);
}
}
17 changes: 15 additions & 2 deletions src/PMS.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -133,8 +133,22 @@ void PMS::loop()
_data->PM_AE_UG_1_0 = makeWord(_payload[6], _payload[7]);
_data->PM_AE_UG_2_5 = makeWord(_payload[8], _payload[9]);
_data->PM_AE_UG_10_0 = makeWord(_payload[10], _payload[11]);
}

// Total particles
uint8_t dataWords = _frameLen/2 - 1; // subtract checksum
if (dataWords >= 12) {
_data->PM_TOTALPARTICLES_0_3 = makeWord(_payload[12], _payload[13]);
_data->PM_TOTALPARTICLES_0_5 = makeWord(_payload[14], _payload[15]);
_data->PM_TOTALPARTICLES_1_0 = makeWord(_payload[16], _payload[17]);
_data->PM_TOTALPARTICLES_2_5 = makeWord(_payload[18], _payload[19]);
_data->PM_TOTALPARTICLES_5_0 = makeWord(_payload[20], _payload[21]);
_data->PM_TOTALPARTICLES_10_0 = makeWord(_payload[22], _payload[23]);
_data->hasParticles = true;
}
else {
_data->hasParticles = false;
}
}
_index = 0;
return;
}
Expand All @@ -143,7 +157,6 @@ void PMS::loop()
_calculatedChecksum += ch;
uint8_t payloadIndex = _index - 4;

// Payload is common to all sensors (first 2x6 bytes).
if (payloadIndex < sizeof(_payload))
{
_payload[payloadIndex] = ch;
Expand Down
13 changes: 11 additions & 2 deletions src/PMS.h
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,15 @@ class PMS
uint16_t PM_AE_UG_1_0;
uint16_t PM_AE_UG_2_5;
uint16_t PM_AE_UG_10_0;

// Total particles
uint16_t PM_TOTALPARTICLES_0_3;
uint16_t PM_TOTALPARTICLES_0_5;
uint16_t PM_TOTALPARTICLES_1_0;
uint16_t PM_TOTALPARTICLES_2_5;
uint16_t PM_TOTALPARTICLES_5_0;
uint16_t PM_TOTALPARTICLES_10_0;
bool hasParticles;
};

PMS(Stream&);
Expand All @@ -38,7 +47,7 @@ class PMS
enum STATUS { STATUS_WAITING, STATUS_OK };
enum MODE { MODE_ACTIVE, MODE_PASSIVE };

uint8_t _payload[12];
uint8_t _payload[24];
Stream* _stream;
DATA* _data;
STATUS _status;
Expand All @@ -52,4 +61,4 @@ class PMS
void loop();
};

#endif
#endif