0

I am using Arduino and NetBeans in my project. My final work is to switch from Arduino program to Java. I managed to install an Arduino-NetBeans plugin as described in Arduino - NetBeans Plugin detail

My Arduino program includes

Serial.begin(9600); /////// Serial.print();

I get an error saying that "Unable to resolve identifier Serial". How can I solve this?

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131
user2236974
  • 89
  • 1
  • 2
  • 6

3 Answers3

2

this is what you have to add to your source file:

#include <Arduino.h>
// imports the Serial class to allow log output
extern HardwareSerial Serial;

then it will work.

cgo
  • 21
  • 2
2

As answered by cgo you can add extern HardwareSerial Serial;

netbeans arduino serial

Or into your Project Settings, go to BUILD > C++ COMPILER > PREPROCESSOR DEFINITIONS and add: __AVR_ATmega328P__ (if you are working with Arduino UNO)

netbeans arduino preprocessor

dsicari
  • 590
  • 6
  • 13
0

The message "unable to resolve identifier Serial" means that the compiler is searching for the variable Serial, but cannot find its declaration. You should check if you include all header files properly. I don't know the NetBeans plugin, but I guess the Serial-structure/class is initialised there.

If that is not helping, you should check the compiler otions and set them to default, as described on the project-site.

Peter Mortensen
  • 30,738
  • 21
  • 105
  • 131