I2C and serial input to serial output

Hello guys,
I need some help with the following problem:

Arduino MEGA
UBLOX NEO 6 GPS connected to RX1/TX1. The GPS is sending NMEA data with 9600 baud.
9250 9DOF IMU connected to I2C Pin 20,21 of the MEGA.

When only reading GPS data from the serial input and outputting to USB (serial monitor in Arduino IDE or terminal program on RASPI), everything is fine.

The IMU is supposed to also send NMEA sentences. To generate this code, I'm using the library from Richards-tech (https://github.com/richards-tech/RTIMULib-Arduino).
Just running the different sketches works fine, NMEA sentences are written to USB.

Now my problem: When trying to combine the two streams, the output is garbled (random CR/LF inserted) an the MEGA hangs after a couple of seconds. The complete code is attached. If lines 204 thru 208 are uncommented, the problem occurs.

Any thoughts?

P.S.: The target of the whole story is to send different input streams (NMEA navigation information and readings from analog sensors to a RASPI for further processing and display.

MPU9250_NMEA.ino (7.42 KB)

Have a look at the examples in Serial Input Basics - the 2nd one is probably most relevant to your project.

Rather than your simple code for receiving data from Serial1, you need to receive a complete message before sending any of it. That way you can keep the messages from the different sources separate.

...R

Thanks for the hint - problem solved.