# Where to define grid for bilinear levelling in Marlin

I'm using firmware Marlin 2.0.3 on an Anet A8 printer. I'm using a Roko SN04-N NPN bed leveller. I've managed to set up 3 points bed levelling but I wanted to try the bilinear levelling.

Issue is, the sensor goes out of the aluminum bed ever so slightly during levelling, resulting in the printing head crashing on the bed.

Where can I set the grid for the bilinear levelling in the config file? I didn't find the option in the file and Google wasn't of any help this time.

• Did you define "Z-probe boundary limits"? Please post your changes to the configuration.h and configuratio_adv.h as in the latter file the boundaries are set in Marlin 2.x; e.g. #define MIN_PROBE_EDGE_LEFT MIN_PROBE_EDGE. Without posting the values, it would be guessing what is wrong. If you used the Anet A8 configuration files from Anet A8 config. you will find that these are incomplete with respect to bed limits, these files require updating! – 0scar Feb 10 '20 at 10:38
• @0scar yes I did and it's ignoring it! This is my configuration.g and this is my configuration_adv.h. I think I got the config for the Anet from the Marlin examples, but I'm not 100%sure. Where should I find a complete setting? – vale.maio2 Feb 10 '20 at 11:11
• No it is not ignoring it, your bed limits are incorrect, I've updated the answer to your specific problem. Basically your left limit is incorrect (too far left), hence the sensor is not on the plate. Hope you can fix it now, happy printing! :-) – 0scar Feb 10 '20 at 14:46

If you have managed to setup 3-point levelling, you should be able to enable bi-linear levelling in the firmware.

From the configuration.h file for Marlin firmware you can find the following options:

/**
* Choose one of the options below to enable G29 Bed Leveling. The parameters
* and behavior of G29 will change depending on your selection.
*
*  If using a Probe for Z Homing, enable Z_SAFE_HOMING also!
*
* - AUTO_BED_LEVELING_3POINT
*   Probe 3 arbitrary points on the bed (that aren't collinear)
*   You specify the XY coordinates of all 3 points.
*   The result is a single tilted plane. Best for a flat bed.
*
* - AUTO_BED_LEVELING_LINEAR
*   Probe several points in a grid.
*   You specify the rectangle and the density of sample points.
*   The result is a single tilted plane. Best for a flat bed.
*
* - AUTO_BED_LEVELING_BILINEAR
*   Probe several points in a grid.
*   You specify the rectangle and the density of sample points.
*   The result is a mesh, best for large or uneven beds.
*
* - AUTO_BED_LEVELING_UBL (Unified Bed Leveling)
*   A comprehensive bed leveling system combining the features and benefits
*   of other systems. UBL also includes integrated Mesh Generation, Mesh
*   Validation and Mesh Editing systems.
*
* - MESH_BED_LEVELING
*   Probe a grid manually
*   The result is a mesh, suitable for large or uneven beds. (See BILINEAR.)
*   For machines without a probe, Mesh Bed Leveling provides a method to perform
*   leveling in steps so you can manually adjust the Z height at each grid-point.
*   With an LCD controller the process is guided step-by-step.
*/
//#define AUTO_BED_LEVELING_3POINT
//#define AUTO_BED_LEVELING_LINEAR
//#define AUTO_BED_LEVELING_BILINEAR
//#define AUTO_BED_LEVELING_UBL
//#define MESH_BED_LEVELING


If you are using 3-point levelling you enabled constant AUTO_BED_LEVELING_3POINT by removing the comment characters (//):

#define AUTO_BED_LEVELING_3POINT


to enable bi-linear levelling, you should remove the comment characters before constant #define AUTO_BED_LEVELING_BILINEAR:

#define AUTO_BED_LEVELING_BILINEAR


Definition of the grid is done by specifying how many point you want to have using constants GRID_MAX_POINTS_X and GRID_MAX_POINTS_Y:

#if EITHER(AUTO_BED_LEVELING_LINEAR, AUTO_BED_LEVELING_BILINEAR)

// Set the number of grid points per dimension.
#define GRID_MAX_POINTS_X 3
#define GRID_MAX_POINTS_Y GRID_MAX_POINTS_X


The code above shows the default definition of a 9 point (3 x 3) grid.

Note that this will only work well if the area for the sensor to reach safely is correctly defined. If the sensor is missing the build plate, you have not correctly defined the limits for the sensor. Question "How to set Z-probe boundary limits in firmware when using automatic bed leveling?" has an accepted answer that describes how to define an area on the plate that the sensor may reach (the answer on this question also discusses Marlin 2.x).

## In the specific case of the OP (after posting the config files)

From the posted configuration files your probe position can be obtained:

#define NOZZLE_TO_PROBE_OFFSET { 25, 55, 0 }


So your probe is at the right-back when facing the printer. Also your bed area attempt (commented) and the current active bed area can be obtained:

#if PROBE_SELECTED && !IS_KINEMATIC
//#define MIN_PROBE_EDGE_LEFT 5
//#define MIN_PROBE_EDGE_RIGHT 200
//#define MIN_PROBE_EDGE_FRONT 55
//#define MIN_PROBE_EDGE_BACK 200
#define MIN_PROBE_EDGE_LEFT MIN_PROBE_EDGE
#define MIN_PROBE_EDGE_RIGHT MIN_PROBE_EDGE
#define MIN_PROBE_EDGE_FRONT MIN_PROBE_EDGE
#define MIN_PROBE_EDGE_BACK MIN_PROBE_EDGE
#endif


From these excerpts it is clear that the bed limits are incorrectly defined.

Following the theory from this answer the probe is only allowed to visit the following (dark red) area:

This area is defined as:

  #define MIN_PROBE_EDGE_LEFT (PROBE_OFFSET_X_FROM_EXTRUDER + MIN_PROBE_EDGE)
#define MIN_PROBE_EDGE_RIGHT (MIN_PROBE_EDGE)
#define MIN_PROBE_EDGE_FRONT (PROBE_OFFSET_Y_FROM_EXTRUDER + MIN_PROBE_EDGE)
#define MIN_PROBE_EDGE_BACK (MIN_PROBE_EDGE)


which translates to:

  #define MIN_PROBE_EDGE_LEFT (25 + MIN_PROBE_EDGE)
#define MIN_PROBE_EDGE_RIGHT (MIN_PROBE_EDGE)
#define MIN_PROBE_EDGE_FRONT (55 + MIN_PROBE_EDGE)
#define MIN_PROBE_EDGE_BACK (MIN_PROBE_EDGE)


As seen in the commented //#define MIN_PROBE_EDGE_LEFT 5 and uncommented #define MIN_PROBE_EDGE_LEFT MIN_PROBE_EDGE (equals 10) left probe limits, you are at least respectively 20  or 15 mm short, hence the sensor is not on the plate on the left.

• I did try that, but the printer is still ignoring probe offset and probing boundaries. I've tried also this bugfix but still probing outside of the bed – vale.maio2 Feb 10 '20 at 10:07
• @vale.maio2 I've updated the answer, from your config files it was clear that the incorrect value for the left boundary was used causing the sensor to be off-plate on the left. – 0scar Feb 10 '20 at 14:50
• thank you very much for your correction, but now when selecting the auto levelling, it just probes the center of the bed and stops there, same when printing something. Unfortunately I have to switch back to 3 points. – vale.maio2 Feb 10 '20 at 15:49
• @vale.maio2 That means that Z_SAFE_HOMING is active, strange that it stops... Look for more information on enabling bi-linear leveling here. Did you also determine the correct Z-offset and set it with M851? – 0scar Feb 10 '20 at 17:03
• yes it's active but it's not an issue with 3 point levelling. I'll have a read at that documentation, but I've also discovered that the bed is absolutely uneven. I need to make it even fist, then even 3 point levelling should suffice. Thank you again for your input. – vale.maio2 Feb 10 '20 at 19:45