Despite several different approaches, I'm getting unpredictable results with intermittent freezes, board resets, and mangling of the text returned to the Serial Monitor; occurring apparently at random.
Here's a clue:
Serial.begin(9600,SERIAL_8N1); //
Serial1.begin(19200,SERIAL_8E1);
Sending data out slower than you read it in isn't a good idea.
{Serial.println("Starting main loop");
Not a single recognized coding style accepts ANYTHING on the line after the {. I'm not impressed with your attempt to invent a new one.
Using do/while in place of a normal while loop is rarely a good idea. In a do/while loop, the body is executed and then the condition is checked. In a while loop, the condition is checked first, then, if appropriate, the body is executed.
The
(almost)
complete
lack
of
indenting
makes
your
code
too
hard
to
read.