Skip to content
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 14 additions & 14 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@ it can measure the bed distance at any point in real time without moving the z a
Faster leveling, realtime compensation, high accuracy.

1. No need to do probe points before every print, it will be automatically compensated for based on actual distance in real time.

2. You can do bed mesh leveling like a normal proximity sensor but much faster with this BDsensor.

3. Easy manual bed level adjustment thanks to ability to display the live sensor distance measurement on your screen.

Sensor type: inductive, eddy, can only measure the metal plate.
Expand All @@ -24,8 +24,8 @@ Range: 4mm (for different metal the range should be different, the normal pei st
* Support high temperature chamber(120C) with the long cable probe [BDsensorM](https://github.com/markniu/Bed_Distance_sensor/wiki/BDsensor-M).
### Hardware Version
. | hardware | firmware/software
--- | --- |---
2022.6 | BDsensor VA, V1.0 | V1.0
--- | --- |---
2022.6 | BDsensor VA, V1.0 | V1.0
2023.4 | BDsensor VB, V1.1, the connector was changed | V1.1, support self reboot
2023.11 | BDsensor VB, V1.3, Upgrade the MCU to STM32 | V1.2, for stm32
2024.2 | |V1.2c, [Support nozzle collision sensing](https://github.com/markniu/Bed_Distance_sensor/wiki/Collision-sensing)
Expand All @@ -35,15 +35,15 @@ Range: 4mm (for different metal the range should be different, the normal pei st

### Software
. | Marlin | Klipper
--- | --- |---
Real Time leveling |:heavy_check_mark:| :heavy_check_mark:
Fast bed mesh |:heavy_check_mark:| :heavy_check_mark:
Fast bed mesh(No toolhead stop)|:heavy_check_mark: | :heavy_check_mark:
Distance display |:heavy_check_mark: | :heavy_check_mark:
Can bus toolhead|No | :heavy_check_mark:
standby mode automatic while printing|:heavy_check_mark: | :heavy_check_mark:
[KAMP](https://github.com/kyleisah/Klipper-Adaptive-Meshing-Purging) Adaptive Meshing & Purging |No | :heavy_check_mark:
nozzle collision sensing|[Detail](https://github.com/markniu/Bed_Distance_sensor/wiki/Collision-sensing-for-Marlin):heavy_check_mark: | :heavy_check_mark:
--- | --- |---
Real Time leveling |:heavy_check_mark:| :heavy_check_mark:
Fast bed mesh |:heavy_check_mark:| :heavy_check_mark:
Fast bed mesh(No toolhead stop)|:heavy_check_mark: | :heavy_check_mark:
Distance display |:heavy_check_mark: | :heavy_check_mark:
Can bus toolhead|No | :heavy_check_mark:
standby mode automatic while printing|:heavy_check_mark: | :heavy_check_mark:
[KAMP](https://github.com/kyleisah/Klipper-Adaptive-Meshing-Purging) Adaptive Meshing & Purging |No | :heavy_check_mark:
nozzle collision sensing|[Detail](https://github.com/markniu/Bed_Distance_sensor/wiki/Collision-sensing-for-Marlin):heavy_check_mark: | :heavy_check_mark:

### Benefit of Collision sensing
1. **Auto z offset calibration**.
Expand All @@ -70,5 +70,5 @@ nozzle collision sensing|[Detail](https://github.com/markniu/Bed_Distance_sensor
#### Where to buy:
[pandapi3d.com](https://www.pandapi3d.com) , [elecrow](https://www.elecrow.com/bd-sensor.html) , [淘宝店](https://item.taobao.com/item.htm?spm=a1z10.1-c.w4004-14344044600.5.60a16ff77NRBL5&id=684572042388)



70 changes: 35 additions & 35 deletions ardunio/bdsensor_mega328p/Panda_segmentBed_I2C.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ int delay_time=100;
void I2C_SegmentBED::setLow(unsigned char pin) {
noInterrupts();
pinMode(pin, OUTPUT);
// if (_pullup)
// if (_pullup)
digitalWrite(pin, LOW);


interrupts();
}
Expand All @@ -25,7 +25,7 @@ void I2C_SegmentBED::setHigh(unsigned char pin) {
// digitalWrite(pin,1);
// return;
noInterrupts();
//if (_pullup)
//if (_pullup)
pinMode(pin, INPUT_PULLUP);
// else
// pinMode(pin, INPUT);
Expand All @@ -50,7 +50,7 @@ int I2C_SegmentBED::i2c_init(unsigned char _sda,unsigned char _scl,unsigned cha
}

// Start transfer function: <addr> is the 8-bit I2C address (including the R/W
// bit).
// bit).
// Return: true if the slave replies with an "acknowledge", false otherwise

bool I2C_SegmentBED::i2c_start(unsigned char addr) {
Expand All @@ -71,7 +71,7 @@ bool I2C_SegmentBED::i2c_start(unsigned char addr) {
}
*/
// Repeated start function: After having claimed the bus with a start condition,
// you can address another or the same chip again without an intervening
// you can address another or the same chip again without an intervening
// stop condition.
// Return: true if the slave replies with an "acknowledge", false otherwise
bool I2C_SegmentBED::i2c_rep_start(unsigned char addr) {
Expand All @@ -97,7 +97,7 @@ void I2C_SegmentBED::i2c_stop(void) {
// Return: true if the slave replies with an "acknowledge", false otherwise
bool I2C_SegmentBED::i2c_write(unsigned char value) {
for (unsigned char curr = 0X80; curr != 0; curr >>= 1) {
if (curr & value) {setHigh(I2C_BED_SDA);} else setLow(I2C_BED_SDA);
if (curr & value) {setHigh(I2C_BED_SDA);} else setLow(I2C_BED_SDA);
setHigh(I2C_BED_SCL);
delayMicroseconds(delay_time);
setLow(I2C_BED_SCL);
Expand All @@ -109,13 +109,13 @@ bool I2C_SegmentBED::i2c_write(unsigned char value) {
delayMicroseconds(delay_time);
unsigned char ack = digitalRead(I2C_BED_SDA);
setLow(I2C_BED_SCL);
delayMicroseconds(delay_time);
delayMicroseconds(delay_time);
setLow(I2C_BED_SDA);
return ack == 0;
}

// Read one byte. If <last> is true, we send a NAK after having received
// the byte in order to terminate the read sequence.
// Read one byte. If <last> is true, we send a NAK after having received
// the byte in order to terminate the read sequence.
unsigned char I2C_SegmentBED::i2c_read(bool last) {
unsigned char b = 0;
setHigh(I2C_BED_SDA);
Expand All @@ -131,7 +131,7 @@ unsigned char I2C_SegmentBED::i2c_read(bool last) {
setHigh(I2C_BED_SCL);
delayMicroseconds(delay_time);
setLow(I2C_BED_SCL);
delayMicroseconds(delay_time);
delayMicroseconds(delay_time);
setLow(I2C_BED_SDA);
return b;
}
Expand All @@ -154,13 +154,13 @@ void I2C_SegmentBED::I2C_send_str(char *dat_r,char send_now)
}
i2c_stop();
}


}

void I2C_SegmentBED::I2C_read_str(char *dat_r,int addr)
{
i2c_stop();
i2c_stop();
if(i2c_start((I2C_7BITADDR<<1)|I2C_WRITE))
{
int i =0;
Expand All @@ -174,32 +174,32 @@ void I2C_SegmentBED::I2C_read_str(char *dat_r,int addr)
i++;
}
i2c_read(true);

}
i2c_stop();
}
////////////////////////////

unsigned short I2C_SegmentBED::BD_Add_OddEven(unsigned short byte)
{
unsigned char i;
unsigned char n;
unsigned short r;
unsigned char n;
unsigned short r;
n =0;
for(i=0;i<10;i++)
{
if(((byte >>i)&0x01) == 0x01)
{
n++;
}
}
}
if((n&0x01) == 0x01)
{
r = byte | 0x400;
r = byte | 0x400;
}
else
{
r = byte | 0x00;
r = byte | 0x00;
}
return r;
}
Expand All @@ -212,26 +212,26 @@ unsigned short I2C_SegmentBED::BD_Add_OddEven(unsigned short byte)
unsigned short I2C_SegmentBED::BD_Check_OddEven(unsigned short byte)
{
unsigned char i;
unsigned char n;
unsigned char r;
unsigned char n;
unsigned char r;
n =0;
for(i=0;i<10;i++)
for(i=0;i<10;i++)
{
if(((byte >>i)&0x01) == 0x01)
{
n++;
}
n++;
}
}
if((byte>>10) == (n&0x01))
if((byte>>10) == (n&0x01))
{
r = BYTE_CHECK_OK;
r = BYTE_CHECK_OK;
}
else
{
r = BYTE_CHECK_ERR;
r = BYTE_CHECK_ERR;
}
return r;
}
}

void I2C_SegmentBED::BD_setLow(unsigned char pin) {
noInterrupts();
Expand Down Expand Up @@ -279,7 +279,7 @@ void I2C_SegmentBED::BD_i2c_stop(void) {

unsigned short I2C_SegmentBED::BD_i2c_read(void)
{

BD_I2C_start();
//// read
BD_setHigh(I2C_BED_SDA);
Expand Down Expand Up @@ -309,7 +309,7 @@ unsigned short I2C_SegmentBED::BD_i2c_read(void)

void I2C_SegmentBED::BD_i2c_write(unsigned int addr)
{

BD_I2C_start();
//// write
BD_setLow(I2C_BED_SDA);
Expand All @@ -319,17 +319,17 @@ void I2C_SegmentBED::BD_i2c_write(unsigned int addr)
addr=BD_Add_OddEven(addr);
///write address
delayMicroseconds(delay_time);
for (int i=10; i >=0; i--)
for (int i=10; i >=0; i--)
{
if ((addr>>i)&0x01) {BD_set_force_High(I2C_BED_SDA);} else BD_setLow(I2C_BED_SDA);
//if (addr &curr) {set_force_High(I2C_BED_SDA);} else setLow(I2C_BED_SDA);
if ((addr>>i)&0x01) {BD_set_force_High(I2C_BED_SDA);} else BD_setLow(I2C_BED_SDA);
//if (addr &curr) {set_force_High(I2C_BED_SDA);} else setLow(I2C_BED_SDA);
BD_set_force_High(I2C_BED_SCL);
delayMicroseconds(delay_time);
BD_setLow(I2C_BED_SCL);
delayMicroseconds(delay_time);
}
////////////
BD_i2c_stop();


}
6 changes: 3 additions & 3 deletions ardunio/bdsensor_mega328p/Panda_segmentBed_I2C.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
//
//
#ifndef Panda_segmentBed_I2C_h
#define Panda_segmentBed_I2C_h

Expand All @@ -9,13 +9,13 @@
#define I2C_MAXWAIT 5000
//#define I2C_7BITADDR 0x3C// DS1307
#define MEMLOC 0x0A
#define ADDRLEN 1
#define ADDRLEN 1

class I2C_SegmentBED{
public:
int i2c_init(unsigned char _sda,unsigned char _scl,unsigned char _addr,int delay_m);
void I2C_read_str(char *dat_r,int addr);
void I2C_send_str(char *dat_r,char send_now);
void I2C_send_str(char *dat_r,char send_now);
//////////////////////
void BD_i2c_write(unsigned int addr);
unsigned short BD_i2c_read(void);
Expand Down
22 changes: 11 additions & 11 deletions ardunio/bdsensor_mega328p/bdsensor_mega328p.ino
Original file line number Diff line number Diff line change
Expand Up @@ -9,28 +9,28 @@
#endif

I2C_SegmentBED BD_SENSOR_I2C;
#define I2C_BED_SDA 12
#define I2C_BED_SCL 11
#define I2C_BED_SDA 12
#define I2C_BED_SCL 11
#define DELAY 100
#define MAX_BD_HEIGHT 6.9
#define CMD_START_READ_CALIBRATE_DATA 1017
#define CMD_END_READ_CALIBRATE_DATA 1018
#define CMD_START_CALIBRATE 1019
#define CMD_END_CALIBRATE 1021
#define CMD_END_CALIBRATE 1021
#define CMD_READ_VERSION 1016
#define CMD_DISTANCD_RAWDATA_TYPE 1020 // switch output distance data type to raw data, default is mm (1 represent 0.01mm)

char tmp_1[50];
unsigned int n=0,i=0;
float Distance=0.0;

U8G2_SSD1306_128X32_UNIVISION_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE);
U8G2_SSD1306_128X32_UNIVISION_F_SW_I2C u8g2(U8G2_R0, /* clock=*/ SCL, /* data=*/ SDA, /* reset=*/ U8X8_PIN_NONE);



void dis_text(char *tmp_d,char x,char y)
{

u8g2.setFont(u8g2_font_ncenB08_tr); // choose a suitable font
u8g2.drawStr(x,y,tmp_d); // write something to the internal memory
u8g2.sendBuffer(); // transfer internal memory to the display
Expand All @@ -40,7 +40,7 @@ void dis_text(char *tmp_d,char x,char y)
unsigned short read_one_data()
{
unsigned short tmp=0;
tmp=BD_SENSOR_I2C.BD_i2c_read();
tmp=BD_SENSOR_I2C.BD_i2c_read();
if(BD_SENSOR_I2C.BD_Check_OddEven(tmp)==0)
//printf("CRC error!\n");
// sprintf(tmp_1,"CRC error");
Expand Down Expand Up @@ -83,21 +83,21 @@ void setup(void) {
read_version(tmp_1+strlen(tmp_1));
dis_text(tmp_1,0,10);
///

}

void loop(void) {
u8g2.clearBuffer();
u8g2.clearBuffer();
u8g2.setFont(u8g2_font_ncenB08_tr); // choose a suitable font
//u8g2.drawStr(x,y,tmp_d); // write something to the internal memory
//u8g2.sendBuffer();
//u8g2.sendBuffer();

sprintf(tmp_1,"");
read_version(tmp_1+strlen(tmp_1));
//dis_text(tmp_1,0,10);
u8g2.drawStr(0,10,tmp_1);
//delay(10);

//delay(10);
//read and display raw data
n=read_raw_data();
sprintf(tmp_1,"%d ",n);
Expand Down
2 changes: 1 addition & 1 deletion ardunio/esp32_vscode/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ Arduino testing code

This is a simple arduino testing code. It read the distance data from BDsensor after initial the communication port.

If you want to do more code by yourself for other application here is the protocol of data
If you want to do more code by yourself for other application here is the protocol of data

https://github.com/markniu/Bed_Distance_sensor/wiki/Data-Protocol

2 changes: 1 addition & 1 deletion ardunio/esp32_vscode/platformio.ini
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
platform = espressif32
board = esp32dev
framework = arduino
lib_deps =
lib_deps =
markyue/Panda_SoftMasterI2C


Loading