fu-hsi / pms Goto Github PK
View Code? Open in Web Editor NEWArduino library for Plantower PMS x003 family sensors.
License: MIT License
Arduino library for Plantower PMS x003 family sensors.
License: MIT License
Hello @fu-hsi ,
i would like to use the PMS library in a .ino sketch for the board NodeMCU in subject.
I need to understand which PMS5003 pins must be connected to which NodeMCU pins and how to specify in the .ino which NodeMCU pins i am using.
I saw somewhere that +5V can be got from NodeMCU VIN ..is it true?
I am going to connect in this way:
NODEMCU -- PMS5003:
VIN -- PIN1
GND -- PIN2
RX -- PIN5 (TXD)
TX -- PIN4 (RXD)
Is it right?
I have to connect the PMS5003 PIN3 (SET) and PIN6 (RESET) too, or they can be left unconnected?
THANK YOU!
Hi,
I am trying to use your code, with a Geniunie Arduino Uno, connected with de AirQuality Monitor (from Plantower) with de PM2.5 Sensor Adpater with a IO Expansion Shield V7.1. Just as the wiki indicates to connect the Air Quality Sensor to the arduino.
When I´m trying to upload the code to the Arduino it generates the following error code:
avrdude: stk500_recv (): programmer is not responding
avrdude: stk500_getsync () attempt 1 of 10: not in sync: resp = 0xb0
avrdude: stk500_recv (): programmer is not responding
avrdude: stk500_getsync () attempt 2 of 10: not in sync: resp = 0xb0
avrdude: stk500_recv (): programmer is not responding
avrdude: stk500_getsync () attempt 3 of 10: not in sync: resp = 0xb0
avrdude: stk500_recv (): programmer is not responding
avrdude: stk500_getsync () attempt 4 of 10: not in sync: resp = 0xb0
avrdude: stk500_recv (): programmer is not responding
avrdude: stk500_getsync () attempt 5 of 10: not in sync: resp = 0xb0
avrdude: stk500_recv (): programmer is not responding
avrdude: stk500_getsync () attempt 6 of 10: not in sync: resp = 0xb0
avrdude: stk500_recv (): programmer is not responding
avrdude: stk500_getsync () attempt 7 of 10: not in sync: resp = 0xb0
avrdude: stk500_recv (): programmer is not responding
avrdude: stk500_getsync () attempt 8 of 10: not in sync: resp = 0xb0
avrdude: stk500_recv (): programmer is not responding
avrdude: stk500_getsync () attempt 9 of 10: not in sync: resp = 0xb0
avrdude: stk500_recv (): programmer is not responding
avrdude: stk500_getsync () attempt 10 of 10: not in sync: resp = 0xb0
I do not know if this is a known problem or if you know how to fix it.
As a note, if I disconnect the PM2.5 Sesor adapter from the Expansion Shield it is possible to load the code, but it does not work when I connect it again. Finally, I have an MQ9 sensor that I´m using with the IO expansion shield and it works properly. So, I´m thinking the problem may be in the code for the Air Quality Sensor ( I have two sensors, just in case, and both have the same problem, and I try with mac and pc).
I will be very grateful for your help, greetings from now,
Can this lib be used in ESP32?
Hi @fu-hsi
is it possible to integrate a functionality for capturing sensing data on Particles of 0.5 um and 0.3 um in you're library? as the PMS7003 can capture these.
maybe you already have this functionality, I've just not been able to find it in your doc.
best regard
Hi guys,
Should not pms.sleep();
turn the fan off? I have feeling that in my case sleep does not work well, because I do not see power consumption difference between an active mode and sleep mode. And at this point, I'm wondering if it is only software sleep and fan should work all the time or maybe it should sleep as well but my code is not working properly :)
Thank you@
Trying to use the Basic sketch just to make sure everything works, but pms.read always returns "false" so I never get to see if any data is written.
PMS7003 is connected to verified +5v and GND on pins 1/2 (labeled VCC and GND on the breakout board) and the fan spins up. Pin 9 (TX) on the PMS is connected to Serial RX on a NodeMCU/ESP8266 and RX on the PMS is connected to TX on the NodeMCU.
Is there any troubleshooting for figuring out why a PMS sensor isn't recognized?
Looks familiar?
id dt pm1 pm25 pm10
------ ------------------- ------ ------ --------
134853 2018-11-24 13:22:59 (NULL) (NULL) (NULL)
134852 2018-11-24 13:20:13 16 30 36
134851 2018-11-24 13:17:27 14 30 36
134850 2018-11-24 13:14:42 12 26 32
134849 2018-11-24 13:11:58 10 24 24
134848 2018-11-24 13:09:12 8 20 20
134847 2018-11-24 13:06:28 8 20 20
134846 2018-11-24 13:03:42 2 16 16
134845 2018-11-24 13:00:58 (NULL) (NULL) (NULL)
134844 2018-11-24 12:58:12 14 24 34
134843 2018-11-24 12:55:27 12 22 34
134842 2018-11-24 12:52:43 10 22 24
134841 2018-11-24 12:49:58 10 18 18
134840 2018-11-24 12:47:12 6 16 16
134839 2018-11-24 12:44:28 4 16 16
134838 2018-11-24 12:41:42 0 6 6
134837 2018-11-24 12:38:58 (NULL) (NULL) (NULL)
In passive mode I receive NULL values from PMS 7003 sensor with constant intervals.
I have not received any complaints from others, these are my observations only.
Simple solution without modify library:
Increase default timeout value for readUntil().
E.g.
pms.readUntil(data, 2000);
In next release I will use flush() after all commands to the sensor to be sure that the whole message has arrived.
Hello,
Thanks for this library.
I am attempting to use the PMS5003 via breakout board with an Arduino UNO.
I am using SoftwareSerial.h to create a Serial1 with Uno Pins 2,3.
However, I cannot see any readings from the PMS5003 unit.
Please advise on my next step? Thank you
Jason
My setup:
Sensor TX -> Arduino PIN 2
Sensor RX -> Arduino PIN 3
5V to 5V, GND to GND
Reset and EN pin not plugged in
My code:
#include <PMS.h>
#include <SoftwareSerial.h>
SoftwareSerial Serial1(2,3);
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)) {
Serial.print("reading 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();
}
// Do other stuff...
}
So I am building an Air Quality Meter and I wanted to use your library. Because it is the easiest to read and use. The only problem is it doesn't have any of the "particles with diameter beyond 0.x um in 0.1L of air." They are the last three data packets in the PMS's UART package. I'll will try to add them in my own branch but Im not a big C++ guy.
Jeff
This is what I found, using a delay after the loop() execute I always get an error,
Using the Simple test Adding a 5 seconds delay just before the LOOP() end, I get the sum error almost immediately after the first read., then more sumerrors.
It seems to be related to timing, since if the delay is 500ms, no error occur.
here are the last pieces of code with the simple test that ALWAYS create the error, how can I fix it, please?
case Pmsx003::noData:
break;
default:
Serial.println("_________________");
Serial.println(Pmsx003::errorMsg[status]);
};
delay(5000); // this delay create a constant sumError if delay is 500 ms no error
}
Hi,
with ESP32 Wroom Dev Board I get only 0 values for all PM sizes every second.
I'm powering the PMS 7003 with 5V (with 3.3V on RX TX)
If I put this in loop: Serial.println(Ser1_33_32_PMS7003.read());
I get every second changing, but not plausible measurement values. See output example:
117:50:38.875 -> 203
17:50:39.466 -> 77
17:50:39.504 -> 0
17:50:39.537 -> 50
17:50:39.605 -> 0
17:50:39.639 -> 0
17:50:39.712 -> 0
17:50:39.748 -> 0
17:50:39.783 -> 205
17:50:40.290 -> 77
17:50:40.358 -> 0
17:50:40.396 -> 50
17:50:40.429 -> 0
17:50:40.497 -> 0
17:50:40.534 -> 0
17:50:40.602 -> 0
17:50:40.635 -> 205
17:50:41.230 -> 77
17:50:41.264 -> 0
17:50:41.297 -> 32
17:50:41.367 -> 0
17:50:41.401 -> 0
17:50:41.469 -> 0
17:50:41.503 -> 0
17:50:41.571 -> 183
Thank you for your help!
Robię update programu przez webupdate. Dotąd wykonałem dwa takie update w momencie, gdy PMS3003 jest uśpiony. Po restarcie ESP i wywołaniu pms.wakeUp() nie są dokonywane pomiary. Oczywiście wentylatora nie słychać. Dopiero po przejściu całej pętli i ponownym pms.wakeUp() pomiary są wykonywane normalnie. Czytałem w pliku expert komentarz, że trzeba pms wybudzić ręcznie, bo po restarcie może nie dokonać pomiaru.
Podobna sytuacja jest, gdy wcisnę reset na płytce. Też pms nie jest wybudzany przy pierwszym przejściu pętli.
Czyżbym musiał pms uśpić w setup() i zaraz go budzić?
Hi guys, does anyone know how to deal with putting PMS7003 into sleep mode using ESP8266 NodeMCU?
I tried a lot of different methods posted on "Issues" but nothing works for me. Has anyone dealt with it so it’s working properly? I know that the sleep mode isn't working because the fan keeps spinning 😕
Below there is my code for using PMS. (I skipped the parts with sending it to ThingSpeak, connecting to WiFi etc.)
#include <SoftwareSerial.h>
#include "PMS.h"
SoftwareSerial serialDust(11, 12); // RX, TX
PMS pms(serialDust);
PMS::DATA data;
void setup()
{
Serial.begin(9600);
serialDust.begin(9600);
pms.passiveMode();
pms.wakeUp();
delay(30000);
pms.requestRead();
if (pms.readUntil(data))
{
PM_1_0=data.PM_AE_UG_1_0;
PM_2_5=data.PM_AE_UG_2_5;
PM_10_0=data.PM_AE_UG_10_0;
}
Serial.flush();
pms.sleep();
Serial.flush();
ESP.deepSleep(300 * 1e6);
}
void loop() {
}
Thanks in advance.
Thank you for this nice library.
I have a problem where I do not get a read if certain GPIO pins are used for I2c.
If I use the default (SDA = 4 - SCL = 5) it works properly.
However if I use SDA = 0 - SCL = 2 I will not get a reads.
It's easy to test by adding ...
Wire.pins(0, 2);
Wire.begin();
As I have hardware already using those pins I don't have a choice.
I have used SDA = 0 - SCL = 2 with many libs without a problem.
I didn't see anything obvious in your code. I don't understand why it doesn't work.
Appreciate any help. Thanks
I use a PMS7003 and the sleep command does not stop the fan. If I short the SET pin to GND the fan stops.
When I change the basic.ino script at line 28 with a simple delay(3000);
I do not get any values.
Probably there is no complete packet to analyse? So the value pms.read(data) is 0?
How can that be solved? I want to run the PMS script in a larger script where a lot of sensors are read. So it takes time to get back to if (pms.read(data))
I solved it already with a for loop. But is there a smarter way?
for (int i = 0; i <= 200; i++) {
Serial.print(i);
if (pms.read(data))
{
Serial.print("\nPM 1.0: ");Serial.print(data.PM_AE_UG_1_0); Serial.print(", ");
Serial.print("PM 2.5: ");Serial.print(data.PM_AE_UG_2_5); Serial.print(", ");
Serial.print("PM 10: ");Serial.print(data.PM_AE_UG_10_0);
i = 200;
}
}
Could you use the reset and power safe mode pins, so it turn off the fan as well?
According to Plantower doc:
PIN3 is SET (3.3V logic)
SET=1 module is in the working state, and the module is electrically active to send data (serial mode).
Instruction change working mode
SET=0 module into low power standby mode
PIN6 is RESET (3.3V logic)
JBanaszczyk incorporated those into his library https://github.com/jbanaszczyk/pms5003 for ESP8266, but it seems to be incompatible with ESP32.
Hello,
I went through the spec sheet of the PMS5003 and I have a couple of question about sleep/wake that I couldn't find in the specsheet neither the lib documentation and I hope you can help me with them.
Hi,
I like this library and use it with ESP32 without any problem . I recently migrated to raspberry picow and tried this library but it didn’t work. The code compiled fine but there is No Data from sensor. Are there any plans for supporting raspberry picow? Thanks
Could be this library adopted to Ardino (Uno, Mega, ...)?
Thank You!
Thank you for the library.
I have issue getting output on Arduino r3. I have connected my rxd to pin6 and txd to pin 4 and I use this code.
I was hoping you could guide me in the right direction.
#include "PMS.h"
#include <SoftwareSerial.h>
SoftwareSerial Serial1(4,6);
PMS pms(Serial1);
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.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();
}
// Do other stuff...
}
Hi,
I hope this is still active, as I would really like to use your code for my PMS5003 on the ESP32 WROOM. When uploading the basic code (after downloading the library) to my esp32 it displays thefollowing:
⸮!⸮H⸮�>⸮\x⸮K⸮$�⸮
At first I thought it had something to do with the baud rate, but this is set to 9600.
Do you have a clue what might be the issue here?
Thanks,
Bas
Hello, i'm a noob. What is the suppoused wiring for an ESP32 wroom? I can use any pin i want? I'd like to implement the "sleep" functionality
FYI I was facing the same problem as described in #6. I solved it by adding a flush() on the serial port used for printing status BEFORE calling pms.sleep(). (In #6 author recommended adding a flush on pms serial port after calling pms.sleep() which was not helping.)
Adjusted advanced example using SoftwareSerial:
#include <SoftwareSerial.h> // using SoftwareSerial might create problems in activating sleep mode, see additional Serial.flush(); below
#include "PMS.h"
SoftwareSerial serialDust(11, 12); // RX, TX
PMS pms(serialDust);
PMS::DATA data;
void setup()
{
// Serial Port setups
Serial.begin(9600); // used for print output
serialDust.begin(9600); // software serial for dust sensor
pms.passiveMode(); // Switch to passive mode
}
void loop()
{
Serial.println("Waking up, wait 30 seconds for stable readings...");
pms.wakeUp();
delay(30000);
Serial.println("Send read request...");
pms.requestRead();
if (pms.readUntil(data)) {
Serial.print("PM 1.0 (ug/m3): ");
Serial.println(data.PM_AE_UG_1_0);
Serial.print("PM 2.5 (ug/m3): ");
Serial.println(data.PM_AE_UG_2_5);
Serial.print("PM 10.0 (ug/m3): ");
Serial.println(data.PM_AE_UG_10_0);
Serial.println();
} else {
Serial.println("No data.");
}
Serial.println("Going to sleep for 60 seconds.");
Serial.flush(); // IMPORTANT when using software serial
pms.sleep();
delay(60000);
}
Tested on Arduino Nano with PMS7003 sensor.
Otherwise, thanks a lot for setting up this very clean library!
I just found on this tutorial:
http://kstobbe.dk/2019/02/16/esp32-pms5003-bme280-mics6814-sensor-build/
using blocking read:
if (pms.readUntil(data, 2*PMS::SINGLE_RESPONSE_TIME))
and this effectively allow me to read data from PMS5003.
Just to confirm it output data each 800ms:
but I see all around people using non blocking read:
if (pms.read(data))
This give me reads randomly (some reads after reset, no reads at all...)
Any background about what could be the reason? Just trying to figure out how to use the sensor properly
Hello,
When calling pms.sleep() it goes to sleep but it immediately wakes up.
Is this proper behavior? What about the SET pin?
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.