Suddenly my program ('Serial2' was not declared in this scope)

my brain was confuse...i was tired a few minute ago...because all day i always try and make program.but I'm more excited to work again now. when i try my code it work fine.and this problem sudenly happen:

C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\arduino-builder -dump-prefs -logger=machine -hardware C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware -hardware C:\Users\ridho\Documents\ArduinoData\packages -tools C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\tools-builder -tools C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware\tools\avr -tools C:\Users\ridho\Documents\ArduinoData\packages -built-in-libraries C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\libraries -libraries C:\Users\ridho\Documents\Arduino\libraries -fqbn=arduino:avr:uno -vid-pid=2341_0043 -ide-version=10815 -build-path C:\Users\ridho\AppData\Local\Temp\arduino_build_179880 -warnings=none -build-cache C:\Users\ridho\AppData\Local\Temp\arduino_cache_67274 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avr-gcc.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware\tools\avr -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware\tools\avr -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware\tools\avr -prefs=runtime.tools.arduinoOTA.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware\tools\avr -prefs=runtime.tools.arduinoOTA-1.3.0.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware\tools\avr -verbose C:\Users\ridho\Documents\Arduino\parsingdata\parsingdata.ino

C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\arduino-builder -compile -logger=machine -hardware C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware -hardware C:\Users\ridho\Documents\ArduinoData\packages -tools C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\tools-builder -tools C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware\tools\avr -tools C:\Users\ridho\Documents\ArduinoData\packages -built-in-libraries C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\libraries -libraries C:\Users\ridho\Documents\Arduino\libraries -fqbn=arduino:avr:uno -vid-pid=2341_0043 -ide-version=10815 -build-path C:\Users\ridho\AppData\Local\Temp\arduino_build_179880 -warnings=none -build-cache C:\Users\ridho\AppData\Local\Temp\arduino_cache_67274 -prefs=build.warn_data_percentage=75 -prefs=runtime.tools.avr-gcc.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware\tools\avr -prefs=runtime.tools.avr-gcc-7.3.0-atmel3.6.1-arduino7.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware\tools\avr -prefs=runtime.tools.avrdude.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware\tools\avr -prefs=runtime.tools.avrdude-6.3.0-arduino17.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware\tools\avr -prefs=runtime.tools.arduinoOTA.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware\tools\avr -prefs=runtime.tools.arduinoOTA-1.3.0.path=C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware\tools\avr -verbose C:\Users\ridho\Documents\Arduino\parsingdata\parsingdata.ino

Using board 'uno' from platform in folder: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware\arduino\avr

Using core 'arduino' from platform in folder: C:\Program Files\WindowsApps\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\hardware\arduino\avr

Detecting libraries used...

"C:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10815 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\variants\\standard" "C:\\Users\\ridho\\AppData\\Local\\Temp\\arduino_build_179880\\sketch\\parsingdata.ino.cpp" -o nul

Generating function prototypes...

"C:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -flto -w -x c++ -E -CC -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10815 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\variants\\standard" "C:\\Users\\ridho\\AppData\\Local\\Temp\\arduino_build_179880\\sketch\\parsingdata.ino.cpp" -o "C:\\Users\\ridho\\AppData\\Local\\Temp\\arduino_build_179880\\preproc\\ctags_target_for_gcc_minus_e.cpp"

"C:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\\tools-builder\\ctags\\5.8-arduino11/ctags" -u --language-force=c++ -f - --c++-kinds=svpf --fields=KSTtzns --line-directives "C:\\Users\\ridho\\AppData\\Local\\Temp\\arduino_build_179880\\preproc\\ctags_target_for_gcc_minus_e.cpp"

Compiling sketch...

"C:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\\hardware\\tools\\avr/bin/avr-g++" -c -g -Os -w -std=gnu++11 -fpermissive -fno-exceptions -ffunction-sections -fdata-sections -fno-threadsafe-statics -Wno-error=narrowing -MMD -flto -mmcu=atmega328p -DF_CPU=16000000L -DARDUINO=10815 -DARDUINO_AVR_UNO -DARDUINO_ARCH_AVR "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\cores\\arduino" "-IC:\\Program Files\\WindowsApps\\ArduinoLLC.ArduinoIDE_1.8.49.0_x86__mdqgnx93n4wtt\\hardware\\arduino\\avr\\variants\\standard" "C:\\Users\\ridho\\AppData\\Local\\Temp\\arduino_build_179880\\sketch\\parsingdata.ino.cpp" -o "C:\\Users\\ridho\\AppData\\Local\\Temp\\arduino_build_179880\\sketch\\parsingdata.ino.cpp.o"

C:\Users\ridho\Documents\Arduino\parsingdata\parsingdata.ino: In function 'void setup()':

parsingdata:26:5: error: 'Serial2' was not declared in this scope

     Serial2.begin (9600, SERIAL_8N1, RXp2, TXp2);

     ^~~~~~~

C:\Users\ridho\Documents\Arduino\parsingdata\parsingdata.ino:26:5: note: suggested alternative: 'Serial'

     Serial2.begin (9600, SERIAL_8N1, RXp2, TXp2);

     ^~~~~~~

     Serial

C:\Users\ridho\Documents\Arduino\parsingdata\parsingdata.ino: In function 'void loop()':

parsingdata:32:9: error: 'Serial2' was not declared in this scope

      if(Serial2.available()>0)

         ^~~~~~~

C:\Users\ridho\Documents\Arduino\parsingdata\parsingdata.ino:32:9: note: suggested alternative: 'Serial'

      if(Serial2.available()>0)

         ^~~~~~~

         Serial

exit status 1

'Serial2' was not declared in this scope

this is my code:

#define RXp2 16
#define TXp2 17
String dataIn;
String dt[10];
int i;
bool parsing=false;
 ////////////////

//int rpm = 0;
//float cadence = 0;
//float Odo = 0;
//float Trip = 0;
//float Speed = 0;
//float torsi = 0;
//float batt = 0;
//float TripNow = 0;
//float OdoNow = 0.0;

//float keliling = 1.57;


 /////////////
void setup() 
{
    Serial.begin(115200);
    Serial2.begin (9600, SERIAL_8N1, RXp2, TXp2);
    dataIn="";
}
 
void loop() 
{
     if(Serial2.available()>0)
     {
           char inChar = (char)Serial2.read();
           dataIn += inChar;
           if (inChar == '\n') 
           {
            parsing = true;
            }
     }
     if(parsing)
     {
            parsingData();
//           voltbat();
//           cadance();
//           kecepatan();
           parsing=false;
           dataIn="";
     }
}
 
void parsingData()
{
      int j=0;
      //kirim data yang telah diterima sebelumnya
      Serial.print("data masuk : ");
      Serial.print(dataIn);
      Serial.print("\n");
      //inisialisasi variabel, (reset isi variabel)
      dt[j]="";
      //proses parsing data
      for(i=1;i<dataIn.length();i++)
      {
             //pengecekan tiap karakter dengan karakter (#) dan (,)
             if ((dataIn[i] == '#') || (dataIn[i] == ','))
             {
                   //increment variabel j, digunakan untuk merubah index array penampung
                   j++;
                  dt[j]=""; //inisialisasi variabel array dt[j]
             }
             else
             {
                  //proses tampung data saat pengecekan karakter selesai.
                  dt[j] = dt[j] + dataIn[i];
             }
      }
      //kirim data hasil parsing
      Serial.print("data 1 : ");
      Serial.print(dt[0].toInt());
      Serial.print("\n");
      Serial.print("data 2 : ");
      Serial.print(dt[1].toFloat());
      Serial.print("\n");
      Serial.print("data 3 : ");
      Serial.print(dt[2].toFloat());
      Serial.print("\n");
      Serial.print("data 4 : ");
      Serial.print(dt[3].toFloat());
      Serial.print("\n");
      Serial.print("data 5 : ");
      Serial.print(dt[4].toFloat());
      Serial.print("\n\n");
      Serial.print("data 6 : ");
      Serial.print(dt[5].toFloat());
      Serial.print("\n\n");
}

in this project i use ESP32 as receiver ADC data from UNO with serial comunication. and it works fine. and then this problem happen. how to solve this?

The uno only has one hardware serial port.

in case you need more information, you are compiling for the UNO

➜ Serial1 or Serial2 etc do not exist on this board. There is only one hardware Serial port and it's called Serial.

if you need more UART ports, get an Arduino MEGA or use a Software Serial emulation