Why the Processing datas are not read well in the Arduino monitor? NOT RESOLVED

Hello,
I' m reading 10 ints in Arduino from Processing.
I have only 7 datas matching as below. Last one should be -7, -7, -7.
I can read this with the other Native serial port with Arduino Due.

12:00:49.940 -> A 1330
12:00:49.940 -> B 1351
12:00:49.940 -> C 1371
12:00:49.940 -> D 1392
12:00:49.940 -> E 1413
12:00:49.940 -> F -7
12:00:49.940 -> G -7
12:00:49.940 -> H 0
12:00:49.940 -> I 0
12:00:49.940 -> J 0

But sometimes 10 datas match...

I send this from Processing (it's an example, not what I have actually send with the data above)
<3155,3370,3586,3801,4017,-16,-17,-18,-19,-20>

I put a video on youtube to be more explicit.

My Arduino Program

//***********  Managing Variable coming from Processing
long w0, w1, w2, w3, w4; // position in step
boolean dataReady = false;
int i; // test speed of motor
int j;



// Example 5 - Receive with start- and end-markers combined with parsing

const byte numChars = 32;
char receivedChars[numChars];
char tempChars[numChars];        // temporary array for use when parsing

      // variables to hold the parsed data
char messageFromPC[numChars] = {0}; //not used for the moment
int integerFromPC0 = 0;
int integerFromPC1 = 0;
int integerFromPC2 = 0;
int integerFromPC3 = 0;
int integerFromPC4 = 0;
int integerFromPC5 = 0;
int integerFromPC6 = 0;
int integerFromPC7 = 0;
int integerFromPC8 = 0;
int integerFromPC9 = 0;

float floatFromPC0 = 0.0; // not used for the moment
float floatFromPC1 = 0.0; // not used for the moment
float floatFromPC2 = 0.0; // not used for the momen
float floatFromPC3 = 0.0; // not used for the moment
float floatFromPC4 = 0.0; // not used for the momen

boolean newData = false; // In order to not copy any datas from the serial if there is no datas coming.

//============

void setup()
{  
   // Does change  baud of serial begin change precisio of the movement or  NO!!!!!!
    Serial.begin (250000); //Port to receive datas: It's a serial port called the Programming port, the program of Arduino is transfered with. And in which go datas from Processing
    SerialUSB.begin (250000); //Port to send datas.It's a NativeUSB port in the Arduino Due just to transfer datas from Arduino to an other software. 
    // I read datas in the Arduino monitor with this Native serial port. In this one go each of 5 datas,
    // from Processing named with a letter. example 10, 12, 14,16, 18--> A 10, B 12, C 14, D 16, E 18
    // Thoses datas indexed will go in Max Msp.
    
 // Select the good port to see datas in the monitor
    Serial.print ("To see datas from Processing, don't forget to select the Native Port, you are on the programming port");     
 
    
// Set MaxSpeed, Acceleration and speed of each motors
  for(uint8_t i = 0; i < NBMOTEURS; i++) {      
  stepper[i].setMaxSpeed(600); 
  stepper[i].setAcceleration(150); // set number of step * seconde -2. 250 bof. 300 trop? 200 OK (sauf 1)
  stepper[i].setSpeed(400); // set number of step * second -1. 500 OK. 400 
   }
}

void loop() { 

//  testStepMotors();

   recvWithStartEndMarkers();  // Receive datas from Processing.
 //  recvWithStartEndMarkersBis(); 
    if (newData == true) {
        strcpy(tempChars, receivedChars);
            // this temporary copy is necessary to protect the original data
            //   because strtok() used in parseData() replaces the commas with \0
        parseData(); 
    
         controlPositionMotor();   
         sendDataToMaxNativePort(); 
         sendDataToMaxProgrammingPort(); 
        newData = false;
    }

  
// sendCounterToMaxProgrammingPort(); 
//testPotarMotor(); // work perfectly
//TestSpeedSendDataToMax (); //work perfectly

// Serial.print("X");  // Richard solution  
}

void recvWithStartEndMarkers() {
    static boolean recvInProgress = false;
    static byte ndx = 0;
    char startMarker = '<';
    char endMarker = '>';
    char rc;

    while (Serial.available() > 0 && newData == false) {
        rc = Serial.read();

        if (recvInProgress == true) {
            if (rc != endMarker) {
                receivedChars[ndx] = rc;
                ndx++;
                if (ndx >= numChars) {
                    ndx = numChars - 1;
                }
            }
            else {
                receivedChars[ndx] = '\0'; // terminate the string
                recvInProgress = false;
                ndx = 0;
                newData = true;
            }
        }

        else if (rc == startMarker) {
            recvInProgress = true;
        }
    }
}

//============

void parseData() {      // split the data into its parts

    char * strtokIndx; // this is used by strtok() as an index

    strtokIndx = strtok(tempChars,",");      // get the first part - the string
 
 // POSITIONS    // REVOLUTIONS
    integerFromPC0 = atoi(strtokIndx);     // convert this part to an integer
    strtokIndx = strtok(NULL, ","); // this continues where the previous call left off
    integerFromPC1 = atoi(strtokIndx);     // convert this part to an integer
    strtokIndx = strtok(NULL, ","); // this continues where the previous call left off
    integerFromPC2 = atoi(strtokIndx);     // convert this part to an integer
    strtokIndx = strtok(NULL, ","); // this continues where the previous call left off
    integerFromPC3 = atoi(strtokIndx);     // convert this part to an integer
    strtokIndx = strtok(NULL, ","); // this continues where the previous call left off
    integerFromPC4 = atoi(strtokIndx);     // convert this part to an integer
    strtokIndx = strtok(NULL, ","); // this continues where the previous call left off
    integerFromPC5 = atoi(strtokIndx);     // convert this part to an integer
    strtokIndx = strtok(NULL, ","); // this continues where the previous call left off
    integerFromPC6 = atoi(strtokIndx);     // convert this part to an integer
    strtokIndx = strtok(NULL, ","); // this continues where the previous call left off
    integerFromPC7 = atoi(strtokIndx);     // convert this part to an integer
    strtokIndx = strtok(NULL, ","); // this continues where the previous call left off
    integerFromPC8 = atoi(strtokIndx);     // convert this part to an integer
    strtokIndx = strtok(NULL, ","); // this continues where the previous call left off
    integerFromPC9 = atoi(strtokIndx);     // convert this part to an integer

}   

  
//============



void controlPositionMotor () {  
  
       stepper[4].moveTo(integerFromPC4);
       stepper[4].run();
       stepper[3].moveTo(integerFromPC3);
       stepper[3].run();
       stepper[2].moveTo(integerFromPC2);
       stepper[2].run();
       stepper[1].moveTo(integerFromPC1);
       stepper[1].run();
       stepper[0].moveTo(integerFromPC0); // First data from Processing reachs here.
       stepper[0].run(); 
}
  

void  sendDataToMaxNativePort() { // Arduino --> Max --> Processing
  
    SerialUSB.print ("A "); SerialUSB.println (integerFromPC0);    
    SerialUSB.print ("B "); SerialUSB.println (integerFromPC1);        
    SerialUSB.print ("C "); SerialUSB.println (integerFromPC2);    
    SerialUSB.print ("D "); SerialUSB.println (integerFromPC3);         
    SerialUSB.print ("E "); SerialUSB.println (integerFromPC4); 
    SerialUSB.print ("F "); SerialUSB.println (integerFromPC5);    
    SerialUSB.print ("G "); SerialUSB.println (integerFromPC6);        
    SerialUSB.print ("H "); SerialUSB.println (integerFromPC7);    
    SerialUSB.print ("I "); SerialUSB.println (integerFromPC8);         
    SerialUSB.print ("J "); SerialUSB.println (integerFromPC9); 


  
}

void sendDataToMaxProgrammingPort() { // Arduino --> Max --> Processing
  
 
  
    Serial.print ("A "); Serial.println (integerFromPC0);    
    Serial.print ("B "); Serial.println (integerFromPC1);        
    Serial.print ("C "); Serial.println (integerFromPC2);    
    Serial.print ("D "); Serial.println (integerFromPC3);         
    Serial.print ("E "); Serial.println (integerFromPC4); 
    Serial.print ("F "); Serial.println (integerFromPC5);    
    Serial.print ("G "); Serial.println (integerFromPC6);        
    Serial.print ("H "); Serial.println (integerFromPC7);    
    Serial.print ("I "); Serial.println (integerFromPC8);         
    Serial.print ("J "); Serial.println (integerFromPC9); 

  
}

void  sendCounterToMaxProgrammingPort() { // Arduino --> Max --> Processing
  
    Serial.print ("F "); Serial.println (integerFromPC5);    
    Serial.print ("G "); Serial.println (integerFromPC6);        
    Serial.print ("H "); Serial.println (integerFromPC7);    
    Serial.print ("I "); Serial.println (integerFromPC8);         
    Serial.print ("J "); Serial.println (integerFromPC9); 

  
}

We can't receive more than 6 datas at the same time?

Now I send three part of datas.

Like this in Processing

<-596,-631,-665,-699,-734,3,3,3,3,3>
*3,3,3,3,3*
$10651,8239,5827,3415,1003$
<-597,-632,-666,-701,-735,3,3,3,3,3>
*3,3,3,3,3*
$10575,8158,5740,3323,905$
<-598,-633,-667,-702,-736,3,3,3,3,3>
*3,3,3,3,3*
$10499,8076,5653,3230,807$

And I receive this in Arduino

18:51:50.465 -> A -598B -633C -667D -702E -736F 3G 3H 3I 0J 0
18:51:50.465 -> K 3L 3M 3N 0O 0
18:51:50.498 -> P 10651Q 8239R 5827S 3415T 1003
18:51:50.498 -> A -598B -633C -667D -702E -736F 3G 3H 3I 0J 0
18:51:50.498 -> K 3L 3M 3N 0O 0
18:51:50.498 -> P 10651Q 8239R 5827S 3415T 1003

As you can see I add letter to my data in Arduino.

Ans sometimes datas are 0, like here 18:51:50.498 -> K 3L 3M 3N 0O 0 , the two last data should be 3

, or I have T 10 and I should have T 1003.

My Arduino Program below

Thanks

oscillators_positionBisOKbislight.ino (11.8 KB)

const byte numChars = 32;

The maximum packet size is 32 bytes. Increase that number to receive larger packets.

groundFungus:

const byte numChars = 32;

The maximum packet size is 32 bytes. Increase that number to receive larger packets.

I have changedconst byte numChars = 32; with numChars =256 and I have in the Arduino Monitor

14:19:09.576 -> A 255B 0C 0D 0E 0F 0G 0H 0I 0J 0
14:19:09.576 -> K 0L 0M 0N 0O 0
14:19:09.614 -> P 0Q 0R 0S 0T 0
14:20:52.801 -> A 255B 0C 0D 0E 0F 0G 0H 0I 0J 0
14:20:52.801 -> K 0L 0M 0N 0O 0
14:20:52.801 -> P 0Q 0R 0S 0T 0

So it is very bad

with 128 it is better I have

14:26:58.209 -> A -3044B -3233C -3423D -3612E -3801F 15G 16H 17I 18J 19
14:26:58.209 -> K 15L 16M 17N 18O 19
14:26:58.209 -> P 6746Q 6528R 8196S 15T 16

when I send this with Processing

<-3044,-3233,-3423,-3612,-3801,15,16,17,18,19>
*15,16,17,18,19*
;6410,6892,7804,5497,9199;

The two first lines in the Arduino Monitor are perfect. But last datas in Arduino Monitor (P Q R S T) don't correspond at all, it was datas printed from 4 frame in Processing
and the real data in Processing was
;6746,6528,8196,5077,9647;

There is an offset too with data 15 and 16 send from the second line in Processing

And with const byte numChars = 64;
it is worst because have this in Arduino

14:45:20.015 -> A -443B -834C -1225D -1616E -2007F 2G 4H 6I 8J 10
14:45:20.015 -> K 2L 4M 6N 8O 10
14:45:20.015 -> P 6Q 0R 0S 0T 0

when I send this from Processing

<-443,-834,-1225,-1616,-2007,2,4,6,8,10>
*2,4,6,8,10*
;6606,6102,5598,5094,4591;

There is a limit of data we can read in the Native serial Port of the Arduino Due

Or should I have to find the perfect const byte.

Or for example alternate the nature of the datas by sending
<-ints>
floats
;ints;

Thank you.

Hello.

I send exactly the same 10 ints, three time with different markers <>. ** ;;

like this with Processing
691: <50,50,50,50,50,0,0,0,0,0>
691: 50,50,50,50,50,0,0,0,0,0
691: ;50,50,50,50,50,0,0,0,0,0;

I receive this in Arduino
A 50B 50C 50D 50E 50F 0G 0H 0I 0J 0
K 0L 0M 0N 0O 0P 0Q 0R 0S 0T 0
U 0V 0W 0X 0Y 0Z 0a 0b 5c 5d 58

const byte is set at 128. There is no difference with 32.

I didn't try my test of the previous post but maybe I should.

Have you considered that having a buffer with 256 elements and an eight bit index into that buffer might not be the best strategy?

TheMemberFormerlyKnownAsAWOL:
Have you considered that having a buffer with 256 elements and an eight bit index into that buffer might not be the best strategy?

I want to read three time the same ten ints. It's to simply my example.
In the future I would like to read 30 datas from one frame from Processing

I don't know if I have to specified something precisely to read and parsed data.
I'm just copy and modify the code without understanding the hole program.

If you have any idea, I will be very careful about the solution.

I have changed my program. It is attached

Thank you.

oscillators_position_revolution_data.ino (19.9 KB)