IntroductionWhen 3D printers, and many other machines, are first powered up they have no record of where the actual moving parts may be. One of the first things that usually happens when a machine comes online is something tells it to locate its origin or home. This process is known as homing. The tool will move as far as it can in a specified direction until it receives feedback from an endstop. Endstops define the boundaries of the machine and may sometimes be referred to as *limit switches* in many applications.
- Endstop analogy
- Types of endstops
- Wiring and configuration
- M119, Testing the configuration
- Software endstops
- G28, the homing command
How endstops work - an analogy
Imagine you are in a small room and cannot see. You are told to sit in the center of the room. You might wander blindly until you crash into a wall. If you are told that the opposite wall is 5 paces away from the wall you crashed into then you would be able to locate the center of the room when travelling in one direction (our Y axis would be homed). You could then repeat the same process for each direction you wanted to travel in (our X and Z).
The concept of endstops and homing are not new. Many applications make use of these strategies and, often, may have their own terminology. We’ll be sticking to the scope of 3D printers here so let’s quickly cover some terminology and assumptions.
Endstop will be preferred over limit switch or other terms.
Homing will be used in place of other nomenclature.
We will be assuming that the home position of the machine is 0, 0, 0.
We will be assuming a Prusa i3 or similar cartesian printer.
Assume X moving in the positive direction moves the carriage to the right (your right).
Assume Y moving in the positive direction moves the table toward you.
Assume Z moving in the positive direction moves the carriage up.
Code examples and configuration will be using the Marlin firmware.
With these assumptions, a homed machine sent to 0, 0, 0 will have the tool placed at the bottom left corner of the bed with the nozzle close to the table.
To follow along with the examples you should have some way to send commands to the printer. Anything that works with a serial device will work: you can use the Arduino serial monitor, the serial monitor in Cura's advanced interface, the Pronterface serial monitor or even the screen command.
If you don’t have a Prusa i3 style cartesian machine running Marlin you can still use this guide - but keep the assumptions above in mind if something doesn’t make sense! Endstops and homing are generic enough to apply to most machines and they generally work the same way.
Types of endstops
There are many types of endstops. The two most commonly used endstops are mechanical or optical. Other types of endstops include contact or proximity.
Fundamentally, these endstops work the same way: something interacting with the endstop causes it to signal the controller that the endstop has been reached.
Many people prefer mechanical endstops for their cost, simplicity and reliability.
Wiring and modes of operation
Some endstops may come pre-wired. Others may have connectors you need to connect yourself. Endstops will generally have two modes:
NC (Normally Closed)
This configuration means that the switch is closed and the endstop is conducting electricity. A continuous signal is sent back to the controller. When the endstop is triggered this signal will stop.
NO (Normally Open)
When the endstop is triggered it begins conducting electricity.
If you have a choice between NO or NC you should use Normally Closed (NC). This will reduce the chance that any stray electrical noise may inadvertently trigger an endstop and is the default mode for many firmware devices.
If you have the endstop enabled but do not have an endstop present you will want to set it to NO. Otherwise, the controller will believe the endstop is triggered when it is actually absent.
In most configurations, only the MIN endstops are used. In some configurations a printer may use a MAX endstop for Z but a MIN endstop for X.
Let's review Marlin's configuration to make more sense of the above:
The configuration above includes a small comment from the Marlin team about NC configuration. We can see that the X_MAX and X_MIN are both configured for NC operation.
The bottom two lines are both commented out meaning that the machine expects to have MAX and MIN endstops working and connected for each axis.
If our machine does not have an endstop for X at its max (there is no endstop on the right side of the axis) then we would need to toggle X_MAX_ENDSTOP_INVERTING to true so that Marlin does not expect a signal from a Normally Closed switch.
If our machine does not have any MAX endstops then we would uncomment #define DISABLE_MAX_ENDSTOPS to disable all MAX endstops. The same is true for disabling MIN endstops if we have no MIN endstops.
Be careful with this configuration!
Disabling endstops that the machine expects to have can result in possible damage to the machine when it attempts to travel beyond its physical limitations trying to find the endstop!
Troubleshooting: I plugged in an endstop and now my board doesn't work!
Each endstop connector has a +, - and signal pin on most boards. You should check if you have shorted your endstop by wiring it incorrectly.
M119, Testing the configuration
Before trying to home or otherwise use the machin we should test it.
When sent to the printer, M119 gives us the current endstop status.
Immediately after powering up a machine send M119 to it. You should see something similar to the above.
Ensure that the output matches your expected configuration. It is a good idea to try toggling the endstops with your hand, a piece of tape, or by manually moving the axis. Issuing M119 again should show you the new endstop status. Repeat for each axis.
Note that not all of the endstops are listed. Depending on your configuration you may see a subset of endstops like the example above. You might also see every endstop listed.
We can see in the example that the Y_MIN of this printer is currently TRIGGERED.
We know that the X_MAX is configured for NO operation but is not displayed: this is expected and effectively how we disable that endstop. For the machine used in the example this endstop doesn't exist.
We know that both DISABLE_MAX_ENDSTOPS and DISABLE_MIN_ENDSTOPS are commented out since this configuration lists MAX and MIN endstops.
If everything looks correct you can now try to use a simple move command like G1 X5. This should move the X axis to the right. Repeat for each axis being sure to check M119 and to not send the current axis beyond its limit.
Troubleshooting: My axis is going the opposite direction I expect
Double check your endstop configuration.
You may also need to invert the direction of the motor, however, that is not covered in this guide.
Troubleshooting: My axis doesn't move at all
Double check the endstop configuration and review the output of M119. You most likely have an endstop configured in the wrong NO or NC configuration, it is shorted or it is not connected at all.
Troubleshooting: An endstop shows up as TRIGGERED when I have no endstop there
Review your configuration. You most likely have an endstop configured as NC and it is not currently connected.
Marlin also has support for software endstops.
A software endstop tells the machine that it should not attempt to travel beyond a limit defined in software.
For our analogy about the room above, if stumbling into the wall is our mechanical endstop then our knowledge about the opposite wall being +5 away would be a software endstop. Software endstops tell the machine that it should never try to travel more than a certain measured distance from an endstop it previously learned about.
Let's look at Marlin's configuration again:
The configuration above tells the machine that it should never try to travel below 0 or above 200 millimeters.
To put it together, if we have a X_MIN endstop configured then the machine will "know" where 0 is and it should never travel beyond 200 millimeters from there.
Depending on your machine, it may be perfectly normal to have negative MIN positions especially for the X axis. This may happen if the X axis is slightly larger than the bed. The designer may have intentionally wanted a gap between the bed and frame for nozzle cleaning or purging. Z may be configured with a negative MIN to allow for probes and Z height adjustments. Be aware of these features when reconfiguring endstops.
G28, the homing command
G28 is the actual code we'll use to tell the machine to learn about its position.
There is one more piece of configuration we'll review:
This configuration tells the machine where it should go when homing. Negative values mean the machine should seek the minimum of the axis. Positive values go to the maximum of the axis.
In the default above with each HOME_DIR set to -1. The X axis should seek to the left, the Y axis should go away from you and the Z axis should go down.
If we have an X_MIN endstop we might want X_HOME_DIR to be -1. The axis should move to the left as far as it can when homed.
If we have a Z_MAX endstop we might want Z_HOME_DIR to be 1 (positive 1). The axis should go as far up as it can when homed.
If you have an axis that is configured for both endstops then you have an option of which direction you would want it to home to.
Some machines have both MIN and MAX endstops on an axis. Some may not. Having an endstop on an axis in a direction you never home to can prevent the carriage from traveling too far. For many modern machines Software Endstops have replaced using additional endstops to prevent traveling beyond the machine's limit.
If you are confident you have configured your endstops correctly, you have verified M119 and you have configured the correct homing directions then send G28 to the printer. Be sure you have your hand on the trusty power button just in case!
Side note: Why is the home command included in gcode so that it runs every time I print?
During operation, we have no guarantee what state the machine is in before we have started sending gcode to it. G28 is included with each gcode file by slicers to ensure we are correctly homed before attempting to print.
Stepper motors (and other common motion systems) may lose steps by being powered off or simply because of normal errors that happen over time. Homing before each print ensures accurate positioning of the tool.
Side note: Running with no endstops (not recommended)
Although not recommended, you can have a machine with no endstops at all. As long as you can be assured that the tool will always start in the same position you could technically skip homing entirely. The benefits of automatically homing during each print far outweight the risk of mispositions resulting in possible damage to the machine. To ensure accuracy and avoid possible damage you should always perform homing operations.
Endstops can be present in a number of different forms with the most common being a microswitch.
Configurations for specific machines can vary wildly. Regardless, the goal is to let the machine seek its position and potentially avoid damaging itself.
Not all machines have every endstop. Software Endstops can take the place of additional endstops not used during homing.
Misconfiguration may cause damage to your machine. Use M119 to check your endstop status.
Watch G28 carefully. Power off the machine if it does not move in the expected directions.