Good evening dear. I am new to the Arduino world, I am trying to create a system in which measurements can be made with the GP2Y1010AU0F dust sensor connected to a TTGO ESP32 LoRa V2 1.6 to be able to send the data to another ESP32 LoRa; But in the code I have an error ('pm' was not declared in this scope). Please if you help me correct my code or give me advice.
Beforehand thank you very much.
Best regards.
-
#include <SPI.h>
-
#include <LoRa.h>
-
/* Connect to SHARP PM2.5 Sensor*/
-
#include <PMsensor.h>
-
PMsensor PM;
-
#define LEDPOWER 12 //pin where the SHARP is connected
-
#define MEASUREPIN 36 //pin where the SHARP is connected
-
//define the pins used by the LoRa transceiver module
-
#define SCLK 5
-
#define MISO 19
-
#define MOSI 27
-
#define CS 18
-
#define RST 23
-
#define DIO 26
-
#define BAND 915E6 //433E6 for Asia, 866E6 for Europe, 915E6 for North America
-
//packet counter
-
int readingID = 0;
-
int counter = 0;
-
String LoRaMessage = "";
-
//Initialize LoRa module
-
void startLoRA()
-
{
-
LoRa.setPins(CS, RST, DIO); //setup LoRa transceiver module
-
while (!LoRa.begin(BAND) && counter < 10) {
-
Serial.print(".");
-
counter++;
-
delay(500);
-
}
-
if (counter == 10)
-
{
-
// Increment readingID on every new reading
-
readingID++;
-
Serial.println("Starting LoRa failed!");
-
}
-
Serial.println("LoRa Initialization OK!");
-
delay(2000);
-
}
-
void startPMsensor()
-
{
-
if (isnan(pm))
-
{
-
Serial.println("Failed to read from SHARP sensor!");
-
return;
-
}
-
}
//EN ESTA PARTE ES QUE ME SALE EL ERROR.//
-
void getReadings() {
-
float pm = 0;
-
int err = pmsensorErrSuccess;
-
if ((err = pm.read(&pm, true, 0.1)) != pmsensorErrSuccess) {
-
Serial.print("data Error = ");
-
Serial.println(err);
-
return;
-
}
-
Serial.print("PM2.5: ");
-
Serial.print(pm);
-
Serial.println(" ppm");
-
}
-
void sendReadings() {
-
LoRaMessage = String(readingID) + "/" + String(pm) ;
-
//Send LoRa packet to receiver
-
LoRa.beginPacket();
-
LoRa.print(LoRaMessage);
-
LoRa.endPacket();
-
Serial.print("Sending packet: ");
-
Serial.println(readingID);
-
readingID++;
-
Serial.println(LoRaMessage);
-
}
-
void setup() {
-
//initialize Serial Monitor
-
Serial.begin(115200);
-
PMsensor.begin();
-
startPMsensor();
-
startLoRA();
-
}
-
void loop() {
-
getReadings();
-
sendReadings();
-
delay(500);
-
}