Understanding input coordinates in GCODE

So we've been building a CoreXY based cnc drill and we have modified a code we found on the internet for our own project. Our assignment is that we put in three coordinates and let the machine do the drilling on those coordinates. So what I want to know is, where do I put in my coordinates in this code?

{
    case 1: {
            Serial.print("Moving");
            float dX=commandParse('X');//move somewhere
            float dY=commandParse('Y');
            float dZ=commandParse('Z');
            Move(dX,dY,dZ);
            break;
    }

ONZECOREXYFORUM.ino (5.01 KB)

So what I want to know is, where do I put in my coordinates in this code?

You send your coordinates to the Arduino in whatever way the mysterious commandParse() method expects to receive data.

Presumably the person who wrote this function knows how it works. But he certainly did his best to make it difficult for anyone else to understand it.

float commandParse(char code) 
{
  char *ptr=buffer;
  while(ptr && *ptr && ptr<buffer+charsRead) {
    if(*ptr==code) {
      return atof(ptr+1);
    }
    ptr=strchr(ptr,' ')+1;
  }
  return -1;
}

And the code in loop() for receiving characters isn't any easier to follow.

However, assuming it works there is no need to fix it. You just need to know how the input data is specified.

If you do need to change your code have a look at the second example in Serial Input Basics which was written in the hope that it could be understood. The system in the 3rd example would more robust.

...R

return atof(ptr+1);

This returns the value of a floating point number represented in the serial input buffer, immediately following the letter specified by the call argument ('X', 'Y' or 'Z').

Would it be possible to send the coordinates with the ''Universal G-code sender''?

Try it and let us know if it works!