Skip to main content

Installation BDsensor

Connect the sensor cable to the motherboard or CAN bus toolhead board.

  • Please note that SB2040 cannot use Bdsensor

  • Please note that SHT36 needs to connect the Bdsensor's CLK/SCL (Input) to the high voltage input port and connect the jumper

  • The Bdsensor's CLK and SDA lines can be connected to any GPIO pin on the circuit board. You can also directly connect the BD sensor cable to the Bltouch port, for example:

    BLtouch    |    BDsensor
    5V --> 5V
    GND --> GND
    S --> CLK/SCL (Input)
    GND --> GND
    Zmin --> SDA (Input/Output)
  • Due to some pins in the motherboard connector may not be directly connected to the MCU's gpios (for example, they may have filter capacitors or are isolated through MOSFETs, diodes, or optocouplers, but if they are isolated through resistors or resistor pull-ups/downs), they cannot be used with Bdsensor. And the firmware will report a connection error. For example

  • The connectors for fans and heaters are isolated through MOSFETs,

  • In some boards, the connectors for temperature thermistors and endstops/probes are usually connected to GND through filter capacitors,

  1. As shown below, install the BD sensor near the hot end. STL of mount, STL_mount_VzBot_Goliath short

Install the patch into Marlin firmware

BDsensor has been integrated into Marlin2.1.x (since August 27, 2022),

You can download the release version. But now it is recommended to download the latest bugfix version: https://github.com/MarlinFirmware/Marlin

What you need is to modify the configuration file and the pin file.

Edit Configuration.h

  1. Enable BD_SENSOR

    Uncomment

    #define BD_SENSOR`
    `#define Z_SAFE_HOMING
    #define BD_SENSOR_PROBE_NO_STOP //adding this new line for fast bed leveling without nozzle stop,

    Only BD_SENSOR_PROBE_NO_STOP

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

    Description: https://github.com/MarlinFirmware/Marlin/pull/25847

  2. Use the probe for homing

    Make sure Z_MIN_PROBE_USES_Z_MIN_ENDSTOP_PIN is disabled, and enable USE_PROBE_FOR_Z_HOMING as follows:

    //#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)

    Here, we must slow down the bump homing speed and Z homing speed because the stopper read from the BDsensor process is not real-time like normal stoppers.

Edit Configuration_adv.h

Enable this feature #define BABYSTEPPING to enable real-time leveling function

#define HOMING_BUMP_DIVISOR { 2, 2, 8 }       // Re-Bump Speed Divisor (Divides the Homing Feedrate)

Edit pins_boardname.h

By adding the following 3 lines in the pin file pins_boardname.h, configure the SDA and SCL pins for BDsensor (for example): pins_PANDA_PI_V29.h

#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 [20,50].

If you want to perform automatic bed leveling probe before printing (G29) like a normal BLtouch, uncomment

#define AUTO_BED_LEVELING_BILINEAR

And edit the values as follows

#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

Display BD Sensor Values on LCD Screen

  • For printers with status display (support gcode M117), such as LCD12864 or some uart screens, such as ender3V2 ...

Calibration

  1. Clean the nozzle, then move the Z-axis via console until the nozzle just touches the bed (BDsensor will use this position as zero point, so no z_offset, set the value to 0).

  2. Send gcode command M102 S-6, the printer will slowly move the Z-axis up by 0.1mm each time until it reaches 4mm. Do not run M102 S-6 before installing the sensor, and do not turn off the power during calibration, otherwise the old calibration data will be deleted. If this happens, just recalibrate.

  3. You can send M102 S-5 to check if the BD sensor is calibrated successfully, which will return the original calibration data stored in the BD sensor.

There is also a calibration tool that can do this: https://github.com/markniu/Bed_Distance_sensor/raw/new/marlin/BD_Config_Tool_Marlin.zip img

Note: Data value 1015 or > 1010 indicates out of sensor range. If the first five points (0~0.5mm) or more values are within 0 to 1000 range and the increased value delta is >=10, then calibration is successful. Just like the chart shown above.

If the first original calibration data returned by M102 S-5 is greater than 400, it means the sensor is installed too high and needs to be reinstalled closer to the bed. Also ensure the second data value is more than 10 higher than the first value.

Testing and Printing

Menu Bed Level

Automatic Bed Leveling

There are two ways to automatically level the bed:

1. Use M102 to level the first few layers in real time

We can easily enable or disable this automatic leveling by sending gcode commands or adding gcode in the gcode file.

To enable bed leveling in Klipper, add the M28 G code below the "Startup G Code" section in the printer machine settings. For example, below G28, this means it will only perform bed leveling at Z-axis heights below 0.2mm. M102 S2

Send or use BD sensor to disable bed leveling, by the way, it is disabled by default. M102 S0``G28``M18

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-level the bed using G29

Another way to auto-level the bed is like G29 for BLtouch, just add one line below G29.

Installation video

Installation video by Chris Basement

Check Z Endstop M119

Before checking this step, do not home Z, otherwise the nozzle may crash into the print bed.

This is the return message after sending the M119 command (report endstop status).

Send: M119
Recv: x:open y:open z:open

If z min is not open, check your configuration. #define Z_MAX_ENDSTOP_HIT_STATE HIGH

  • Ensure the Z motor is off/unlocked
  • Manually move the Z-axis down until the nozzle closes the bed
  • Send M102 S-2, the return value should be 0.00mm, then send M119 again, you can see the z endstop is now triggered.
Send: M119
Recv: x:open y:open z:TRIGGERED

Check Connection

Check the connection through M102 S-1. This is an example of the return message, please check if the connection and wire order return blank or other strings.

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

If all the above steps are correct, you can now home the Z axis.