Parse a serial string

i am kind of new to arduino.

I have a program sending a serial string $ABDATA,xx,yy. and i want the x and the y in two int numbers. but Serial.parseInt() will not work because of there is letters in the string? and i have tryed a lot of other different methodes but cant find one that will work for me. xx is a position from 0 to 255 and yy is a speed from 0 to 1000 $ABDATA is contant and is not importent.

Thanks alot \Yakov

Hello and welcome :slight_smile:

The easiest way is to use sscanf

i have tryed a lot of other different methodes but cant find one that will work for me.

The homework hotline is currently closed. You need to post some code.

I understand it can be hard for beginners… This example will read everything available in the Serial buffer until a “\r” is found, and then will try to parse as you described:

void loop()
{
  // if there is something in the serial buffer
  if ( Serial.available() > 0 ) 
  {
    static char input[64];
    static uint8_t i;
	
    // read one character
    char c = Serial.read();

    // if the character is not a "\r" and the input buffer is not full 
    if ( c != '\r' && i < 64-1)
    {
      // store the character at the end of the input buffer
      input[i++] = c;
    }
	
    // else, the input is ready to be processed
    else
    {
      // add a null terminator to make it a valid C string
      input[i] = '\0';
      //reset index for the next serial message
      i = 0;
      
      // try parsing the input as you described
      uint8_t xx;
      uint16_t yy;
	  
      if ( sscanf( input, "$ABDATA,%hhu,%hu", &xx, &yy ) == 2 )
      {
        Serial.println( xx );
        Serial.println( yy );
      }
    }
  }
}