Thank you very much for your reply and modifying the code. However, after some research, I still can't figure how the modified code produce result as follow. (random negative sign and two sets or three sets of data at once from one serial port)
Also, I've been trying to format the output such that the data from the second serial port follows the first serial port such as
I tried Serial.print but all the decimal places are omitted, could you please give me some hint on how to resolve this problem please?
Since the Serial buffers are 64 bytes, and you are receiving 2(Serial1,Serial2) stream at 56k and only sending 1(Serial) stream at 56k you can,will overflow (Serial) if the data stream from (Serial1+Serial2) is greater than 56k.
From how i understand it, you mean Serial communication is very slow for the MEGA, and since the BAUD rate is set to be 56400, the buffer will be overflowed with data coming from the sensor? Could you tell me what you mean by "only sending 1(Serial) stream at 56k you can"? are you saying the MEGA communicate with the computer via the TX0 and RX0 ?
static uint8_t lastSerial=0; // source of last character send out Serial
I am thinking the static variable lastSerial is local correct? meaning after each loop, lastSerial changes to 1 or 2 according to which serial port acts last? Also, I will probably not be able to think of your way to go around my problem due to my lack of knowledge in C++. Could you recommend me a good way to learn how to code in Arduino more efficiently?
Thank you Chuck once again for your help and time, I really appreciate it!