I already read (and used) the PC-Arduino comms using Python. It works
I already implemented a small C++ program/Arduino Sketch that works, but... needs the Arduino IDE serial comm to start.
You don't need to specifically #include anything to support serial comms in the Arduino IDE
As @srnet said, it is built into the Arduino environment provided by the IDE. The IDE Serial Monitor provides a basic serial terminal, but if you want to use screen controls such as cursor positioning, then you can use an alternative terminal program on the PC
I start the C++ program
=> Nope ! the C++ program can not open the communication channel
1') I load the sketch into the Arduino, using the IDE and then I open the serial console (of the IDE)
2') I start the C++ program
=> Yes !!! it works as it should be and I can now close the Arduino IDE (serial console and the IDE itself).
I already read about this, it seems that I need to wait for the Arduino to reset... I was trying to adapt the code from "PC-Arduino comms using Python"... but I guess that instead of the "include Serial" (on the Python code) I need the "termios.h".
I didn't try that yet, a kind of merging of two contributions I read in the forum.
Using AVR based Arduino boards, when the Arduino Serial port is opened, either by opening the Serial monitor or by an external connection, then the board is reset
This can be prevented by making a hardware modification to the board and there are also Arduino and other boards that do not reset the board because the serial connection is handled by another chip on the board and not the main processor
... and that's my problem. From what I read I need to wait for the Arduino to reset and then I can begin the communication.
My questions are:
"when the Arduino Serial port is opened"
I imagine that the "openning" happens when I write in the C++ code something like " fd_ard = open("/dev/ttyUSB0", O_RDWR | O_NOCTTY | O_NDELAY);", the O_RDWR is (!?) read+write
How can I wait for the Arduino to reset?
I imagine (I didn't test it yet) that I can open it RDWR, then (as suggested in the Python code) wait for a response of the Arduino (that will be in the sketch), and then pursue with the communication (without closing the connection).
The "is there anybody there ?" technique is probably the most certain way of ensuring that the connection is available and could be extended to have the Arduino send back the CRC of the received message to be checked at the PC side to ensure that the message was received correctly
Once open, do you actually need to close the serial connection ?
No I don't... I will open it and then when the program ends ... the connection is closed.
The simplest possible
The goal is to have a simple program then receive commands and pass them to the Arduino ... this Arduino is in term the master of a network of Arduinos receiving commands and making actions... everything is working (almost) the PC/C++ program is the last part, for the prototype, version 0.
Later today I will try this and I will report to you. Thank you for all your help.
The simplest way is to open the serial connection, wait a while then send blindly with no way of knowing that the data arrived
At the very least you would be wise to top and tail your messages with begin and end markers to ensure that the Arduino keeps in step with the data being sent