OK. Thanks Power_Broker.
Your info was very helpful. I could establish a connection between my Nano and my Mega using following sketches.
Nano
#include "SerialTransfer.h"
SerialTransfer myTransfer;
void setup()
{
Serial.begin(1200);
// Serial1.begin(115200);
myTransfer.begin(Serial);
}
void loop()
{
myTransfer.txBuff[0] = 'h';
myTransfer.txBuff[1] = 'i';
myTransfer.txBuff[2] = '\n';
myTransfer.sendData(3);
delay(100);
}
As you see I didn't use serial1 because the Nano only has 1 Serial port (0). It implies that I have to disconnect the serial wires while uploading a sketch. Maybe later I'll try to use SoftwareSerial to avoid this.
I lowered the bitrate to 1200 because (for test purposes), I used just simple (unscreened) wires for Rx, Tx and GND and also because speed is not important for me now.
Mega :
#include "SerialTransfer.h"
SerialTransfer myTransfer;
void setup()
{
Serial.begin(1200);
Serial3.begin(1200);
myTransfer.begin(Serial3);
}
void loop()
{
if(myTransfer.available())
{
Serial.println("New Data");
for(byte i = 0; i < myTransfer.bytesRead; i++)
Serial.write(myTransfer.rxBuff[i]);
// Serial.println();
}
else
{
Serial.print("ERROR: ");
Serial.println(myTransfer.status);
}
delay(500);
}
The final delay(500) is used to mimic the time that the complete program will need before it gets back to collecting serial data. I used a bitrate of 1200 to print to the Serial Monitor because I've read that using different baud rates on different serials can cause problems.
The result that I see on the Serial monitor (connected to the Mega) is rather weird. It works, but now and then I get error messages... (Same errors when using different baud rates)
Here's what I see on the Serial Monitor of the Mega :
...
New Data
hi
New Data
hi
New Data
hi
New Data
hi
New Data
hi
New Data
hi
ERROR: -1
New Data
hi
ERROR: -1
New Data
hi
New Data
hi
New Data
hi
New Data
hi
New Data
hi
ERROR: 2
ERROR: 2
ERROR: -1
New Data
hi
New Data
hi
New Data
hi
etc ...
Here and there also an ERROR -3 appears ... Maybe the errors appear because the nano is trying to send while the Mega is still reading ? But then why is it always a different error code ?
Anyhow... I think that (thanks to your info) I am on a good road, but there's still a few "pot holes" ...
So... things BEGIN to work... !!YES!!
Do you have any ideas to smooth out those "pot holes" so that I can go on (and maybe have to ask more questions )
Again, in advance : I thank you for your "cooperation"
PS. Nano and Mega are connected to the same PC, but each on their own arduino.exe