Parsing Integers from Serial data stream I'm trying to send sensor data from my Remote Control to my Bot via Bluetooth. 
It's 6 numbers that I would like to have read as integers on the other side. 
I'm printing them to Serial on the Remote side with the numbers separated by commas. I've also added a start marker "&lt;" and an end marker ">".  

The incoming data from the remote looks like this in the Bots Serial Monitor: 

&lt;1,1,1,1,1,512>
&lt;1,1,1,1,1,512>
&lt;1,1,1,1,1,513>
&lt;1,1,1,1,1,512>
&lt;1,1,1,1,1,512>
etc

Before adding in the markers I was trying to use Serial.parseInt() to do this, but I kpet getting out of order numbers (probably from no start marker?). 

if (Serial1.available() &gt; 0) {

 trig1 = Serial.parseInt();
 trig2 = Serial.parseInt();
 trig3 = Serial.parseInt();
 trig4 = Serial.parseInt();
 trig5 = Serial.parseInt();
 pot = Serial.parseInt();

if (Serial.read() == '\n') {
}
}


But now that I have the markers I don't know the best way to initialize the code.  Anyone have any ideas on how to parse these 6 numbers into usable integers?

EDIT:  I've wrote a code based on VE7JRO's comments.  

uint16_t myArray[6] = {};
int counter = 0;


void setup(){

Serial.begin(9600);

}

void loop(){
  if (Serial.available() &gt; 0) {
  char* pch = strtok(Serial.read,"&lt;&gt;,\r\n");
   }
while(pch != NULL){
  myArray[counter] = atoi(pch);
  pch = strtok(NULL, "&lt;&gt;,\r\n");
  counter += 1;
 }

 trig1 = myArray[0];
 trig2 = myArray[1];
 trig3 = myArray[2];
 trig4 = myArray[3];
 trig5 = myArray[4];
 pot   = myArray[5];

 Serial.print (trig1);
 Serial.print (", ");
 Serial.print (trig2);
 Serial.print (", ");
 Serial.print (trig3);
 Serial.print (", ");
 Serial.print (trig4);
 Serial.print (", ");
 Serial.print (trig5);
 Serial.print (", ");
 Serial.println(pot);  
 }  


I'm getting this error code: invalid use of non-static member function
for this line:  

      char* pch = strtok(Serial.read,"&lt;&gt;,\r\n");


Other than that. I subbed out the test input that  VE7JRO put in and inserted "Serial.read". Not sure if that is the correct way to do this.  Any ideas? 

I tried your second sketch.  It kind of worked.  The data that printed to the serial monitor looked like this:

1, 1, 1, 1, 1, 519
518, 1, 1, 1, 1, 519
1, 1, 1, 1, 19, 9
1, 1, 1, 1, 1, 519
1, 1, 1, 1, 1, 519
1, 1, 1, 1, 1, 518
1, 1, 519, 518, 1, 518
1, 1, 519, 518, 1, 518
1, 1, 518, 518, 1, 518
1, 1, 1, 1, 1, 8
1, 1, 1, 1, 1, 519
1, 1, 518, 1, 1, 1
8, 1, 518, 1, 1, 1
1, 1, 519, 1, 1, 1
1, 1, 1, 519, 1, 1
1, 1, 1, 519, 1, 1
1, 1, 1, 1, 1, 519
1, 1, 1, 1, 1, 518
1, 1, 1, 1, 519, 8
1, 1, 1, 1, 1, 518
1, 1, 1, 1, 1, 519
1, 1, 1, 1, 1, 518
1, 1, 1, 1, 1, 518
1, 1, 1, 1, 1, 520

it should have all been   1, 1, 1, 1, 1, 518(ish).
Here is a sketch that uses strtok() and atoi() to parse the data and store the results in an integer array.



char testInput[] = "&lt;1,2,3,4,5,512&gt;\r\n";
uint16_t myArray[6] = {};

void setup(){

  Serial.begin(9600);

  int counter = 0;
  char* pch = strtok(testInput,"&lt;&gt;,\r\n");

  while(pch != NULL){
    myArray[counter] = atoi(pch);
    pch = strtok(NULL, "&lt;&gt;,\r\n");
    counter += 1;
  }

  // Print out the contents of the integer array.
  for(int i = 0; i &lt; counter; i++){
    Serial.println(myArray[i]);
  }

}

void loop(){}


EDIT

Based on your comments, I have another sketch for you to try.

// Sample input: &lt;1,2,3,4,5,512&gt;
char testInput[40];
uint16_t myArray[6] = {};
int counter = 0;

void setup(){
  Serial.begin(9600);
}

void loop(){

  if(Serial.available() &gt; 0){

    Serial.readBytesUntil('\n', testInput, 40);

    char* pch = strtok(testInput,"&lt;&gt;,\r\n");

    while(pch != NULL){
      myArray[counter] = atoi(pch);
      pch = strtok(NULL, "&lt;&gt;,\r\n");
      counter += 1;
    }

    Serial.print (myArray[0]);
    Serial.print (", ");
    Serial.print (myArray[1]);
    Serial.print (", ");
    Serial.print (myArray[2]);
    Serial.print (", ");
    Serial.print (myArray[3]);
    Serial.print (", ");
    Serial.print (myArray[4]);
    Serial.print (", ");
    Serial.println(myArray[5]);

    counter = 0;
  }
}