Dust sensor and TTGO ESP32 LoRa V2 1.6

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.

  1. #include <SPI.h>

  2. #include <LoRa.h>

  3. /* Connect to SHARP PM2.5 Sensor*/

  4. #include <PMsensor.h>

  5. PMsensor PM;

  6. #define LEDPOWER 12 //pin where the SHARP is connected

  7. #define MEASUREPIN 36 //pin where the SHARP is connected

  8. //define the pins used by the LoRa transceiver module

  9. #define SCLK 5

  10. #define MISO 19

  11. #define MOSI 27

  12. #define CS 18

  13. #define RST 23

  14. #define DIO 26

  15. #define BAND 915E6 //433E6 for Asia, 866E6 for Europe, 915E6 for North America

  16. //packet counter

  17. int readingID = 0;

  18. int counter = 0;

  19. String LoRaMessage = "";

  20. //Initialize LoRa module

  21. void startLoRA()

  22. {

  23. LoRa.setPins(CS, RST, DIO); //setup LoRa transceiver module

  24. while (!LoRa.begin(BAND) && counter < 10) {

  25. Serial.print(".");
    
  26. counter++;
    
  27. delay(500);
    
  28. }

  29. if (counter == 10)

  30. {

  31. // Increment readingID on every new reading
    
  32. readingID++;
    
  33. Serial.println("Starting LoRa failed!");
    
  34. }

  35. Serial.println("LoRa Initialization OK!");

  36. delay(2000);

  37. }

  38. void startPMsensor()

  39. {

  40. if (isnan(pm))

  41. {

  42. Serial.println("Failed to read from SHARP sensor!");
    
  43. return;
    
  44. }

  45. }

//EN ESTA PARTE ES QUE ME SALE EL ERROR.//

  1. void getReadings() {

  2.  float pm = 0;
    
  3.  int err = pmsensorErrSuccess;
    
  4.  if ((err = pm.read(&pm, true, 0.1)) != pmsensorErrSuccess) { 
    
  5.  Serial.print("data Error = ");
    
  6.  Serial.println(err);
    
  7.  return;
    
  8. }

  9. Serial.print("PM2.5: ");

  10. Serial.print(pm);

  11. Serial.println(" ppm");

  12. }

  13. void sendReadings() {

  14. LoRaMessage = String(readingID) + "/" + String(pm) ;

  15. //Send LoRa packet to receiver

  16. LoRa.beginPacket();

  17. LoRa.print(LoRaMessage);

  18. LoRa.endPacket();

  19. Serial.print("Sending packet: ");

  20. Serial.println(readingID);

  21. readingID++;

  22. Serial.println(LoRaMessage);

  23. }

  24. void setup() {

  25. //initialize Serial Monitor

  26. Serial.begin(115200);

  27. PMsensor.begin();

  28. startPMsensor();

  29. startLoRA();

  30. }

  31. void loop() {

  32. getReadings();

  33. sendReadings();

  34. delay(500);

  35. }

PM is not the same thing as pm.

C++ is case-sensitive.

Please remember to use code tags when posting code AND all of your error messages.

float pm = 0;
 int err = pmsensorErrSuccess;
 if ((err = pm.read(

Here, the compiler will probably mention something about "read" not being defined for objects of type float.

Thanks for your comments, indeed I have an error, request for member 'read' in 'pm', which is of non-class type 'float'

 float pm = 0;
  int err = PMsensorErrSuccess;
  
  if ((err = pm.read(&pm, true, 0.1)) != PMsensorErrSuccess) {
    Serial.print("data Error = ");
    Serial.println(err);
    return;
 if ((err = PM.read(&pm, 

etc?

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.