Weird error during compilation

Hi all,
first of all please pardon a noob if I use the wrong theme !
I try to compile a sketch for ESP32 with LoRa chip.
This sketch compiled without error before. After a few modifications it suddenly complains about an error at a line which isn't existing in the sketch. Please see for yourself.

Compile Errors 1.txt (1,7 KB)
LoRaSender01.ino (4,3 KB)

I have uninstalled the Arduino IDE and deleted all related folders (e.g. libraries) except the sketch folder and re-installed the IDE.
Error remains the same.
I'm somewhat baffled what is happening.
If anybody has a (good :wink:) tip for me I will be grateful !
Thanks Peter

The sketch you posted does not match the error messages, errors from the sketch are about 30 lines farther into the code.

Which ESP32 board are you compiling for?

Hi david_2018,
that's what bothers me and I can't get rid of it ! The code line of the serial error is somthing like 356 but my sketch has only some 130 lines of code. I looked with Ultrasearch in the files and find a "Serial0" only in a library file. I have no idea how this slips into the sketch code.

To answer your question: LILYGO T3 V1.6.1 LoRa Board with display.

Thanks for your help !

Peter

P.S. I have no ocurrence of "Serial0" in my code.

I was referring to the lines in your code.
The error text shows the following:

  140 | Serial.println("Going to sleep now");

but that is on line 177 in the LoRaSender01.ino file.

There are several errors in the code, but if it doesn't match what you are actually using there is little use in pointing them out.

I didn't realize that as I was wondering about the "Serial0" error in the 3rd line.
What do you think could help ? Delete the file and start a new sketch with the same text typed anew ?
I have not the slightest idea what could cause this mixup of files.
I had however problems before that - when trying to compile - the compiler suddenly grumbled about the "Serial"code word (not declared). This disappeared when I restarted the laptop.

Can you post the actual code that you are compiling?

Please post code and errors in a post using code tags, not as an attachment.


Note that the ini file that you attached is called LoraSender1.ino, the error however seems to point at ESP32_LoRa_Sender_10102024.ino.ino

I suspect a caching problem. Please delete all subdirectories in

  1. C:\Users\Papa\AppData\Local\Temp\arduino\sketches\
  2. C:\Users\Papa\AppData\Local\Temp\arduino\cores\ (maybe not needed).

In case of further problems, please let us know where we can find the Battery library.

Here is the code:

/*********
  Rui Santos
  Complete project details at https://RandomNerdTutorials.com/ttgo-lora32-sx1276-arduino-ide/
*********/



//Libraries for LoRa
#include <SPI.h>
#include <LoRa.h>
#include <Battery.h>

//Libraries for OLED Display
#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>

//define the pins used by the LoRa transceiver module
#define SCK 5
#define MISO 19
#define MOSI 27
#define SS 18
#define RST 14
#define DIO0 26

RTC_DATA_ATTR int bootCount = 0;

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

//OLED pins
#define OLED_SDA 21
#define OLED_SCL 22
#define OLED_RST -1
#define SCREEN_WIDTH 128  // OLED display width, in pixels
#define SCREEN_HEIGHT 64  // OLED display height, in pixels

#define BUTTON_PIN_BITMASK 0x200000000

// battery voltage from ESP32 ADC read
#define vbatPin 35
#define String(VBattery)   
)


//packet counter
int counter = 0;

Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, OLED_RST);

void setup() {
  //initialize Serial Monitor
  Serial.begin(115200);
  while (!Serial);

  // Battery read
    pinMode(vbatPin, INPUT);

  //reset OLED display via software
  pinMode(OLED_RST, OUTPUT);
  digitalWrite(OLED_RST, LOW);
  delay(20);
  digitalWrite(OLED_RST, HIGH);

  //initialize OLED
  Wire.begin(OLED_SDA, OLED_SCL);
  if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3c, false, false)) {  // Address 0x3C for 128x32
    Serial.println(F("SSD1306 allocation failed"));
    for (;;)
      ;  // Don't proceed, loop forever
  }
  String (LoRaSend) = analogRead(35);
  display.ssd1306_command(SSD1306_DISPLAYON);
  display.clearDisplay();
  display.setTextColor(WHITE);
  display.setTextSize(1);
  display.setCursor(0, 0);
  display.print("LORA SENDER ");
  display.setCursor(0, 30);
  display.println("Analog Value= ");
  display.println(LoRaSend);

  display.display();

  Serial.println("LoRa Sender Test");

  //SPI LoRa pins
  SPI.begin(SCK, MISO, MOSI, SS);
  //setup LoRa transceiver module
  LoRa.setPins(SS, RST, DIO0);

  if (!LoRa.begin(BAND)) {
    Serial.println("Starting LoRa failed!");
    while (1)
      ;
  }
  Serial.println("LoRa Initializing OK!");
  // display.setCursor(0, 10);
  // display.print("LoRa Initializing OK!");
  // display.display();
  // delay(1000);

  LoRa.setSyncWord(0xA5);
  VBattery = analogRead(35);


}

void loop() {

  SendString = VBattery;
  LoRa.setTxPower(22);
  String (SendData) =   // Battery Voltage
float VBAT = int(analogRead(35)) / 4095 * 2 * 3.3 * 1.1;

  /* The ADC value is a 12-bit number, so the maximum value is 4095 (counting from 0).
  To convert the ADC integer value to a real voltage you’ll need to divide it by the maximum value of 4095,
  then double it (note above that Adafruit halves the voltage), then multiply that by the reference voltage of the ESP32 which 
  is 3.3V and then finally, multiply that again by the ADC Reference Voltage of 1100mV.
  */
  Serial.print("AnalogRead = ");
  Serial.println(analogRead(35));


  Serial.print("Vbat = ");
  Serial.print(VBAT);
  Serial.println(" Volts");
  Serial.print(SendString);
  
  delay(5000);


  while (counter < 4) {

    Serial.print("Sending packet: ");
    Serial.println(counter);

    // LORA send Data
    LoRa.beginPacket();
    LoRa.print(SendString);
    delay(1000);
    // LoRa.print("               ");
    LoRa.endPacket();

    display.clearDisplay();
    display.setCursor(0, 0);
    display.println("LORA SENDER");
    display.setCursor(0, 20);
    display.setTextSize(1);
    display.print("LoRa packet sent.");
    display.setCursor(0, 30);
    display.print("Counter:");
    display.setCursor(50, 30);
    display.println(counter);
    display.print("VBat = ");
    display.println(VBAT);
      display.println(" V");
      display.print(SendData);
    display.display();
 

    counter++;

    delay(10000);
     }


    esp_sleep_enable_ext0_wakeup(GPIO_NUM_4, 1);

    LoRa.sleep();

    display.ssd1306_command(SSD1306_DISPLAYOFF);

    //Go to sleep now
    Serial.println("Going to sleep now");
    delay(500);
    esp_deep_sleep_start();

    Serial.println("This will never be printed");
  
}


// }

tippe oder füge den Code hier ein

Here are the errors:

In file included from C:\Users\Papa\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.0.5\cores\esp32/Arduino.h:200,
                 from C:\Users\Papa\AppData\Local\Temp\arduino\sketches\34FC23C5058564B6647C96341D540EAE\sketch\ESP32_LoRa_Sender_10102024.ino.ino.cpp:1:
C:\Users\Papa\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.0.5\cores\esp32/HardwareSerial.h:356:16: error: 'Serial' does not name a type
  356 | #define Serial Serial
      |                ^~~~~~
C:\Users\Papa\Documents\Arduino\ESP32_LoRa_Sender_10102024.ino\ESP32_LoRa_Sender_10102024.ino.ino:140:1: note: in expansion of macro 'Serial'
  140 | Serial.println("Going to sleep now");
      | ^~~~~~
C:\Users\Papa\Documents\Arduino\ESP32_LoRa_Sender_10102024.ino\ESP32_LoRa_Sender_10102024.ino.ino:141:6: error: expected constructor, destructor, or type conversion before '(' token
  141 | delay(500);
      |      ^
C:\Users\Papa\Documents\Arduino\ESP32_LoRa_Sender_10102024.ino\ESP32_LoRa_Sender_10102024.ino.ino:142:23: error: expected constructor, destructor, or type conversion before ';' token
  142 | esp_deep_sleep_start();
      |                       ^
C:\Users\Papa\AppData\Local\Arduino15\packages\esp32\hardware\esp32\3.0.5\cores\esp32/HardwareSerial.h:356:16: error: 'Serial' does not name a type
  356 | #define Serial Serial
      |                ^~~~~~
C:\Users\Papa\Documents\Arduino\ESP32_LoRa_Sender_10102024.ino\ESP32_LoRa_Sender_10102024.ino.ino:144:1: note: in expansion of macro 'Serial'
  144 | Serial.println("This will never be printed");
      | ^~~~~~

exit status 1

Compilation error: expected constructor, destructor, or type conversion before '(' token

Hi sterretje,

that was my guess also, that somewhere information is cached and I can't get rid of it, but I couldn't find any info where the cache files are.
I will do as you proposed and report.
Thanks !

BTW: is there any settings possibility to empty the cache every time before compiling a sketch ?

Unfortunately not; it was suggested long ago but I could not find and issue report back on github where it would be official.

Post a link to the original sketch on the randomnerds

I copied the code from the NERDS website and it compiles fine. All your deleting, uninstallig and installing only confuses the issue. Uness their is CONCRETE evidence of a failed installation, none of those steps is needed. I wil now try with your copy of the code. From what you siad it sounds like you may have hand transcribed it rther than copy all and paste. Will update.

I used the original code from your link and it compiles fine. Why did you add Battery.h?

You mean, it confuses you.

I get different errors and warnings:

extraneous closing parenthesis on line 45:

)

Wrong syntax on line 74, no need for the parrenthesis around LoRaSend, and a String cannot be initialized to a numeric value.

  String (LoRaSend) = analogRead(35);

The variable VBattery is not declared.

Line 115 has an error, missing initializer, or if you intended the next line to be the initializer it should not be declaring a float.

    String (SendData) =   // Battery Voltage
    float VBAT = int(analogRead(35)) / 4095 * 2 * 3.3 * 1.1;

It is irrelevant, I am not debugging his pile of random LOC.

We were not asked to debug. That's probably the next step but that's another story.

That's a leftover from a perevious try. Not used any more. I was going to clean up the code when it properly compiles.

I have to clear one thing:
I'm a noob with c++, makes me enough headache ! :grimacing:
Just to build a small project needs a lot of digging.
It's like learning a new language just to order a meal in a foreign restaurant. I'm almost 80 and not so firm any more with learning new things, so have mercy on me ... :innocent: