Send commands to GRBL(on an arduino Uno) using a Arduino Mega

So i have build a machine that is controlled by an Arduino Mega. It has an XY table that is run by two stepper motors. These two steppers need a seperat controller to run fast enough, so i have flashed a Arduino Uno with GRBL and connected the GRBL arduino to the Arduino mega thorugh the mega’s serial1 port.

Using the SerialPassthrough (on the mega) i can communicate with the GRBL arduino. Everything works.

I can now write a code that controls the machine and if i need to move the steppers i send something like “x1000 y500” thorugh the serial1 and it moves to these positions. So far so good.

My problem is, how do i check when the position has been reached? GRBL only sends a ok command, when the position is received, not when it have arrived at that position.

I can send a “?” while is is running and then it returns the actual position (at the time requested) in this string:

<Run|MPos:159.100,32.844,0.000|FS:1030,0|Pn:XYZ>

(When i send the ? in the above example we were a X159.100 Y32.844)

Is the best approach to disect this string and retrieve the current position and then compare this to the commanded position? Am i missing an easier way? If this indeed the right way, how do i disect this string most efficiently?

Best regards

Okay so i just discovered (facepalm) that when it is not running aka. when it has reached the position, it says:

<Idle|MPos:1000.000,500.000,0.000|FS:0,0|Pn:XYZ>

It litteraly tells you in the first part of the string what it does. That makes it so much more easy. Know i can just check the first letter, if it is R (as in Run) its not there and if it is I (as in Idle) it is there.

Other suggestions are stil welcome :slight_smile:

You may find some ideas in Serial Input Basics - simple reliable ways to receive data - especially the 3rd example and the parse example.

...R