Synchronization of serial and system generated messages

I have a small project which I am making on mega2560. I am using GPS and echosounder and getting their messages on serial1 and serial2. Also, one message is generated internally and displayed. But the problem is I cannot synchronize them.

Could You use millis, or micros, and note the time for either the start or the end each serial channel message?

Sir, I will explain to you my problem. I am controlling 2 motors and getting the speed and direction of motors which is processed by the program itself not receiving through the serial port.
But GPS and echosounder messages are received through the serial port and shown at the serial monitor.

and I cannot use delays as it will delay my program.

Take a look at my tutorial on Arduino Serial I/O for the Real World which deals with non-blocking Serial read/write.
In your case you can add a large output buffer to write the data to as it is received (i.e. synchronized) without blocking when the Serial Tx buffer fills up.

I have a question, My Arduino mega was working fine. But now my rx0 and tx0 pins are not working. Is it a board problem?

rx0/tx0 are connected to the USB (Serial), so just try any code sample the tries to print/read from Serial and make sure that works (without the other code)

I checked and the result is this the rx0 and tx0 pins on my mega 2560 are damaged. I think it was because of my stupidity because I think I put wrong connections with max232.

This topic was automatically closed 120 days after the last reply. New replies are no longer allowed.