Arduino Mega 2560 'Serial2' was not declared in this scope

I'm confused...

I have a Nextion display connected to my genuine Arduino Mega. I also have a couple of one-wire temp sensors and one RTC clock. Temperatures and time are shown in the display etc. Nothing complicated, very basics. I got it working, display is connected to Mega serial 2, I send commands to the serial 2 port, all fine.

But, today my scetch just keeps giving error:

C:\Users\mikko\Documents\Arduino\Check-panel\Check-panel.ino: In function 'void setup()':
Check-panel:90:3: error: 'Serial2' was not declared in this scope
   Serial2.begin(115200);
   ^~~~~~~
C:\Users\mikko\Documents\Arduino\Check-panel\Check-panel.ino:90:3: note: suggested alternative: 'Serial'
   Serial2.begin(115200);
   ^~~~~~~
   Serial

The same code was working before just as it is. No changes made. What an earth happened? I upgraded to Win11 some time ago, can this be related to it? How to fix?

Once again, the same code was working earlier without any problems.

Relevant code here:

#include <arduino-timer.h>

#include <OneWire.h>
#include <DallasTemperature.h>
#include <RTClib.h>

#include <doxygen.h>
#include <NexButton.h>
#include <NexCheckbox.h>
#include <NexConfig.h>
#include <NexCrop.h>
#include <NexDualStateButton.h>
#include <NexGauge.h>
#include <NexGpio.h>
#include <NexHardware.h>
#include <NexHotspot.h>
#include <NexNumber.h>
#include <NexObject.h>
#include <NexPage.h>
#include <NexPicture.h>
#include <NexProgressBar.h>
#include <NexRadio.h>
#include <NexRtc.h>
#include <NexScrolltext.h>
#include <NexSlider.h>
#include <NexText.h>
#include <NexTimer.h>
#include <Nextion.h>
#include <NexTouch.h>
#include <NexUpload.h>
#include <NexVariable.h>
#include <NexWaveform.h>

#define ONE_WIRE_BUS 2

OneWire oneWire(ONE_WIRE_BUS); 
DallasTemperature sensors(&oneWire);

  bool showOut = true;
  auto timer = timer_create_default();
  auto clockTimer = timer_create_default();

void setup() {

  Serial.begin(9600);
  Serial2.begin(115200);

...

  }

My first guess is your board isn’t set as MEGA2560 in the Tools men.

1 Like

Of course...
How stupid one can be :crazy_face:

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