G code interperter

Hello everyone,i'm new on this forum.I couldn't find the introduction topic so let's make this one be my personal introduction :slight_smile:

I'm form Croatia,my name is Tomislav i'm 19,I've got my arduino uno a few weeks ago and i've pretty much got the hang of programing it.

Now to cut to the chase,

i've made a small CNC engraver

I've worked with CNC metal milling machines and naturally i'm most comfortable controlling it with g-code which i plan to send trough serial via linux terminal,

for you who don't know how a g-code looks like here's an example:

G0 X10 Y10;
G1 Z-40;
G1 X-10 ;
G1 Y-10;
G1 X10;
G1 Y10;
G1 Z5;
G0 Z35;
G0 X0 Y0;

it's supposed to make a rectangle

i haven't really used Serial.read() and similar commands much but basically i need it to tell the difference between G0 and G1 and set the stepper speeds accordingly,
to read the number behind X,Y and Z and move the right axis.

G0 and G1 are optional but i really need X,Y,Z

I've already got the rest of the controls like speed,sensor switches, and the steps each motor needs to make to move 1 mm

i just need it to tell the difference between the axis marks(XYZ)

Any ideas?

Thanks for reading :slight_smile:

I suggest looking at the "Communications" examples. CharacterAnalysis looks like it has a lot of good stuff in it.

For my small lathe I convert the GCode using Python on my PC and just send numbers to the Arduino for the total time for a movement and the intervals between steps. The timings are in microsecs.

In any case you may find the examples in Serial Input Basics useful. They are simple reliable ways to receive data.

...R

Have a character buffer where you read an entire line into (read until CRLF) and then go though looking for white space or alpha characters to either chop out into separate char arrays or generate pointer/length array that indexes the original char buffer.
Then go though these arrays pointers to determine the meanings. The first should always be a command (G, M) and the rest (if any) parameters for that command (X, Y, Z, F etc). If they are position parameters like x,y,z then determine what direction and how fast you step from current position to new position and perform it.

Another option might be to see how GRBL does it.