Unified Bed Leveling (UBL) - Marlin Firmware

Unified Bed Leveling (UBL) Marlin Firmware
If you are not familiar with automatic bed leveling, it is a way to measure the topology of your build plate and compensate for any imperfections. This will ensure your first layer has a consistent thickness by adjusting the Z axis while printing. Even though your build plate might appear perfectly flat, it actually has high and low spots which can cause issues on your first layer even after doing a "four corner level." 

Unfortunately, most 3D printers today only come with a Z end stop as opposed to a bed leveling probe. The good news is if yours did not come with a leveling probe, they are generally cheap and easy to add using something like the BLTouch or similar.

Prerequisites:

-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:

  1. 3 Point Leveling - Probes 3 points to define a plane (assumes the plate is perfectly flat)
  2. Linear Leveling - Probes a grid and creates matrix using "least squares" algorithm
  3. Bilinear Leveling - Probes a grid and creates a mesh to represent imperfections in bed
  4. Mesh Bed Leveling - Manually creates a mesh using a piece of paper at various points on the bed (no probe required--somewhat tedious process)
  5. 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:

//#define AUTO_BED_LEVELING_3POINT 

//#define AUTO_BED_LEVELING_LINEAR 

//#define AUTO_BED_LEVELING_BILINEAR 

#define AUTO_BED_LEVELING_UBL 

//#define MESH_BED_LEVELING

 

 /** 

   * Normally G28 leaves leveling disabled on completion. Enable 

   * this option to have G28 restore the prior leveling state. 

   */ 

#define RESTORE_LEVELING_AFTER_G28

#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 ENABLE_LEVELING_FADE_HEIGHT

#define G26_MESH_VALIDATION 

#if ENABLED(G26_MESH_VALIDATION) 

   #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. 

#endif

//============================================================================   //========================= 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.


M190 S{material_bed_temperature} 

G28 

G29 P1 

G29 P3 

G29 F10 

G29 S1 

G29 A 

G29 L1 

M500 

Understanding UBL Functions

M190 S{material_bed_temperature}

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.

G28

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.

G29 P1

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.

G29 P3

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.

Unified Bed Leveling (UBL) Marlin Firmware G29 P3

G29 F10

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.

Fade Height Unified Bed Leveling (UBL) Marlin Firmware

G29 S1

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.

G29 A

Ensures UBL is activated for the next step

G29 L1

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.

M500

Saves settings to EEPROM for future use. If you do not save, all data will be lost after powering down the machine.

Summary

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!


-3DMaker Engineering

Recommended Products:

3 comments

  • I just have to say that I really appreciate the graphic you have for explaining fade height. I remember having an awful time trying to figure out what it meant when I installed a bltoutch on my machine. After rereading explanations of fade height many time I eventually got a picture in my head that is exactly like that graphic. Would have been so much easier if I had found this article

    Mendel
  • Can you just use the gcode in you slicer without changing the firmware?

    IDM
  • Can you just use the gcode in you slicer without changing the firmware?

    IDM

Leave a comment

Please note, comments must be approved before they are published