serial.available OK with IDE and KO with C language

This is an exmple of a code writen with the IDE and tested with the termnal include into IDE. Every thinks are OK, the Serial.available() works fine.

{ Serial.begin(57600) ;
Serial.println("Hello, world!") ;
{... i = Serial.available() ; sprintf(errmsg," AVAIL %d",i); Serial.println(errmsg) ; ...

Every thinks are OK.

Now, I write the same code in C language with the plugin eclipse (Arduino Eclipse IDE named Sloeber - Welcome!), with the same hardware, on the same computer, the same USB port, .... of course I can load the code on the target. The println command works fine, but the available() commande always return 0. I use the IDE terminal as terminal like in the first example.

Have you some ideas ? Do I use the right RX port ? A configuration ? Does the IDE libraries are the same as the C libraries ?

SoftwareSerial mySerial(0,1) ; // RX, TX == 1

void setup()
mySerial.begin(57600) ;
mySerial.println("Hello, world!") ;

void loop()
{ ...
j = mySerial.available() ; sprintf(errmsg," AVAIL %d",j); mySerial.println(errmsg) ;

I think you can’t use the pin 0,1 with software serial (besides there is no point of doing that)

You have right.

What I need is the Serial object in Cpp, like in the IDE. I don’t understand how to have Serial in C :

  • Serial is not found by the link editor
  • Serial seems to be a C know symbol
  • Serial.begin is defined

I imagined that SerialSoftware was a solution, but it is not.

Do you know how to use Serial in C ?

I always use the IDE, but just compile once verbose and you will see what includes to do it yourself without the IDE.

Do you know how to use Serial in C ?

The Arduino IDE is C. What you don't see is that the IDE adds the appropriate headers to the code before passing it off to the compiler. Eclipse doesn't know to do that. So you need to include "HardwareSerial.h" yourself.