gcode command reference table

Explain

This page describes the commands supported by the gcode()
function, their command formats, and how to use them. The "-" sign in the command format (e.g. G1 Axes- F- ) represents a numeric input. For details on the various motion effects, see the Motion Methods Description page.

G-Code Reference Table

G-Code explain
G1 Linear motion
G2 Clockwise circular motion
G3 Counterclockwise circular motion
G4 Pause Command
G17 Select the XY plane of circular motion
G18 Select the XZ plane for circular motion
G19 Select the YZ plane for circular motion
G90 Absolute Position Mode
G91 Relative Position Mode
G90.1 Absolute position mode for arc center
G91.1 Arc center relative position mode
G92 Coordinate System Offset

G1

G1 Axes- F-

For linear movements, G90 and G91 can be used to specify absolute or relative mode.

  • Axis: The coordinates of the end point
  • F: Feed rate
Example:

1. Move in a straight line from the current position to absolute coordinates (10,10,20) at a feed rate of 500.

1
2
machine.gcode("G90");
machine.gcode("G1 X10 Y10 Z20 F500");       

2. Move relative to the current position (10,-10,20)

1
2
machine.gcode("G91");
machine.gcode("G1 X10 Y-10 Z20 F500");           

3. The X and Y axis positions of the current position are not changed, and the Z axis is moved to absolute coordinate Z=50.

1
2
machine.gcode("G90");
machine.gcode("G1 Z50 F500");                       

G2、G3

Center Mode:

G2 Axes- Offsets- P- F-

Radius Mode:

G2 Axes- R- P- F-

G2 is a clockwise circular move, and G3 is a counterclockwise circular move, and can be combined with G17, G18, and G19 to specify the circular plane and helix axis.

  • Axis: The coordinates of the end point
  • Offset: Center of arc
  • R: Radius of the arc
  • P: Number of circles drawn
  • F: Feed rate

The arc radius R can be negative. If it is negative, the path of the drawn arc will be greater than 180°. Depending on the combination of parameters, you can draw shapes such as arcs, circles, and spirals. For details on how it works, see the description of how it works .

Example:

1. On the XY plane, draw a 90° arc from (0,0,0) to (50,50,0) with (50,0,0) as its center.

1
2
3
machine.gcode("G90");
machine.gcode("G1 X0 Y0 Z0 F500");
machine.gcode("G2 X50 Y50 I50 J0 F500");//If you use the circle center mode, the center of the circle will be (50,0,0), and the arc will be (50,50,0)

2. On the XY plane, draw a 90° arc centered at (50,0,0) from (0,0,0) to (50,50,0).

1
2
3
machine.gcode("G90");
machine.gcode("G1 X0 Y0 Z0 F500");
machine.gcode("G2 X50 Y50 R50 F500");//Draw a clockwise arc with radius 50 using radius mode (50,50,0)

3. On the XY plane, draw a 270° arc from (0,0,0) to (50,50,0) with (50,0,0) as its center.

1
2
3
machine.gcode("G90");
machine.gcode("G1 X0 Y0 Z0 F500");
machine.gcode("G3 X50 Y50 R-50 F500");//R -50 Masterpiece Largeーク

 

4. On the XY plane, draw a 90° arc centered at (0,50,0) from (0,0,0) to (50,50,0).

1
2
3
machine.gcode("G90");
machine.gcode("G1 X0 Y0 Z0 F500");
machine.gcode("G3 X50 Y50 R50 F500"); //Draw a counterclockwise arc with radius 50 using radius mode (50,50,0)

5. Draw a circle on the XZ plane, starting from (0,0,0) and moving clockwise, centered at (0,0,50).

1
2
3
4
machine.gcode("G90");
machine.gcode("G1 X0 Y0 Z0 F500");
machine.gcode("G18");
machine.gcode("G2 X0 Z0 I0 K50 F500");//If the start and end points are the same, it will be a circle.

6. With XY as the arc surface, the origin as the center, the Z axis as the height, and a pitch of 10, draw a clockwise spiral starting at (50,0,0) and ending at (50,0,100).

1
2
3
4
5
machine.gcode("G90");
machine.gcode("G1 X50 Y0 Z0 F500");
machine.gcode("G17");
//On the xy plane, draw a spiral line with the z axis pointing up. P 10 means it will go around in a total of 10 circles to reach the destination.
machine.gcode("G2 X50 Y0 Z100 I-50 J0 P10 F500");

G4

G4 S-

G4 P-

The machine will stop working for a while.

  • S: Time in seconds. Both inputs must be integers.
  • P: Time (milliseconds)
Example:

1. Wait for 2 seconds at coordinates (50,0,0), then move in a straight line to coordinates (0,50,0).

1
2
3
4
machine.gcode("G90");
machine.gcode("G1 X50 Y0 Z0 F500");
machine.gcode("G4 S2");
machine.gcode("G1 X0 Y50 Z0 F500");

2. Wait for 0.5 seconds at coordinates (50,0,0), then move in a straight line to coordinates (0,50,0).

1
2
3
4
machine.gcode("G90");
machine.gcode("G1 X50 Y0 Z0 F500");
machine.gcode("G4 P500");
machine.gcode("G1 X0 Y50 Z0 F500");

G17、G18、G19

G17

G18

G19

Specifies the plane of the circular motion, if not specified it will be preset to G17.

  • G17: Specifying a plane as the XY plane
  • G18: Specifying a plane as the XZ plane
  • G19: Specifying a plane as the YZ plane
Example:

1. Starting at the origin (0,0,0), draw a circle clockwise in the XY plane with center (50,0,0) and radius 50, and draw a circle counterclockwise in the YZ plane with center (0,0,50) and radius 50.

1
2
3
4
5
6
machine.gcode("G90");
machine.gcode("G1 X0 Y0 Z0 F500");
machine.gcode("G17")
machine.gcode("G2 X0 Y0 I50 J0 F500");
machine.gcode("G19")
machine.gcode("G3 Y0 Z0 J0 K50 F500");

2. With XZ as the arc face, (0,0,50) as the center, Y as the height, and a pitch of 10, draw a clockwise spiral starting at (0,0,0) and ending at (0,100,0).

1
2
3
4
5
machine.gcode("G90");
machine.gcode("G1 X0 Y0 Z0 F500");
machine.gcode("G18");
// A spiral line is created clockwise along the Y axis with a height of 100 and a total of 10 turns.。
machine.gcode("G2 X0 Y100 Z0 I0 K50 P10 F500");

G90、G91

G90

G91

Sets the position coordinate mode. If not specified, it will be preset to G90.

  • G90: When using Absolute mode, axis parameter values ​​for G1, G2 and G3 commands are absolute positions.
  • When G91: Relative mode is used, axis parameter values ​​for G1, G2 and G3 commands are relative positions.
example:

1. Move a line from the current position to the absolute coordinates (10,10,20).

1
2
machine.gcode("G90");
machine.gcode("G1 X10 Y10 Z20 F500");

2. Move relative to the current position (10,-10,20)

1
2
machine.gcode("G91");
machine.gcode("G1 X10 Y-10 Z20 F500");

3. Draw an arc clockwise from coordinates (50,0,0) with center (100,0,0) and radius 50, moving it to (150,0,0).

1
2
3
machine.gcode("G90");
machine.gcode("G1 X50 Y0 Z0 F500");
machine.gcode("G2 X150 Y0 I50 J0 F500");

4. Draw an arc clockwise from coordinates (50,0,0) with center (100,0,0) and radius 50, moving it to (150,0,0).

1
2
3
4
machine.gcode("G90");
machine.gcode("G1 X50 Y0 Z0 F500");
machine.gcode("G91");
machine.gcode("G2 X100 Y0 I50 J0 F500");

G90.1、G91.1

G90.1

G91.1

Sets the mode of circle center coordinates. If not specified, it will be preset to G91.1.

  • G90.1: When using absolute mode, the offset parameter values ​​for G2 and G3 commands become absolute positions.
  • G91.1: When using relative mode, the offset parameter values ​​for G2 and G3 commands are relative positions.
Example:

1. Draw an arc clockwise from coordinates (50,0,0) with center (100,0,0) and radius 50, moving it to (150,0,0).

1
2
3
4
machine.gcode("G90");
machine.gcode("G1 X50 Y0 Z0 F500");
machine.gcode("G90.1");
machine.gcode("G2 X150 Y0 I100 J0 F500");

2. Draw an arc clockwise from coordinates (50,0,0) with center (100,0,0) and radius 50, moving it to (150,0,0).

1
2
3
4
machine.gcode("G90");
machine.gcode("G1 X50 Y0 Z0 F500");
machine.gcode("G91.1");
machine.gcode("G2 X150 Y0 I50 J0 F500");

G92

G92 Axes-

The coordinate system offset, which specifies the coordinate value of the axis' current position.

  • Axis: The coordinates of the current position
Example:

1. Offset the coordinate system and specify the current position as absolute coordinates (50,50,50).

1
machine.gcode("G92 X50 Y50 Z50");

reference

How it works()
gcode()


Library Reference

The text of the 86Duino reference material is licensed under Creative Commons Attribution-ShareAlike 3.0 Code examples within the reference material are released into the public domain.