I am receiving a communication from another arduino composed from a number, a letter and termination. Here is how I send it.
sprintf_P(ToSend, PSTR("%04d, %c, %02d\n"), 14, 'R', '\n');
Serial3.write (ToSend);
On the receiving side I got the code below. Works great, except I am not getting the R character, I always get an i. GO figure. Please help,
void recvWithEndMarker() {
static byte ndx = 0;
char endMarker = '\n';
char rc;
while (Serial3.available() > 0 && newData == false) {
rc = Serial3.read();
if (rc != endMarker) {
receivedChars[ndx] = rc;
ndx++;
if (ndx >= numChars) {
ndx = numChars - 1;
}
}
else {
receivedChars[ndx] = '\0'; // terminate the string
ndx = 0;
newData = true;
}
}
}
void showNewData()
{int X1_Latest=0;
char X2_Latest = 'x';
if (newData == true) {
char* ptr;
ptr = strtok(receivedChars, ",");
X1_Latest = atoi(ptr);
ptr = strtok(NULL, ",");
X2_Latest = ptr;
Serial.print(" X1 Latest: ");
Serial.print(X1_Latest);
Serial.print(" X2 Latest: ");
Serial.println(X2_Latest);
//Serial.println(receivedChars);
newData = false;
}
}