The second one shows that you can synchronize on the char 13 (which is a newline)
now using double buffering -something like this. data is collected in val array and if full it is copied for use into buffer.
unsigned long lastTime = 0;
int count = 0;
char val[6];
char buffer[6];
void setup()
{
Serial.begin(....);
lastTime = millis();
}
void loop()
{
if (pH.available() >0)
{
char incharPH = (char)pH.read();
if (inharPH == 13)
{
val[count] = 0;
count = 0;
strcpy(buffer, val);
}
val[count] = inCharPH;
}
if (millis() -1000 > lastTime)
{
Serial.println(buffer);
lastTime += 1000;
}
// rest of code
}
I saw on the datasheet that the sensor could be calibrated using one of the various commands.
No time to dive into that now, sorry ...