Receiving strings from Serial not coming synchonously

The SD card logs a CSV format. In the end of post #13 I gave some sample output from that logging. The 6th row logged had the weird data in it. I'll do some more hunting but at least it's working.

protomor:
The 6th row logged had the weird data in it.

You need to determine when that happens in relation to when the receiving Arduino starts receiving and when the sending Arduino starts sending. I wonder if all the values before that faulty line are a hangover from a previous start?

Maybe when the receiving Arduino starts it should empty the Serial Input buffer as a first step?

...R

Maybe when the receiving Arduino starts it should empty the Serial Input buffer as a first step?

That's what I was hinting at. I suspect that the sender starts sending data before the receiver is ready, and that the incoming buffer overflows before OP is ready to start reading. Hence the corrupt packet. Once that is cleared out (by OP assuming that all the data is valid), the rest of the data is sent without causing an overflow of the receiver's buffer.

	Serial.begin(9600);

	// I guess keep waiting till we get a response. 
	while (!Serial) {
		; // wait for serial port to connect. Needed for Leonardo only
	}

	Serial.println("card initialized");

	delay(1000);

That delay() there is not helping. The sender can send a bunch of data in that time.

That's followed by a while loop that takes who knows how long to complete.

That's followed by a loop to find a file to write to.

That's followed by a while loop that waits until the GPS is sending good data, or two seconds, whichever happens first.

That's followed by another while loop that waits for the Uno to send some data, or two seconds, whichever is less.

But, by that time, the Uno has send 14 novels, most of which got dumped in the bit bucket.

So, a few complete packets, a partial packet were sent, filling the incoming buffer, before the Arduino started reading data. When that happens, the partial packet gets followed by a complete packet, which is exactly what the output showed.

So, yeah, once this Arduino detects that the other one is sending data, this one needs to dump all the data in the buffer.

It's funny that I find posts from you guys - Serial.flush() does not work? - Programming Questions - Arduino Forum

Adding in a buffer clear definitely fixed things. I'm getting no more junk in my logs or on scree. I think that fixes things. Thank you for being so patient with me!