Seperating bytes from Processing over serial

Hi all,

I'm trying to send two values, mouseX and mouseY, to my Arduino Diecimilla over serial. It works fine with just one value, but I'm really not sure how to send two values and then seperate them out of the incoming serial data on the Arduino. I haven't been able to find anything on Google, mostly because I don't know what I'm searching for. Is this called flow control? The best solution I can come up with is formatting the serial data, say for example by inserting an x in front of the x value and a y in front of the y value, and then checking each incoming byte in my Arduino code, looking for an x character or a y character. The specifics of all that kind of scare me though and I have no idea where to start...

Or another thought was to have Processing send one byte of data corresponding to mouseX, then wait for a confirmation from Arduino that the byte has been recieved, then Processing would send the next byte, mouseY, and so on.

I just keep thinking that there has to be a more elegant and well established method for dealing with this problem. All of the Processing / Arduino tutorials and references I've found refer to sending single values only. Might someone be able to please point me in the right direction? Even if you could just throw some search terms at me that would be great - my brain is exploding.

Cheers,

Rob

Why not send a line with x and y value and a newline character? So every line only has x and y value. Hmm, but you still need to separate on a space. Ok, the code below is a piece from a gps program. It replaces comma’s with the 0’s. So instead of one long string I have a bunch of strings after each other.

int gpsLine_size = strlen(gpsLine);
while((gpsLine[i]) && (i<gpsLine_size))
            {
              if(gpsLine[i] == ',')
              {
                commacount++;
                gpsLine[i] = 0;
                i++;
                  if (commacount == 1) timePtr = &gpsLine[i];
                if (commacount == 2) latPtr = &gpsLine[i];
                if (commacount == 4) lonPtr = &gpsLine[i];
              }
              else i++;
            }

In your case, if you have a space between the values you can replace this by a 0 and create a pointer to the next character. So, something like this:

xPtr = &xyline[0];
while( i< strlen(xyline)
{
    if (xyline == ' ')
    {
         i++;
         yPtr = &xyline[i];
     }
     else i++;
}

Just typed in the code, didn’t check it. It is only for insipiration. :slight_smile: