Skip to content

Installing Bed Distance Sensor

Mark edited this page Jul 11, 2024 · 89 revisions

This installation is for the printers running Marlin firmware.

Step1. Attach the sensor cable to the mainboard

the wires CKL and SDA of BDsensor can be connect to any GPIO pins of your mainboard. You can also connect the BDsensor cable into the Bltouch port directly(except the MKS board),for example:

BLtouch    |    BDsensor
 GND      -->     GND
 5V       -->     5V
 S        -->     SCL/CLK
 GND      -->     GND
 Zmin     -->     SDA

Since some of the pins on the mainboard maybe not connected to gpio of MCU directly (e.g. there is a filter capacitor on it or isolated by mosfet, diode or optocoupler, but it's OK if they are isolated by resistors or pullup/pulldown by resistors), they cannot work with BDsensor. and the firmware will report connection error. For example

  • The connectors for FANs and Heaters are isolated by mosfet,
  • The connectors for temperature thermistors and Endstops/Probe in some boards like MKS are normally connected to GND by filtered capacitors,

Please feel free to send me or share your connection picture if you are not sure.

Step2. Mount the BDsensor near to the hot end. STL of mount

https://raw.githubusercontent.com/markniu/Bed_Distance_sensor/new/doc/images/Connection1.jpg

Step3. Configure & flash Marlin firmware

The BDsensor have been integrated to Marlin2.1.x(Since 2022.8.27),

you can download the release version. but now recommend downloading the latest bugfix version: https://github.com/MarlinFirmware/Marlin

What do you need is change the configure file and pins file.

Edit Configuration.h

1. Enable BD_SENSOR

Uncomment

#define BD_SENSOR
#if ENABLED(BD_SENSOR)
  #define BD_SENSOR_PROBE_NO_STOP // Probe bed without stopping at each probe point
  #define BD_SENSOR_CONTACT_PROBE // it uses nozzle collision sensing to probe while homing,this is a new feature.
#endif

Latest marlin:https://github.com/MarlinFirmware/Marlin

Marlin with Nozzle collision sensing: https://github.com/MarlinFirmware/Marlin/pull/27243)

2. Homing with probe

make sure the Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN is disabled and USE_PROBE_FOR_Z_HOMING should be enable like the following

//#define Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN
// Force the use of the probe for Z-axis homing
#define USE_PROBE_FOR_Z_HOMING

3. Slow down the second homing Z speed

#define Z_PROBE_FEEDRATE_SLOW (Z_PROBE_FEEDRATE_FAST / 16)

If you work with the new contact feature: nozzle collision sensing, this value is different and please refer to this https://github.com/MarlinFirmware/Marlin/pull/27243

Edit Configuration_adv.h

#define BABYSTEPPING // enable this for the feature of real time leveling

Edit pins_boardname.h

Configure the pins for the SDA and SCL of the BDsensor in your pins file pins_boardname.h (E.g. pins_PANDA_PI_V29.h) by adding the following 3 lines:

#define  I2C_BD_SDA_PIN    PC6   // Please change to the actual number which the SDA wire is connected to your mainboard
#define  I2C_BD_SCL_PIN    PB2   // Please change to the actual number which the SLK wire is connected to your mainboard
#define  I2C_BD_DELAY  20      // default value is 20, should be in the range [10,30].

if you want to do the auto bed leveling probe (G29) before print like normal BLtouch, Uncomment

#define AUTO_BED_LEVELING_BILINEAR

and edit the value like the following

#define Z_CLEARANCE_DEPLOY_PROBE   0 // Z Clearance for Deploy/Stow
#define Z_CLEARANCE_BETWEEN_PROBES  1 // Z Clearance between probe points
#define Z_CLEARANCE_MULTI_PROBE     1 // Z Clearance between multiple probes

in the Configuration.h

Step4. Compile and Flash

Compile the new marlin firmware and flash the mainboard.

1. Then check the connection by M102 S-1

please check the connection and wire order if it return blank or other string.

Send: M102 S-1
Recv: V1.0 pandapi3d.com

2. Check the Z endstop by M119

Please do not Homing Z until you have checked this step or else the nozzle maybe cashes the printer bed.

Send: M119
Recv: x:open y:open z:open
  • make sure the z motors off/unlock

  • move the z axis down with hand until the nozzle close the bed

  • send M102 S-2, the return value should be 0.00mm and then send M119 again, you can see the z endstop is triggered now.

Send: M119
Recv: x:open y:open z:TRIGGERED
  • If all above steps are right, then you can homing z axis now.

Step5. Calibration

  1. Clean the nozzle,

  2. If the BD_SENSOR_CONTACT_PROBE is enabled please send G28 then G1 Z0 else you need to manually move the Z axis until the nozzle just touches the bed plate,(The BDsensor will use this position as the 0 point,so the z_offset is no needed and we set the value as 0).

  3. Send gcode M102 S-6,then it will move the z axis slowly up 0.1mm everytime until it reach to 3.9mm.done

Check whether the BDsensor has been calibrated successful by M102 S-5 that will return the raw calibration data which stored in the BDsensor.

There is also a Calibrate Tools to do that: https://github.com/markniu/Bed_Distance_sensor/raw/new/marlin/BD_Config_Tool_Marlin.zip

Note

If the first raw calibration data returned by the M102 S-5 is greater than 400, that means the sensor is mounted too high and needs to be remounted close to the bed. If the first raw <100, that means the sensor is mounted too close to the bed.

Make sure that the second data is greater than the first data value by more than 10

Check Accuracy

  • Move the z axis to 1mm after homing then read the distance value from BDsensor by M102 S-2, the returned value should be about 1mm too, e.g. 0.98~1.02mm.
G28
G1 Z1

waiting the toolhead stops then

M102 S-2
  • Check if the zero position is as expected by G1 Z0 after G28, if not please calibrate again.

Step6. Printing

There are 2 ways to do auto bed leveling:

1.Real time leveling at first few layers with M102

we can easily enable or disable this auto level by sending gcode command or and adding gcode in the gcode file.

To enable bed leveling in Cura, add the M102 G-Code right below the G28 (Home All Axes) G-code in the Start G-code section of your printer’s Machine Settings. For example M102 S2 below the G28 , that means it will only do bed leveling below 0.2mm of Z axis height.

Send M102 S0orG28or M18 will disable bedlevel with BDsensor,BTW,this is disabled by default.

M102   S-1     //Read sensor information, and we can use this for connection checking.
M102   S-2     //Read current distance value
M102   S-5     //Read raw Calibrate data
M102   S-6     //Start Calibrate,before that make sure the nozzle is just touched the bed,and then the printer restarted. don't home z axis before this.
M102   S4      //Set the adjustable Z height value,e.g. M102 S4  means it will do adjusting while the Z height <=0.4mm , disable it by M102 S0.

2. Auto Bed Leveling with G29

Another way to do auto bed leveling is like BLtouch with G29,just add a line G29 below G28.

Installation Video

Installation Video from Chris's Basement

Marlin Example Project:

https://drive.google.com/drive/folders/13poitJhHradERgTLGtSDJb0zpuyNYHZY?usp=sharing

Note

  • If the first raw calibration data returned by the M102 S-5 is greater than 400, that means the sensor is mounted too high and needs to be remounted > > closer to the bed, the recommend value of first data is 100. also make sure that the value of second data is greater than the first data by more than 10
    • FAQ: if calibration data begins with 1 and second value is 9 and third 24 what that means?
    • that means the resolution between 0-0.1mm is only 9,and the 0.1-0.2mm is 15.so recommend to calibrate again let the first resolution 0-0.1mm > bigger than 10