Hello all,
Wish a good day to all. Currently I face a problem with Serial.readStringUntil that I can't solve. I will attach my code below. I insert a string via serial monitor. Everything works fine but If I send fast strings via serial monitor then sometimes Serial.readStringUntil doesn't catch right the string. Example string is: $GPRMC,144326.00,A,5107.0017737,N,11402.3291611,W,0.080,323.3,210307,0.0,E,A*20^ with terminator character ^. As you can see from screenshot it didn't read right the string.
I wish I explained the problem right.
#include <string.h>
#include <Wire.h>
#include <Arduino.h>
String ReadString; //Serial string
char ReadCharArray[90]; // characters number
char str2[15];
const char *Wanted_Signals[4] = {"$GPRMC", "$GPGGA", "$GPGSA", "$WIMWV"};
const byte numChars = 85;
char receivedChars[numChars];
boolean newData = false;
void setup() {
// put your setup code here, to run once:
Serial.begin(57600);
Serial.setTimeout(200); // sets the maximum milliseconds to wait for serial data. It defaults to 1000 milliseconds.
}
int i = 0;
void loop() {
//Serial.flush();
unsigned long StartTime = millis();
//delay(100);
//recvWithEndMarker();
//showNewData();
//Serial.readBytesUntil('^',ReadCharArray,90);
ReadString=Serial.readStringUntil('^'); // 94 NMEA data ends with 'return' character, which is ascii(13)
ReadString.trim(); // they say NMEA data starts with "$", but the Arduino doesn't think so.
ReadString.replace(" ","");
Serial.print("String: "); Serial.print(ReadString); Serial.print("\n");
// $GPGGA,095000.099,3935.008,N,02123.742,E,1,12,1.0,0.0,M,0.0,M,,*65^
// $GPRMC,144326.00,A,5107.0017737,N,11402.3291611,W,0.080,323.3,210307,0.0,E,A*20^
// $GPGSA,M,3,17,02,30,04,05,10,09,06,31,12,,,1.2,0.8,0.9*35^
// ReadString = "$GPRMC,144326.00,A,5107.0017737,N,11402.3291611,W,0.080,323.3,210307,0.0,E,A*20";
ReadString.toCharArray(ReadCharArray,90);
//Serial.print(ReadCharArray[13]);
// ######### only for test ########
strcpy(str2, Wanted_Signals[1]);
//###### $GPRMC
if ((!strncmp(Wanted_Signals[0], ReadCharArray, strlen(Wanted_Signals[0]))))
{
*/
Serial.print("##################");Serial.print("\n");
}
}