When auto bed leveling is concerned, hardware selection seems to get all the attention. Tuck into this detailed guide of setting up Marlin for auto bed leveling to make sure that that shiny new probe actually works!
One of the more tedious tasks of preparing for a 3D print job is leveling the bed. Manual leveling is no fun, requiring repeated adjustments in close proximity to all the hot parts of a printer. That’s probably why auto bed leveling became such a popular feature so quickly: With this feature, the nozzle always starts at the perfect height across the entire bed automatically, with no manual intervention necessary.
The problem is, if you’re using Marlin firmware, configuring it for auto bed leveling can be a twisted and confusing path.
If you’re unfamiliar with modifying and flashing firmware, we’ve got a solid, in-depth tutorial on the subject. One relevant takeaway is that much of the configuration process has to do with comments:
Down to Business…
The configuration changes will be made in the Configuration.h file of the Marlin firmware. The Marlin package includes a folder of example configurations for many popular 3D printers you can start with.
Disclaimer: Any changes to your firmware can result in unforeseen and unfortunate consequences. Always make a copy of any working configuration. All3DP cannot gauge your level of skill or be responsible for any damage that occurs to your property.
Auto bed leveling in Marlin spans roughly a quarter of Configuration.h and wanders through several sections while skipping others. So in this article, we’ll simulate the code and indicate skips and omissions with a short string of tildes (~~~~~~) to indicate where we’re skipping things for clarity. There can be some extensive gaps between the important sections, but we’ll point out landmarks along the way so you can stay oriented.
Our journey begins about a quarter of the way through Configuration.h under “Endstop Settings”. What we want to do here is set some electrical characteristics of the Z sensor.
Since the microcontrollers typically used for 3D printers have internal pull-up resistors, we probably don’t need to concern ourselves with these “ENDSTOPPULLUP” lines unless you’re having sensing issues. If so, you can try uncommenting those lines.
The “ENDSTOPINVERTING” lines configure whether the triggered sensor sets a high or low signal. The rule of thumb here is if you have an NPN type sensor, set “Z_MIN_PROBE_ENDSTOP_INVERTING” to true, and for a PNP type sensor set both “Z_MIN_PROBE_ENDSTOP_INVERTING” and “Z_MIN_ENDSTOP_INVERTING” to false. For example, a moving pin probe like a BLTouch would be set to false.
If you get any of this wrong, it shouldn’t hurt anything as long as you test that your sensor actually senses proximity before you start moving your bed or extruder assembly.
The Z Probe
We’re going to skip quite a bit until we get to the Z probe options. This is where we define a few more electrical and some mechanical aspects of the sensor.
The next thing we need to indicate is where the probe is connected. If the sensor has its own dedicated port, we would uncomment “Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN” and add the pin number at the end of that line. If it replaces an endstop, then that line would be commented and we would uncomment “Z_MIN_PROBE_ENDSTOP” instead.
If the sensor has no moving parts, then “FIX_MOUNTED_PROBE” is uncommented a bit further down. On the other hand, if your probe has some sort of servo mechanism which swings an arm, the servo port and Deploy and Stow angles are the next option to uncomment and set.
The settings for a BLTouch are nice and easy. Just uncomment the BLTouch line. You don’t have to change the delay unless you’re having issues with the pin getting caught or being inconsistent.
And finally, starting with the probing heaters line, we come to an area that’s for troubleshooting things like vibration issues and configuring somewhat exotic hardware. If you don’t know why you need to go there, you probably shouldn’t.
We’re still under “Probe Options”, but there’s a special landmark to check out next. One of the things we need to examine in Marlin auto bed leveling is some ASCII art that defines how to describe where the nozzle and sensor are in relation to each other. The takeaway here is that if your sensor is in front or to the left of the printer’s nozzle, then the X and Y offset values will be negative.
For the X and Y values, measure from the point of the nozzle to the center of the sensor. Try to be as accurate as possible. Alternatively, you can set Z to zero for now and fill it in later, or leave it at zero and save the value to your controller’s memory after setting the Z offset.
We also need to examine “MIN_PROBE_EDGE 10”. It’s already uncommented, but you will want to check that 10 mm gives you enough clearance from the edge of your bed.
Then we skip a few lines about the speed of probing and how many times the sensor probes a spot. Following that are some default position rest positions, stepper motor and servo defaults, and other defaults that work fine in typical situations. You can adjust these later if you please, but none of it needs to be addressed at this time.
There’s also a repeatability test that you don’t need to keep enabled on your LCD display.
Note: As you go through Configuration.h in your Marlin auto bed leveling journey, examine the comments along the way and decide if they apply to your situation. In most cases, defaults are where you need to be.
From here, we’re skipping things that you shouldn’t have to concern yourself about on a working 3D printer. These are things that define your bed size and whether or not you use software endstops, the size of your bed, and so on. In other words, things that have already been set on your working 3D printer.
When you get to “MIN_SOFTWARE_ENDSTOP_Z”, you’ll want to disable that temporarily. it keeps your nozzle from crashing into the bed but it may keep you from setting the Z offset at all since it won’t let you send the nozzle to a negative value. Uncomment it again after you’ve set your sensor’s Z offset.
And with that, we’re finally out of the probe options. Nothing else concerns us until we get to “Bed Leveling”.
Bed Leveling Settings
Now we set the pattern and protocol for the bed leveling process. You could choose “AUTO_BED_LEVELING_3POINT” or “AUTO_BED_LEVELING_LINEAR” if you’re certain that your bed is absolutely flat with no warps or uneven spots. If you’re not so sure, Marlin auto bed leveling lets you compensate with “AUTO_BED_LEVELING_BILINEAR”. Meanwhile, “AUTO_BED_LEVELING_UBL” is similar but more advanced and lets you create a mesh diagram of the high and low sections of your bed. For most people, linear and bi-linear would be good choices. Mesh bed leveling is a manual process. Be sure to uncomment your method of choice.
The G28 command sets your printer’s carriage to the home position, which is the last thing that happens before printing starts. The problem is that issuing a G28 clears the leveling information that’s been collected. So we must uncomment “#define RESTORE_LEVELING_AFTER_G28”.
After the first layer or two, your bed shouldn’t affect the layers of your model. That’s why “ENABLE_LEVELING_FADE_HEIGHT” is uncommented and a low number value (3 is good) is added at the end.
The “Mesh Validation Tool” is a bed test that prints a grid of squares across your bed. Enabling it puts the option in your LCD display. If you use it, you’ll also have to set the layer height, nozzle diameter and temperature settings for your filament.
Deeper Bed Settings
Next, we define the grid with the number of X and Y points. A 3 x 3 grid is standard for a square bed. You could add a row or column for a rectangular grid. Increasing the number of points increases the program your controller needs and could cause a crash.
Now we set the restrictions for where your our probe is actually able to reach without running over the edge or slamming into something. Each line should be uncommented and the X or Y values for min and max positions entered here.
Since an offset probe can’t make it all the way from front to back or end to end, if you are using bilinear leveling, you’ll probably want to uncomment “EXTRAPOLATE_BEYOND_GRID”. The next section enables a more advanced variation of bilinear probing that you can experiment with if you choose.
There’s not much left to do. If you are using universal bed leveling, things can stay pretty much as they are in that section. Mesh leveling, as stated earlier, is not an automatic process and will be the subject of another article. (Stay tuned!) The only thing left to decide is if you want an auto-leveling option on your LCD menu. If so, then uncomment “#define LCD_BED_LEVELING”.
And so we finish our journey of Marlin auto bed leveling configuration at roughly the half-way point of the Configuration.h file.
Like many things related to Marlin and 3D printers in general, there are a lot of options to account for the variations between printers, probing methods, and probe hardware. But you only need concern yourself with the sections that apply to your situation. If you understand your equipment and make your way carefully through the options while heeding the advice in the comments, configuring Marlin for auto bed leveling is a straightforward task.
Feature image source: David Contreni / All3DP
License: The text of "How to Set Up Marlin for Auto Bed Leveling" by All3DP is licensed under a Creative Commons Attribution 4.0 International License.
Subscribe to updates from All3DP
You are subscribed to updates from All3DP
You can’t subscribe to updates from All3DP. Learn more…