G-code is the programming language based on RS274 that’s used by machines like 3D printers, CNC machines, and laser engravers. Essentially, it’s the instructional commands that a printer’s firmware interprets so that the printer can function as you want it to. The ‘G’ in G-code is one of the command letters from RS274, and other letter codes (‘M’, ‘S’, and more) exist, too. However, when someone says “G-code” nowadays, they’re usually referring to the RS274 language as a whole.

Each G-code specification is written with a letter followed by a number, and every combination has a different function and purpose. For example, the command G0 tells your printer to move rapidly while the command G1 is for moving in a controlled manner.

Every line of G-code can also contain multiple commands, and some commands only work with specified coordinates that go after that initial command. For example, you can’t just use input G0. Instead, you have to specify the coordinates such as G0 X10 Y10, which tells your printer to rapidly move to 10 units on the X- and Y-axis. For reference, every print or machining job can contain hundreds, if not thousands, of G-code lines.

As we said, each G-code command serves a different purpose, and some are used for movement, while others are used for heating, pausing, and more. The G-code command G28 is a handy one that moves your machine’s axes to their true zero position or home. In this article, we’ll go over the G28 command, reviewing what it does and how you can use it with examples.

Back to Contents

G28 G-code: The Basics

How To Use It

You can use Pronterface or another G-code terminal to send G-code to your machine
You can use Pronterface or another G-code terminal to send G-code to your machine (Source: 3daybreaker via GitHub)

The G28 command homes all of your machine’s different movement axes, pushing any carriages on the X-, Y-, and Z-axis to their endstop. The endstop (also known as a limit switch) on each axis is the sensor device that signals when the end of the path on an axis has been reached.

Although many CNC machines don’t have endstops, they still respond to the G28 command, but the home position is just a digitally set or fabricated location. So sending the G28 command on a CNC machine will bring the axis to their last set or recorded home origin position.

To use this G-code command, it’s super easy! All you have to do is open up a G-code terminal like Pronterface or the one integrated in OctoPrint‘s user interface. Then input G28 followed by the specific axes you want to be homed, and your machine will bring the specified axes to their home position. This will happen regardless of any endstops of temporary work offsets, like the ones set by the G92 command.

Basically, the G28 command is just a condensed form of G0 X0 Y0 Z0. Unless you specify which axis you want to home (G28 X), it will home all axes. So, for example, G28 would equate to G0 X0 Y0 Z0 and tell your printer to move to those coordinates, while G28 X Z would mean G0 X0 Z0 (telling your printer to move the X- and Z-axis to their endstop home positions).

If you use an auto bed leveling (ABL) sensor like BLTouch, the sensor serves as your endstop. When you use the G28 command with an ABL sensor, your printer (if its firmware is set up correctly) will move the Z-axis down until the endstop ABL sensor is triggered.

When to Use It

You can also use the G28 command on CNC machines or other machines with no endstops
The G28 command can be used on CNC machines (Source: Michael Una via Inventables)

For 3D printing, basically every slicer will include the G28 command as one of the commands in the start G-code script. Without it, you’d have to manually move your printhead to its home starting position, as you have to do on a CNC machine to home the axes.

You should use the G28 command before any print job on a 3D printer because you want every axis carriage to be at its true home position before the printer starts reading new G-code script. If you didn’t home your 3D printer before use, it would start a print job relative to wherever it’s currently located.

On this note, the G91 command turns your printer to incremental or relative positioning mode, while the G90 command sets your machine to absolute (true) position mode. These commands are commonly used before sending a G28 command on a machine with no endstops to put each axis in its home position.

Image of:
It's important to start a print in the right place (Source: Bondtech)

So, let’s say you want to set a new home position on your machine 3 mm above where your tool head is right now. You could send the command G91 G0 Z3, followed by the command G28 X0 Y0 Z0, which would tell the machine to move to the new position and then set it as the home position. Alternatively, you could simply send the command G91 G28 X0 Y0 Z3, which combines these two lines.

Overall, the G28 command is necessary for any machine or print job because it allows the machine to find its home and origin. The G28 command is easy to send and use, and no coordinate specification is required unless you want to only home certain axes. Also, the command isn’t constrained by temporary work offsets, and you can even use the G28 command on machines without endstops.

Back to Contents

Advertisement
Advertisement
Advertisement
G28 G-code: The Basics

Common Issues

Make sure to reactivate your bed leveling values after using the G28 command
Make sure to reactivate your bed leveling values after using the G28 command (Source: VinayakNair via Instructables)

While there aren’t that many issues with the G28 command, you may have some trouble using it. Below are a couple of problems and solutions you can use to get the G28 command to function properly:

  • Bed leveling values lost: If you’re using a bed leveling method and the values aren’t being applied to prints, your firmware needs to be changed. All you need to do is add the command M420 S after every instance of the G28 command, or, if you have Marlin firmware, you could use the command RESTORE_LEVELING_AFTER_G28.
  • ABL sensor pin deploys: One user mentioned how on their printer with two endstops on the Z-axis, the sensor deployed when they sent the G28 command. In response, a developer for Marlin firmware recommended connecting the ABL sensor to a pin that’s not Z_Min_PIN, enabling Z_MIN_PROBE_ENDSTOP, and disabling Z_MIN_PRBE_USES_Z_MIN_ENDSTOP_PIN in Marlin firmware.

Back to Contents

Advertisement
Advertisement

Lead image source: Core3D Custom Printers

License: The text of "G28 G-code: All You Need to Know about Homing" by All3DP is licensed under a Creative Commons Attribution 4.0 International License.

Stay informed with notifications from All3DP.

You get a notification when a new article is published.

You can’t subscribe to updates from All3DP. Learn more… Subscribe to updates

You can’t subscribe to updates from All3DP. Learn more…

Topics
Advertisement