Eclipse IDE - Mega 2560 - Symbol 'Serial1' could not be resolved

I have a working Eclipse project that's using softwareserial to talk to a wifi chip. To conserve memory I want to get rid of the softwareserial library and use Serial1 as a hardware serial port (TX1 in my 2560 board).

I added #include "HardwareSerial.h" and try to use Serial1 directly in the code, but the compiler is throwing this error:

Symbol 'Serial1' could not be resolved

I understand that HardwareSerial.h declares Serial1 only if UBRR1H is defined.

#if defined(UBRR1H)
extern HardwareSerial Serial1;
#define HAVE_HWSERIAL1
#endif

I created a launch target on Eclipse as follows:

Target Name: Arduino 2560
Serial Port: /dev/ttyACM0
Board Type: Arduino/Genuino Mega or Mega 2560
Processor: ATmega2560 (Mega 2560)
Programmer: AVR ISP

I assumed that creating this launch target would somehow define UBRR1H but that doesn't seem to be the case.
Is there anything else I'm missing?

Is anybody using Eclipse IDE with hardware port 1 or up successfully, if so, please share the right configuration steps.

Thanks in advance.

In the Arduino IDE all you need is
Serial1.begin(speed);
in setup(), just like having Serial.begin(speed);

Does eclipse do that as well?

include Arduino.h

Thanks for the quick replies. Just to make it clearer, this piece of code works in the Arduino IDE:

#include <Arduino.h>
#include "HardwareSerial.h" //this line seems redundant

void setup() {
	Serial.begin(115200);
	Serial1.begin(115200);
}

void loop() {

}

But if I build the same piece of code in Eclipse, Serial1 is not recognized:

Method 'begin' could not be resolved
Symbol 'Serial1' could not be resolved

However, this code works just fine, using the software serial library:

#include <Arduino.h>
#include <SoftwareSerial.h>

void setup() {
	SoftwareSerial Serial1(6, 7); // RX, TX
	Serial.begin(115200);
	Serial1.begin(115200);
}

void loop() {

}

Any clues?

Thanks.

does it compile for Mega variant? because standard variant (for 328p) doesn't have Serial1

Juraj:
does it compile for Mega variant? because standard variant (for 328p) doesn't have Serial1

It's compiling for the Mega variant. These are the parameters for the Eclipse Arduino target:

Target Name: Arduino 2560
Serial Port: /dev/ttyACM0
Board Type: Arduino/Genuino Mega or Mega 2560
Processor: ATmega2560 (Mega 2560)
Programmer: AVR ISP

One would think Eclipse would set the appropriate #define statements when setting up a target with multiple hardware serial ports but only a single Serial is defined.

Finally, I found a solution! I thought I'd post it here in case somebody else runs into the same problem.

The answer came from this link: Hardware serial port as "Serial" · Issue #10 · Sloeber/arduino-eclipse-plugin · GitHub it's for the Sloeber plugin but applies to the CDT. The issue seems to be with the compiler indexes not being properly built. Here:

preferences->C/C++->indexer->index unused headers.
preferences->C/C++->indexer->index source and header files opened in the editor.
preferences->C/C++->indexer->Index all variants of specific headers. Add arduino.h and WProgram.h separated by commas.
Do next four in this sequence
Right click the project->index->Search for unresolved includes.
Right click the project->index->Freshen all Files.
Right click the project->index->Update with modified files.
Right click the project->index->Rebuild.

1 Like

I thought you have a compiler error, not a red underline