G-Code Crash Course for Working with Plotters

I specifically wrote about serial programming for Arduino previously because I want to feed an Arduino controlling an XY-plotter G-codes, over a serial interface.

What are G-Codes and how are they different from say SVG?

Both SVG, PDF and G-Codes do in a way represent a vector graphics image. But when plotting, routing or 3D printing a regular vector graphics format is not well suited.

G-Codes for 2D Plotting

To get an idea of how G-codes work, let me first show you the beginning of an example file.

%
G90
G49
M3 S15000
G0 X20.456 Y20.910 Z15.000
G1 Z35.000 F2500
G1 X18.202 Y13.354 F2500
X16.806 Y13.352
X15.300 Y18.656
  1. They seem to be line based. Newline is significant.

Each Line an Action

Each line is an action. So these two code segments do not do the same thing. This first line will move the pen to coordinate (20.456, 20.910, 15.00) in one motion. Coordinates are assumed to be in millimeters.

G0 X20.456 Y20.910 Z15.000
G0 X20.456 
Y20.910
Z15.000

Mode Based

Instructions like G0, G1 and others start modes. E.g. G0 means move fast, while G1 means move slow. However once you've issues G0, it will keep moving fast for every coordinate given on the following lines. It will not start to move slow until it hits a line starting with G1.

G90 and G91 for Absolute and Relative Positioning

The coordinates given by X, Y and Z instructions can be absolute or relative to current position. G90 means absolute position. G91 means relative.

G91
G0 X15 Y10

G0 and G1 for Positioning and Drawing

With G0 you go max speed to a position. That would be bad if you are say routing something with a drill bit. Thus it is what you should prefer doing when the machine is just positioning itself. Such as when the pen is lifted and moving into position.

F, Feed Rate

The F code does not matter for XY plotting, but since it pops up in the example files I have for plotting and you will probably see it often, I guess it is good to know about. Example line:

G1   Z35.000 F2500

Final Remarks

For more detailed explanation there are lots of great resources out there. I particularly liked this one from Simplify3D.

Geek dad, living in Oslo, Norway with passion for UX, Julia programming, science, teaching, reading and writing.

Get the Medium app

A button that says 'Download on the App Store', and if clicked it will lead you to the iOS App store
A button that says 'Get it on, Google Play', and if clicked it will lead you to the Google Play store