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.