putting PMS5003 into "passive" mode

Breakout boards, sensors, other Adafruit kits, etc.

Moderators: adafruit_support_bill, adafruit

Please be positive and constructive with your questions and comments.
Locked
User avatar
earthres
 
Posts: 221
Joined: Fri May 28, 2021 10:48 am

putting PMS5003 into "passive" mode

Post by earthres »

I am using the Adafruit library for getting particulate data from your PMS5003. As I understand it, this sensor has an "active" mode that sends a data stream about once per second, and a "passive" mode that sends data only on request. The "active" mode is the default mode, as implemented in the sample code with the library. (right?) Do you have an example code that puts the PMS5003 in "passive" mode and sends a data stream only on request?

User avatar
mikeysklar
 
Posts: 13936
Joined: Mon Aug 01, 2016 8:10 pm

Re: putting PMS5003 into "passive" mode

Post by mikeysklar »

@earthres,

There is a chunk of code using passive mode in an issue here using the pms5003 library.

https://github.com/jbanaszczyk/pms5003/issues/8

This looks like the juicy bit...Full code below...Keep in mind it's from an old issue.

Code: Select all

pms.write(Pmsx003::cmdModePassive);

Code: Select all

#include <Arduino.h>
#include <pms.h>

Pmsx003 pms(D6, D7); //Wemos RX-D7, TX-D6

////////////////////////////////////////

void setup(void) {
Serial.begin(115200);
while (!Serial) {};
Serial.println("Pmsx003");

pms.begin();
//pms.waitForData(Pmsx003::wakeupTime);
//pms.write(Pmsx003::cmdModeActive);
//pms.write(Pmsx003::cmdModePassive);
}

////////////////////////////////////////

auto lastRead = millis();

void loop(void) {
delay(30000);
pms.write(Pmsx003::cmdWakeup);
pms.waitForData(Pmsx003::wakeupTime);
pms.write(Pmsx003::cmdModeActive);
delay(30000);
const auto n = Pmsx003::Reserved;
Pmsx003::pmsData data[n];

Pmsx003::PmsStatus status = pms.read(data, n);

switch (status) {
	case Pmsx003::OK:
	{
		Serial.println("_________________");
		auto newRead = millis();
		Serial.print("Wait time ");
		Serial.println(newRead - lastRead);
		lastRead = newRead;

		// For loop starts from 3
		// Skip the first three data (PM1dot0CF1, PM2dot5CF1, PM10CF1)
		for (size_t i = Pmsx003::PM1dot0; i < n; ++i) { 
			Serial.print(data[i]);
			Serial.print("\t");
			Serial.print(Pmsx003::dataNames[i]);
			Serial.print(" [");
			Serial.print(Pmsx003::metrics[i]);
			Serial.print("]");
			Serial.println();
		}
		break;
	}
	case Pmsx003::noData:
		break;
	default:
		Serial.println("_________________");
		Serial.println(Pmsx003::errorMsg[status]);
pms.write(Pmsx003::cmdModePassive);
//pms.write(Pmsx003::cmdSleep);
};

}`

Locked
Please be positive and constructive with your questions and comments.

Return to “Other Products from Adafruit”