Arduino IDE 2.2.0 can't find Serial2

My sketch worked perfectly under 2.1.1 with an ESP32 using core version 2.0.11. After updating the IDE to 2.2.0 it can't use Serial2:
....\Arduino\XXX_prototype_QR\XXX_prototype_QR.ino:257:3: error: 'Serial2' was not declared in this scope
Serial2.begin(GPS_BAUD, SERIAL_8N1); // GPS serial
^~~~~~~
.
.
.
Compilation error: 'Serial2' was not declared in this scope

What to do?

Start by posting a complete sketch that illustrates the problem but preferably not your 257 line (or more) monster

1 Like

Thanks for your quick response.

I will try to extract the serial code and post it here. Meanwhile, I reinstalled 1.8.19. All works perfectly as it did under 2.1.1. I would have gone back to 2.1.1 but it is no longer on the website.

It should be easy to demonstrate the problem with a small sketch

void setup()
{
  Serial2.begin(9600, SERIAL_8N1);
}

void loop()
{}

If that compiles then suspect your main sketch is doing something different

You can always download all the releases from GitHub. 2.1.1 is here for the time being. You might need to click on the Assets section to expand to see all the artifacts.

I copied and pasted your code. No joy.

C:\Users\KarlB\AppData\Local\Temp.arduinoIDE-unsaved2023729-20616-1nd8n2n.qimem\sketch_aug29a\sketch_aug29a.ino: In function 'void setup()':
C:\Users\KarlB\AppData\Local\Temp.arduinoIDE-unsaved2023729-20616-1nd8n2n.qimem\sketch_aug29a\sketch_aug29a.ino:3:3: error: 'Serial2' was not declared in this scope
Serial2.begin(9600, SERIAL_8N1);
^~~~~~~
C:\Users\KarlB\AppData\Local\Temp.arduinoIDE-unsaved2023729-20616-1nd8n2n.qimem\sketch_aug29a\sketch_aug29a.ino:3:3: note: suggested alternative: 'Serial'
Serial2.begin(9600, SERIAL_8N1);
^~~~~~~
Serial

exit status 1

Compilation error: 'Serial2' was not declared in this scope

Which board have you got selected in the IDE when compiling that sketch ?

DOIT ESP32 DEVKIT V1

Your code runs without complaint in 1.8.19. Same board.

Here are the two IDEs side by side.

I have just installed 2.2.0, set the target to DOIT ESP32 DEVKIT V1 and the sketch compiles OK for me. I am using the ESP32 boards files version 2.0.11 which is the same as you

Try uninstalling the board files and installing them again

I went back to 2.1.1 by installing it overtop 2.2. All works as before.

I've lost the morning fighting with 2.2.0. I will stick with 2.1.1 for the time being.

Thanks for your help.

That sounds like a sensible decision, but it makes me wonder what is wrong

My brain took a reset during a happy vacation and I unwisely updated to IDE 2.2.1, forgetting the grief caused by 2.2.0. As before, it sees Serial2 as undefined.

Where are the board files located and what should be deleted?

Hi @W4KRL. I'm going to ask you to post the full verbose output from a compilation.


:exclamation: This procedure is not intended to solve the problem. The purpose is to gather more information.


Please do this:

  1. Select File > Preferences... from the Arduino IDE menus.
    The "Preferences" dialog will open.
  2. Check the box next to "Show verbose output during: ☐ compilation" in the "Preferences" dialog.
  3. Click the OK button.
  4. Select Sketch > Verify/Compile from the Arduino IDE menus.
  5. Wait for the compilation to fail.
  6. You will see a "Compilation error: ..." notification at the bottom right corner of the Arduino IDE window. Click the COPY ERROR MESSAGES button on that notification.
  7. Open a forum reply here by clicking the Reply button.
  8. Click the <CODE/> icon on the post composer toolbar.
    This will add the forum's code block markup (```) to your reply to make sure the error messages are correctly formatted.
    Code tags icon on toolbar
  9. Press Ctrl+V.
    This will paste the compilation output into the code block.
  10. Move the cursor outside of the code tags before you add any additional text to your reply.
  11. Click the Reply button to post the output.

In case the output is longer than the forum software will allow to be added to a post, you can instead save it to a .txt file and then attach that file to a reply here:

  1. Open any text editor program.
  2. Paste the copied output into the text editor.
  3. Save the file in .txt format.
  4. Open a forum reply here by clicking the Reply button.
  5. Click the "Upload" icon (Upload icon) on the post composer toolbar:
    Upload icon on toolbar
    A dialog will open.
  6. In the dialog, select the .txt file you saved.
  7. Click the Open button.
  8. Click the Reply button to publish the post.

Alternatively, instead of using the "Upload" icon on the post composer toolbar as described in steps (5) - (7) above, you can simply drag and drop the .txt file onto the post composer field to attach it.

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