Serial data transfer

I have an LCD screen that has an Arduino driving it. I am sending it x,y,z coordinates and some string data from a PC (using python) to the Arduino.
The serial data I am sending to Arduino is in the format: ‘’ where ff is a hexadecimal string number

Below is the Arduino code used to read the serial information.

void recvWithStartEndMarker(){
 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;
       }
   }
}

Then within the loop I am trying to separate the x, y and z components and draw a circle on the LCD screen corresponding to the x,y,z coordinates.

void loop(){

NewDL();        //displays on screen
recvWithStartEndMarker();
int i =1;
switch(receivedChars[0]){
 case 'x':
   xcord=0;
   while (receivedChars[i]!=NULL){
     xcord=receivedChars[i]+xcord;
     i++;
   }
   endCount++;
 case 'y':
   ycord=0;
   while (receivedChars[i]!=NULL){
     ycord=receivedChars[i]+ycord;
     i++;
   }
   endCount++;
 case 'z':
   zcord=0;
   while(receivedChars[i]!=NULL){
     zcord=receivedChars[i]+zcord;
     i++;
   }
   endCount++;
  
}
if(endCount>2){  
 API_COLOR_RGB(255,0,0);
 API_POINT_SIZE(int(zcord)*16);
 API_BEGIN(FTPOINTS);
 API_VERTEX2F(int(xcord)*16,int(ycord)*16);
 endCount=0;
}
                    
ShowDL();

This is the python code I am using to send the information, I have a very loose grasp of pyserial so please poke holes in this code if you see anything that can be improved.

 def __sendData__(xcord,ycord,zcord,data):
            
            ser.flushInput()
            print("b4")
            ser.flushInput()
            
            xcord =zcord;
            ycord=ycord;
            zcord=zcord;
            
            #assemble data to be sent
            xcordb="{0:x}".format(xcord)
            ycordb="{0:x}".format(ycord)
            zcordb="{0:x}".format(zcord)
            #datad=data
            #datad=bytes(data,'utf-8')
            #end='g'
            #end=bytes(end,'utf-8')
            #print('aft')
            start='<'
            end='>'
            xx=bytes('x','utf-8')
            yy=bytes('y','utf-8')
            zz=bytes('z','utf-8')
            start=bytes(start,'utf-8')
            end=bytes(end,'utf-8')
            xcordb = bytes(xcordb,'utf-8')
            ycordb = bytes(ycordb,'utf-8')
            zcordb = bytes(zcordb,'utf-8')
            ser.write(start);
            ser.write(xx);
            ser.write(xcordb)
            ser.write(end)
            ser.write(start)
            ser.write(yy)
            ser.write(ycordb)
            ser.write(end)
            ser.write(start)
            ser.write(zz)
            ser.write(zcordb)
            ser.write(end)
            #ser.write(datad)
            #ser.write(end)
            print('data sent')

I cant seem to get the circle to draw according to the x,y, z coordinates sent. Can anyone see any obvious things I am doing wrong?
I am more than happy to elaborate.

cchpackers1:
I have an LCD screen that has an Arduino driving it. I am sending it x,y,z coordinates and some string data from a PC (using python) to the Arduino.
The serial data I am sending to Arduino is in the format: ‘’ where ff is a hexadecimal string number

Please use code tags.

Anyways, have you gave consideration as to how to keep the data sentences in sync?

What happens if the receiver starts receiving data at instead of ? Think of the code sent as one sentence and put a beginning of sentence and an end of sentence delimiter.

Sort of like what I do here:

void fReceiveSerial_LIDAR( void * parameters  )
{
  bool BeginSentence = false;
  sSerial.reserve ( StringBufferSize300 );
  char OneChar;
  for ( ;; )
  {
    EventBits_t xbit = xEventGroupWaitBits (eg, evtReceiveSerial_LIDAR, pdTRUE, pdTRUE, portMAX_DELAY);
    if ( LIDARSerial.available() >= 1 )
    {
      while ( LIDARSerial.available() )
      {
        OneChar = LIDARSerial.read();
        if ( BeginSentence )
        {
          if ( OneChar == '>')
          {
            if ( xSemaphoreTake( sema_ParseLIDAR_ReceivedSerial, xSemaphoreTicksToWait10 ) == pdTRUE )
            {
              xQueueOverwrite( xQ_LIDAR_Display_INFO, ( void * ) &sSerial );
              xEventGroupSetBits( eg, evtParseLIDAR_ReceivedSerial );
              //
            }
            BeginSentence = false;
            break;
          }
          sSerial.concat ( OneChar );
        }
        else
        {
          if ( OneChar == '<' )
          {
            sSerial = ""; // clear string buffer
            BeginSentence = true; // found beginning of sentence
          }
        }
      } //  while ( LIDARSerial.available() )
    } //if ( LIDARSerial.available() >= 1 )
    xSemaphoreGive( sema_ReceiveSerial_LIDAR );
    //            Serial.print( "fReceiveSerial_LIDAR " );
    //        Serial.print(uxTaskGetStackHighWaterMark( NULL ));
    //            Serial.println();
    //        Serial.flush();
  }
  vTaskDelete( NULL );
} //void fParseSerial( void * parameters  )

When a character is received the char is checked to see if it the beginning of the sentence by if ( OneChar == ‘<’ ). If the beginning of the sentence has been received then the gate is open to begin receiving and storing the other received characters until a ‘>’ is received. Then the gate is closed, and the received string is sent down to be parsed. In the above case, as soon as the queue is sent the code goes back to checking for a new sentence character.

The serial data I am sending to Arduino is in the format: ‘’ where ff is a hexadecimal string number

Are you sending the hexidecimal numbers as ascii characters, or as binary data?
Are you sending the coordinates and data all in a single line, or separately?
Is the line terminated in a newline or other character to indicate end of line?

recvWithStartEndMarker();
int i =1;
switch(receivedChars[0]){
 case 'x':

You have COMPLETELY misunderstood what recvWithStartEndMarker() does. It obviously sets a flag that indicates whether it has received any data and it sets another flag that indicates whether it has received the end of the packet.

You completely ignore those flags, and ASSume that calling the function is good enough to assure that there is new, usable data in the receivedChars array.

Try again.

cchpackers1:
The serial data I am sending to Arduino is in the format: ‘’

It would make things simpler if you send it as a single message like <xff,yff,zff,data> as it would ensure that all of the pieces of data are in their correct order.

…R