I have a simple setup with an Uno connected to two temperature probes via two AD8495 boards. The arduino code just polls the analog pins, averages 500 readings over 15 seconds, then outputs the calculated temperatures, differential temperature, voltages, and sample size to the serial monitor in JSON formatting. For the MOST part this works fine, but fairly often I get some lines where it stops halfway through a line and starts another or drops the first parts of one line.
Recently my serial monitor ends up looking something like this, with most lines showing up correctly, but several losing data.
{"rTemp":"63.1","sTemp":"64.2","dTemp":"1.1","rVolt":"1.326","sVolt":"1.330","rSamp":"500","sSamp":"500"}
{"rTemp":"63.1","sTemp":"64.2","dTemp":"1.1","rVolt":"1.326","sVolt":"1.330","rSamp":"500","sSamp":"500"}
{"rTemp":"63.1","sTemp":"64.2","dTemp":"1.1","rVolt":"1{"rTemp":"63.1","sTemp":"64.2","dTemp":"1.1","rVolt":"1.326","sVolt":"1.330","rSamp":"500","sSamp":"500"}
{"rTemp":"63.1","sTemp":"64.2","dTemp":"1.1","rVolt":"1.326","sVolt":"1.330","rSamp":"500","sSamp":"500"}
{"rTemp":"63.1","sTemp":"64.2","dTemp":"1.1","rVolt":"1.326","sVolt":"1.330","rSamp":"500","sSamp":"500"}
":"63.7","sTemp":"63.7","dTemp":"0.0","rVolt":"1.328","sVolt":"1.328","rSamp":"500","sSamp":"500"}
{"rTemp":"63.1","sTemp":"64.2","dTemp":"1.1","rVolt":"1.326","sVolt":"1.330","rSamp":"500","sSamp":"500"}
Additionally, when this happens I tend to run into a lot of AVRDUDE Out of Sync or programmer not responding errors if I try and upload a sketch. The only I/O pins connected are A0 and A1, with a 5V pin feeding the two 8495s and a voltage divider connected to ARef and GND so I can better utilize the ADC for normal HVAC temperatures.
The Serial output is currently done via several print statements:
Serial.print("{\"rTemp\":\"");
Serial.print(String(returnTemperature,1));
Serial.print("\",\"sTemp\":\"");
Serial.print(String(supplyTemperature,1));
Serial.print("\",\"dTemp\":\"");
Serial.print(String(deltaTemp,1));
Serial.print("\",\"rVolt\":\"");
Serial.print(String(returnVoltage,3));
Serial.print("\",\"sVolt\":\"");
Serial.print(String(supplyVoltage,3));
Serial.print("\",\"rSamp\":\"");
Serial.print(sampleSize - returnErrors);
Serial.print("\",\"sSamp\":\"");
Serial.print(sampleSize - supplyErrors);
Serial.println("\"}");
delay(2);
But I ran into the same issue when using a StaticJsonDocument and serializeJson to output data to the serial port.
Right now I'm just guessing a bad board since it's some unbranded amazon-bought "UNO", but is there something else I should look at to ensure my serial data is clean and uninterrupted?