Unified Bed Leveling (UBL) - Marlin Firmware
-Working ABL probe (we recommend a Genuine BLTouch)
-Manually Leveled Bed
-Basic Understanding of Arduino IDE and Firmware Flashing (or VS Code if you are using 32-bit controller)
Bed Leveling Methods
There are 5 main types of auto bed leveling currently available at the time of writing this article:
- 3 Point Leveling - Probes 3 points to define a plane (assumes the plate is perfectly flat)
- Linear Leveling - Probes a grid and creates matrix using "least squares" algorithm
- Bilinear Leveling - Probes a grid and creates a mesh to represent imperfections in bed
- Mesh Bed Leveling - Manually creates a mesh using a piece of paper at various points on the bed (no probe required--somewhat tedious process)
- Unified Bed Leveling (UBL) - similar to bilinear leveling except it adds various tools such as matrix editing to fine-tune the probing results. Another great feature is you can save multiple meshes if you have different build plates you use
Enabling UBL in Firmware
In order to utilize UBL, you will first need to enable it in your firmware and re-flash your machine. Using Arduino IDE, go to the "configuration.h" tab and make the following changes highlighted in red:
* Normally G28 leaves leveling disabled on completion. Enable
* this option to have G28 restore the prior leveling state.
#if ANY(MESH_BED_LEVELING, AUTO_BED_LEVELING_BILINEAR, AUTO_BED_LEVELING_UBL)
// Gradually reduce leveling correction until a set height is reached,
// at which point movement will be level to the machine's XY plane.
// The height can be set with M420 Z
#define MESH_TEST_NOZZLE_SIZE 0.4 // (mm) Diameter of primary nozzle.
#define MESH_TEST_LAYER_HEIGHT 0.2 // (mm) Default layer height for the G26 Mesh Validation Tool.
#define MESH_TEST_HOTEND_TEMP 205 // (°C) Default nozzle temperature for the G26 Mesh Validation Tool. #define MESH_TEST_BED_TEMP 60 // (°C) Default bed temperature for the G26 Mesh Validation Tool.
#define G26_XY_FEEDRATE 20 // (mm/s) Feedrate for XY Moves for the G26 Mesh Validation Tool.
//============================================================================ //========================= Unified Bed Leveling ================================= //============================================================================
#define MESH_EDIT_GFX_OVERLAY // Display a graphics overlay while editing the mesh
#define MESH_INSET 35 // Set Mesh bounds as an inset region of the bed
#define GRID_MAX_POINTS_X 10 // Don't use more than 15 points per axis, implementation limited.
#define GRID_MAX_POINTS_Y GRID_MAX_POINTS_X
#define UBL_MESH_EDIT_MOVES_Z // Sophisticated users prefer no movement of nozzle
#define UBL_SAVE_ACTIVE_ON_M500 // Save the currently active mesh in the current slot on M500
//#define UBL_Z_RAISE_WHEN_OFF_MESH 2.5 // When the nozzle is off the mesh, this value is used
// as the Z-Height correction value.
Typical UBL Start G-Code
To make things simple we will show you the typical start code we put in our slicer for UBL. Then we will go through line-by-line so you can understand what each function does and decide if you need to make any changes for your own setup.
Understanding UBL Functions
This function ensures the bed is up to temperature before taking any probing points. This is critical to getting accurate readings as the bed will change shape when heated.
Homes the machine so it knows the location of XYZ "zero." All g-code, unless in relative mode, is based on the home position of 0,0,0 which is determined by the end stop locations.
Runs the automatic probing routine for UBL. There are other options, however, most users with a BLTouch or other ABL device will use G29 P1.
Extrapolates the leveling topology to areas of the bed the probe could not reach. This lets the software make an educated guess on bed topology in the areas it was unable to probe. Without running this command, areas that weren’t probed will be ignored and may lead to an inaccurate first layer. For example, the probe may have only been able to probe the area in green (see below) due to machine limitations and probe position. G29 P3 will use the surrounding in green to fill in the missing mesh data for the areas in red.
Sets fade height to 10mm. The first 10mm of the print will have a variable Z position during the print. This means the nozzle will follow the ups and downs of the build plate on the first layer, however, over the next 10mm this effect will taper off. This allows the rest of the print to have a constant Z which will likely lead to cleaner, more accurate prints. Note: if your bed is not leveled properly, this can result in finished parts that are out of square as shown below. This is why it is vital you still level your bed even with ABL capability.
Saves the bed topology results into slot one. Unlike some of the other bed leveling methods, UBL allows you to save multiple meshes (using S1, S2, S3, etc.) and recall them later. This is very beneficial if you don’t want to run UBL before each print and have multiple build surfaces.
Ensures UBL is activated for the next step
Loads mesh #1 for the current print job. If you have multiple meshes saved in different slots you can also call a different number mesh here. Simply replace the L1 with the appropriate L number.
Saves settings to EEPROM for future use. If you do not save, all data will be lost after powering down the machine.
There are more functions that can be used with UBL, however, these are more than enough to get you up and running. As of writing this article, UBL is the most advanced ABL method available in Marlin Firmware. It offers many tools like the ability to save multiple meshes and manual editing of probe points. In addition, you can recall an existing mesh using G29 L# and then run G29 J afterward which will probe 3 points to tilt the existing mesh to match your build surface in case it has changed since running previously.
Getting a grasp on all of the functions can be intimidating at first but once you get them down it will ensure you get a perfect first layer every time!