Serial communication and Arduino program in C When I flash this simple code (using Arduino-Makefile):

#include &lt;avr/io.h&gt;
#include &lt;util/delay.h&gt;
#include &lt;Arduino.h&gt;

void init_io(void) {

    // open serial port
    Serial.begin(9600);
    while (!Serial);
    Serial.println("Comm-link online");

}//END: init_io

int main(void) {

    init_io();

    while (1) {

        // send data only when you receive data:
        if (Serial.available() &gt; 0) {

            // read the incoming byte:
            int incomingByte = Serial.read();

            // say what you got:
            Serial.print("I received: ");
            Serial.println(incomingByte, DEC);

        } else {

            //  Serial.println("No serial ");

        }

    }//END: loop

    return 0;
}//END: main


I only see first two chars printed in the serial output:


  ~$> Co


The input also does not work as intended - tested on two independent microcontrolers, Mega and Uno. I'm not sure what's the cause of this behaviour. Here's the Makefile:

BOARD_TAG    = uno # megaADK uno
MONITOR_PORT  = /dev/ttyACM0
ARDUINO_LIBS = 

include $(ARDMK_DIR)/Arduino.mk


It's definitely not a hardware problem, I've used serial i/o before in other projects.
When using the Arduino core library, you normally do not write a
main() function. Instead, you write setup() and loop() and rely on
libcore's provided main() for calling them.

If you nevertheless want to provide your own main(), then you should
call init(); (with no arguments) before you try to use the library.
Adding this single call makes your program work on my Uno.

However, since it does not seem to be officially documented, this trick
may not be safe against upgrades in the core library. Writing setup()
and loop() should be more future-proof.