Not receinving the complete message sent using my python code by serial port to my arduino DUE

Hi,

I am sending a frame (around 300 characters) using my python code to the arduino, but my arduino code can ' t read the totality of my frame.

Arduino code :

const byte numChars = 1200;
char receivedChars[numChars];
char tempChars[numChars];
int tramValue[numChars];
boolean newData = false;
int m = 1;

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

void loop() {
  recvWithStartEndMarkers();
  if (newData == true) {
    strcpy(tempChars, receivedChars);   // this temporary copy is necessary to protect the original data
    parseData();
    LEDLightUp();
    newData = false;
  }
}

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 * token; // this is used by strtok() as an index

  token = strtok(tempChars, ",");
  tramValue[0] = atoi(token);

  while (token != NULL) {
    token = strtok(NULL, ",");
    tramValue[m] = atoi(token);
    m++;
  }
  
}

Python code:

def sendNumLED(numLED):
    port = "COM5"
    try :
        ser = serial.Serial(port,9600,timeout=6)
        time.sleep(1)
        finalNumLED = "<"+4,0,0,180,1,4,7,11,14,17,21,24,28,31,35,38,41,47,50,54,57,60,64,67,70,74,77,80,84,87,180,176,173,169,166,163,160,157,153,150,146,142,139,134,131,127,124,120,117,113,110,107,104,100,97,93,185,188,192,195,198,202,205,208,212,215,219,222,225,231,234,238+">"
        print("Numéros des LED à allumer : "+finalNumLED)
        ser.write(finalNumLED.encode())
    except SerialException:
        return 1

If you have an idea let me know.

try

Serial.begin(115200);

Thanks for your answer, i already tryed to change the baud value, but it doesn't change anything.

really?

I tried a few value and don' t ask me why 1000 was the one who got the most character from the serial port.

how big number can store a Byte?

0 to 255

what happen if add 1 to byte variable which already store 255?

You can t

1000 - 255 - 255 - 255 = 235;
1200 - 255 - 255 - 255 - 255 = 180.
235 > 180

i can't, but you.
try this:

const byte numChars = 1200;
void setup() {
  Serial.begin(9600);
  Serial.print(numChars);
}
void loop() {}

But your using 5 byte
I don t see why you compare 235 and 180

or even this:

const byte numChars1000 = 1000;
const byte numChars1200 = 1200;

void setup() {
  Serial.begin(9600);
  Serial.print(numChars1000);
  Serial.print('>');
  Serial.println(numChars1200);
}

void loop() {}

I don't get anything in my monitor

But anyway even if i put 64 byte, i read that the buffer never get full, the arduino empty it faster than the buffer receive character. But in my case it s seems that s not the case.

Note that the 64 byte size of the Arduino serial input buffer does not limit the number of characters that you can receive because the code in the examples can empty the buffer faster than new data arrives.

got anything?

no :roll_eyes:

show

I don't know why but i got the good result now XD

232>176

variable which types is able to store 1200?