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

Cannot get output from Arduino #29

Open
rudvfaden opened this issue Jun 11, 2023 · 2 comments
Open

Cannot get output from Arduino #29

rudvfaden opened this issue Jun 11, 2023 · 2 comments

Comments

@rudvfaden
Copy link

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...
}
@Just-ice-E
Copy link

Just-ice-E commented Jul 29, 2023

I have a similar issue, I cannot get my sensor (PMS5003) to interface with my Nano and output to Serial Monitor. I have a DHT sensor interfacing also to verify that the code is working. From the PMS5003 the Tx -> D3, Rx -> D2. Also the fan kicks on so I know the sensor is receiving power but I am not sure why I can't get it to read at all, let alone reading from the sensor.

Here is my code:

#include "DHT.h"
#include "PMS.h"
#include "SoftwareSerial.h"

#define DHTPIN 13 // Digital pin connected to the DHT sensor
#define DHTTYPE DHT22 // DHT 22 (AM2302), AM2321

DHT dht(DHTPIN, DHTTYPE);

SoftwareSerial Serial1(3,2); // RX, TX
PMS pms(Serial1);
PMS::DATA data;

void setup() {
Serial.begin(9600);
Serial.println(F("DHTxx test!"));

dht.begin();

Serial1.begin(9600);
Serial.println("Warming up");
}

void loop() {
// Wait a few seconds between measurements.
delay(2000);

float h = dht.readHumidity();
// Read temperature as Celsius (the default)

// Check if any reads failed and exit early (to try again).
if (isnan(h)) {
Serial.println(F("Failed to read from DHT sensor!"));
return;
}

Serial.print(F("Humidity: "));
Serial.println(h);

if (pms.read(data)) {
Serial.println("PM reading good"); //This is the real problem area, I can't even get the code to output anything
}
}

@fu-hsi
Copy link
Owner

fu-hsi commented Jul 29, 2023

@Just-ice-E you can't block main loop like these:

// Wait a few seconds between measurements.
delay(2000);

Please use examples provided with library.
You can also use passive mode and then you will be able to block with the main loop.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants