Writing Gcode in arduino IDE

I have a CNC drilling machine. I want the Arduino to do a drilling pattern when a sensor is activated. Is there a way to use the Arduino IDE and write an IF condition for that sensor so if it is true it performs a certain G-code set of instructions that is also written on the Arduino IDE? If not, how could I achieve this? I want the Arduino to do the pattern by itself, not by sending G-code through the computer.

AndresIsaacL: I have a CNC drilling machine. I want the Arduino to do a drilling pattern when a sensor is activated. Is there a way to use the Arduino IDE and write an IF condition for that sensor so if it is true it performs a certain G-code set of instructions that is also written on the Arduino IDE? If not, how could I achieve this? I want the Arduino to do the pattern by itself, not by sending G-code through the computer.

Are you quite confident your Arduino drilling machine executes G-code directly or is the G-code interpreted on your PC and resulting movement commands are sent to the Arduino drilling machine?

On the other side of the picture, how will your Arduino know when one line of G-code has completed and it's time to begin the next line?

Paul

AndresIsaacL: it performs a certain G-code set of instructions

Do you have an Arduino program that can interpret GCode?

Without that, you are not even at the starting line.

Many people use the GRBL program to interpret GCode and drive CNC stepper motors. But AFAIK GRBL is not designed to do things when sensors are activated. GRBL relies on receiving a sequence of instruction that is started by the user. I know GRBL can work with instructions sent from a PC. I think it may also be able to read the instructions from an SD Card - but only when told to do start doing so by the user.

In theory it may be possible to modify the GRBL program but that would not be easy as it is a very complex program.

My suggestion is to use your Arduino to monitor the sensor and then send a message to the PC so that the PC can interpret the GCode and send appropriate messages to the Arduino to get the stepper motors to move as needed. That way the Arduino program could be relatively simple.

...R