简介
TMF8801 是一个飞行时间 (ToF) 激光测距传感器,通过测量光波的脉冲差测量距离。无论物体的颜色、反射率和纹理如何,它都能提供物体的单区域检测。
TMF8801提供 2 – 250 cm 距离的高动态范围测量,能够在 ±5% 范围内进行高精度距离测量,并且能够在黑暗环境和有阳光的情况下运行。
TMF8801内置直方图提供动态盖板玻璃校准和串扰补偿,并且通过片上阳光抑制滤波器将背景光噪声降至最低。
TMF8801通过I2C 快速模式通信接口和一个集成微控制器,所有算法都包含在片上,无需外部光学器件。
特色
- 21º FOI,探测中心最近的物体
- 在测量(精度)的5%以内,不受阳光或黑暗环境影响,没有像iToF那样的多路径和多对象问题
- 20 – 2500mm 距离检测
- 内置直方图,补偿玻璃污垢
- 940nm VCSEL 1 类人眼安全
- 低功耗,940μA功耗10Hz(接近模式)、60Hz运行时的26mA功耗(距离和接近模式)、0.26μA断电电流消耗(EN=0)
适用场景:
- 3D人脸识别
- 接近检测
- 存在检测
- 物体检测
- 距离测量
- 避免碰撞
技术规格
- 工作电压:2.7~3.3V
- 工作电流:<1.5mA
- 接近检测距离:20-100mm
- 距离检测距离:100-2500mm
- 工作温度:-30—60℃
- 通信接口:Breakout 2.54mm-8Pin I2C
- 外形尺寸:21*14.5mm
- 安装孔尺寸:2.0mm
- 安装孔间距:17mm
引脚说明
名称 | 功能描述 |
---|---|
VCC | 电源正极 |
GND | 电源负极 |
SCL | 时钟线 |
SDA | 数据线 |
INT | 报警中断 |
EN | 复位 |
PIN0 | 中断输出引脚0 |
PIN1 | 中断输出引脚1 |
使用教程
准备
-
硬件
- 1 x Arduino UNO控制板
- 1 x TMF8701传感器
- 若干 杜邦线
-
软件
- Arduino IDE, 点击下载Arduino IDE
- TMF8x01库文件和示例程序。
关于如何安装库文件,点击链接
-
主要API接口函数列表
int begin();
/**
* @brief sleep sensor by software, the sensor enter sleep mode(bootloader). Need to call wakeup function to wakeup sensor to enter APP0
*/
void sleep();
/**
* @brief wakeup device from sleep mode, it will running app0
* @return enter app0 return true, or return false.
*/
bool wakeup();
/**
* @brief get a unique number of sensor .Each sensor has a unique identifier.
* @return return 4bytes unique number:
* @n the byte0 of return: serial_number_0
* @n the byte1 of return: serial_number_1
* @n the byte2 of return: identification_number_1
* @n the byte2 of return: identification_number_0
*/
uint32_t getUniqueID();
/**
* @brief get sensor's model.
* @return return a String:
* @n TMF8801: the sensor is TMF8801
* @n TMF8701: the sensor is TMF8701
* @n unknown : unknown device
*/
String getSensorModel();
/**
* @brief get software version of patch.
* @return return string of device software version,format:
* @n major.minor.patch numbers.chip id version
*/
String getSoftwareVersion();
/**
* @brief Get 14 bytes of calibration data.
* @param data Cache for storing calibration data
* @param len The bytes of calibration data,its value can only be 14 bytes
* @return Vail data return true, or return false.
*/
bool getCalibrationData(uint8_t *data, uint8_t len = SENSOR_MTF8x01_CALIBRATION_SIZE);
/**
* @brief set 14 bytes of calibration data.
* @param data Pointer to calibration data.
* @param len The bytes of calibration data,its value can only be 14 bytes
* @return set sucess return true, or return false.
*/
bool setCalibrationData(uint8_t *data, uint8_t len = SENSOR_MTF8x01_CALIBRATION_SIZE);
/**
* @brief disable measurement config. Need to call startMeasurement before using this function.
*/
void stopMeasurement();
/**
* @brief Waiting for data ready.
* @return if data is valid, return true, or return false.
*/
bool isDataReady();
/**
* @brief get distance, unit mm. Before using this function, you need to call isDataReady().
* @return return distance value, unit mm.
*/
uint16_t getDistance_mm();
/**
* @brief enable INT pin. If you call this function,which will report a interrupt
* @n signal to host by INT pin when measure data is ready.
*/
void enableIntPin();
/**
* @brief disable INT pin.
*/
void disableIntPin();
/**
* @brief power on sensor when power down sensor by EN pin.
* @return sucess return True, or return False
*/
bool powerOn();
/**
* @brief power down sensor by EN pin.
* @return sucess return True, or return False
*/
bool powerDown();
/**
* @brief get I2C address.
* @return return 7 bits I2C address
*/
uint8_t getI2CAddress();
/**
* @brief Config the pin of sensor.
* @param pin: The pin of sensor, example PIN0 and PIN1,which is an enumerated variable of ePin_t.
* @n ePIN0: The PIN0 of sensor config.
* @n ePIN1: The PIN1 of sensor.
* @n eGPIOTotal: both of PIN0 and PIN1.
* @param config: The config of pin, which is an enumerated variable of ePinControl_t.
*/
void pinConfig(ePin_t pin, ePinControl_t config);
接线图
样例代码1 - 距离检测
/*!
* @file getDistance.ino
* @brief Get measurement data by PROXIMITY and DISTANCE hybrid mode.
* @n note: TMF8801 only suport one mode, PROXIMITY and DISTANCE hybrid mode.
* *
* Ranging mode configuration table:
* --------------------------------------------------------------------------------|
* | Type | suport ranging mode | ranging ranges | Accuracy |
* |---------------------------------------|-----------------|---------------------|
* | TMF8801 | PROXIMITY and DISTANCE | | 20~100mm: +/-15mm |
* | | hybrid mode(only one) | 20~240cm | 100~200mm: +/-10mm |
* | | | | >=200: +/-%5 |
* |---------------------------------------|-----------------|---------------------|
* | | PROXIMITY mode | 0~10cm | |
* | |---------------------------|-----------------| >=200: +/-%5 |
* | TMF8701 | DISTANCE mode | 10~60cm | 100~200mm: +/-10mm |
* | |---------------------------|-----------------| |
* | | PROXIMITY and DISTANCE | 0~60cm | |
* | | hybrid mode | | |
* |---------------------------------------|-----------------|----------------------
* *
* @n hardware conneted table:
* ------------------------------------------
* | TMF8x01 | MCU |
* |-----------------------------------------|
* | I2C | I2C Interface |
* |-----------------------------------------|
* | EN | not connected, floating |
* |-----------------------------------------|
* | INT | not connected, floating |
* |-----------------------------------------|
* | PIN0 | not connected, floating |
* |-----------------------------------------|
* | PIN1 | not connected, floating |
* |-----------------------------------------|
*
* @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
* @licence The MIT License (MIT)
* @author [Arya](xue.peng@dfrobot.com)
* @version V1.0
* @data 2021-03-26
* @get from https://www.dfrobot.com
* @url https://github.com/DFRobot/DFRobot_TMF8x01
*/
#include "DFRobot_TMF8x01.h"
#define EN -1 //EN pin of of TMF8x01 module is floating, not used in this demo
#define INT -1 //INT pin of of TMF8x01 module is floating, not used in this demo
DFRobot_TMF8801 tof(/*enPin =*/EN,/*intPin=*/INT);
//DFRobot_TMF8701 tof(/*enPin =*/EN,/*intPin=*/INT);
uint8_t caliDataBuf[14] = {0x41,0x57,0x01,0xFD,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04};//The 14 bytes calibration data which you can get by calibration.ino demo.
void setup() {
Serial.begin(115200); //Serial Initialization
while(!Serial){ //Wait for serial port to connect. Needed for native USB port only
}
Serial.print("Initialization ranging sensor TMF8x01......");
while(tof.begin() != 0){ //Initialization sensor,sucess return 0, fail return -1
Serial.println("failed.");
delay(1000);
}
Serial.println("done.");
Serial.print("Software Version: ");
Serial.println(tof.getSoftwareVersion());
Serial.print("Unique ID: ");
Serial.println(tof.getUniqueID(),HEX);
Serial.print("Model: ");
Serial.println(tof.getSensorModel());
tof.setCalibrationData(caliDataBuf, sizeof(caliDataBuf)); //Set calibration data.
/**
* @brief Config measurement params to enable measurement. Need to call stopMeasurement to stop ranging action.
* @param cailbMode: Is an enumerated variable of eCalibModeConfig_t, which is to config measurement cailibration mode.
* @n eModeNoCalib : Measuring without any calibration data.
* @n eModeCalib : Measuring with calibration data.
* @n eModeCalibAndAlgoState : Measuring with calibration and algorithm state.
* @param disMode : the ranging mode of TMF8701 sensor.(this mode only TMF8701 support)
* @n ePROXIMITY: Raing in PROXIMITY mode,ranging range 0~10cm
* @n eDISTANCE: Raing in distance mode,ranging range 10~60cm
* @n eCOMBINE: Raing in PROXIMITY and DISTANCE hybrid mode,ranging range 0~60cm
*/
tof.startMeasurement(/*cailbMode =*/tof.eModeCalib); //Enable measuring with Calibration data.
//tof.startMeasurement(/*cailbMode =*/tof.eModeCalib, /*disMode =*/tof.ePROXIMITY); //only support TMF8701
}
void loop() {
if (tof.isDataReady()) { //Is check measuring data vaild, if vaild that print measurement data to USB Serial COM.
Serial.print("Distance = ");
Serial.print(tof.getDistance_mm()); //Print measurement data to USB Serial COM, unit mm, in eCOMBINE mode.
Serial.println(" mm");
}
}
结果
可以测量0-2500mm
超出测量范围显示0mm
注意:0-20mm以及240cm-250cm的测量数据可能不准确
样例代码2 - 中断输出
你可以把TMF8x01的INT引脚连接到MCU外部中断引脚。
当传感器有数据时,INT引脚将会产生一个低电平信号,MCU通过检测低电平可以判断是否有数据到来
/*!
* @file interrupt.ino
* @brief If you enable INT pin, MCU will capture a interrupt signal when the measure is completed.
* @n You can attach the INT pin of TMF8x01 to MCU external interrupt pin.
* @n 当传感器有数据时,INT引脚将会产生一个低电平信号,MCU通过检测低电平可以判断是否有数据到来
* *
* Ranging mode configuration table:
* TMF8X01_MODE_PROXIMITY: PROXIMITY mode
* TMF8X01_MODE_DISTANCE: DISTANCE mode
* TMF8X01_MODE_COMBINE: PROXIMITY and DISTANCE hybrid mode
* default mode: TMF8X01_MODE_COMBINE
* --------------------------------------------------------------------------------|
* | Type | suport ranging mode | ranging ranges | Accuracy |
* |---------------------------------------|-----------------|---------------------|
* | TMF8801 | PROXIMITY and DISTANCE | | 20~100mm: +/-15mm |
* | | hybrid mode(only one) | 20~240cm | 100~200mm: +/-10mm |
* | | | | >=200: +/-%5 |
* |---------------------------------------|-----------------|---------------------|
* | | PROXIMITY mode | 0~10cm | |
* | |---------------------------|-----------------| >=200: +/-%5 |
* | TMF8701 | DISTANCE mode | 10~60cm | 100~200mm: +/-10mm |
* | |---------------------------|-----------------| |
* | | PROXIMITY and DISTANCE | 0~60cm | |
* | | hybrid mode | | |
* |---------------------------------------|-----------------|----------------------
* *
* @n hardware conneted table:
* -------------------------------------------------------
* | TMF8x01 | MCU |
* |------------------------------------------------------|
* | I2C | I2C Interface |
* |------------------------------------------------------|
* | EN | not connected, floating |
* |------------------------------------------------------|
* | INT | to the external interrupt pin of MCU |
* |------------------------------------------------------|
* | PIN0 | not connected, floating |
* |------------------------------------------------------|
* | PIN1 | not connected, floating |
* |------------------------------------------------------|
*
* @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
* @licence The MIT License (MIT)
* @author [Arya](xue.peng@dfrobot.com)
* @version V1.0
* @data 2021-03-26
* @get from https://www.dfrobot.com
* @url https://github.com/DFRobot/DFRobot_TMF8x01
*/
#include "DFRobot_TMF8x01.h"
#define EN -1 //EN pin of of TMF8x01 module is floating, not used in this demo
#define INT 2 //connected INT pin of module1 to the external interrupt pin of MCU
DFRobot_TMF8701 tmf8x01(/*enPin =*/EN,/*intPin=*/INT);
//DFRobot_TMF8801 tmf8x01(/*enPin =*/EN,/*intPin=*/INT);
bool irqFlag = false;
void notifyFun(){
irqFlag = true;
}
void setup() {
Serial.begin(115200); //Serial Initialization
while(!Serial){ //Wait for serial port to connect. Needed for native USB port only
}
Serial.print("Initialization ranging sensor TMF8x01......");
while(tmf8x01.begin() != 0){ //Initialization sensor,sucess return 0, fail return -1
Serial.println("failed.");
delay(1000);
}
Serial.println("done.");
Serial.print("Sensor Version info: ");
Serial.println(tmf8x01.getVersion()); //Print sensor info, fomat:major_patch_HW_SERIAL NUMBER
tmf8x01.enableIntPin(); //Enable INT pin to check measurement data. Sending a low signal to host if measurement distance completed.
#ifdef ARDUINO_ARCH_MPYTHON
/* mPython Interrupt Pin vs Interrupt NO
* ----------------------------------------------------------------------------------------------------
* | | DigitalPin | P0~P20 can be used as external interrupt |
* | mPython |---------------------------------------------------------------------------|
* | | Interrupt No | use digitalPinToInterrupt(Pn) to query interrupt number |
* |--------------------------------------------------------------------------------------------------|
*/
attachInterrupt(digitalPinToInterrupt(INT)/*query Interrupt NO of P0*/,notifyFun,FALLING); //Enable the external interrupt of mPython P0; rising edge trigger; connect INTA to P0
#else
/* Main-board of AVR series Interrupt Pin vs Interrupt NO
* ---------------------------------------------------------------------------------------
* | | DigitalPin | 2 | 3 | |
* | Uno, Nano, Mini, other 328-based |--------------------------------------------|
* | | Interrupt No | 0 | 1 | |
* |-------------------------------------------------------------------------------------|
* | | Pin | 2 | 3 | 21 | 20 | 19 | 18 |
* | Mega2560 |--------------------------------------------|
* | | Interrupt No | 0 | 1 | 2 | 3 | 4 | 5 |
* |-------------------------------------------------------------------------------------|
* | | Pin | 3 | 2 | 0 | 1 | 7 | |
* | Leonardo, other 32u4-based |--------------------------------------------|
* | | Interrupt No | 0 | 1 | 2 | 3 | 4 | |
* |--------------------------------------------------------------------------------------
*/
/* microbit Interrupt Pin vs Interrupt NO
* ---------------------------------------------------------------------------------------------------------------
* | | DigitalPin | P0~P20 can be used as external interrupt |
* | microbit |---------------------------------------------------------|
* |(when used as external interrupt, do not need to | Interrupt No | Interrupt NO is pin value, for instance, |
* | set it to input mode via pinMode) | | the Interrupt NO of P0 is 0, P1 is 1. |
* |-------------------------------------------------------------------------------------------------------------|
*/
attachInterrupt(/*Interrupt NO*/0,notifyFun,FALLING); //Enable external interrupt 0, connect INTA to the main-controller's digital pin: UNO(2),Mega2560(2),Leonardo(3),microbit(P0)
#endif
tmf8x01.startMeasurement(/*cailbMode =*/tmf8x01.eModeCalib); //Enable measuring with Calibration data.
//tmf8x01.startMeasurement(/*cailbMode =*/tmf8x01.eModeNoCalib); //Enable measuring with no Calibration data.
//tmf8x01.startMeasurement(/*cailbMode =*/tmf8x01.eModeCalibAndAlgoState); //Enable measuring with Calibration data and Algorithm state.
}
void loop() {
if(irqFlag){
irqFlag = false;
if (tmf8x01.isDataReady()) { //Is check measuring data vaild, if vaild that print measurement data to USB Serial COM.
Serial.print("Distance = ");
Serial.print(tmf8x01.getDistance_mm()); //Print measurement data to USB Serial COM, unit mm, in TMF8X01_MODE_COMBINE mode.
Serial.println(" mm");
}
}
}
结果
样例代码3 - 睡眠模式
测距20次,睡眠2s,再测距,TMF8x01传感器可以进入睡眠模式,在该模式下,传感器将停止测距.我们可以通过wakeup去唤醒该传感器,重新进入测距模式。
**注意:**测距模式下电流大概为37.9mA, 睡眠模式下电流为1.2mA
/*!
* @file sleep.ino
* @brief 测距20次,睡眠2s,再测距,TMF8x01传感器可以进入睡眠模式,在该模式下,传感器将停止测距.我们可以通过wakeup去唤醒该传感器,重新进入测距模式。
* @n note: 测距模式下电流大概为37.9mA, 睡眠模式下电流为1.2mA
* *
* Ranging mode configuration table:
* TMF8X01_MODE_PROXIMITY: PROXIMITY mode
* TMF8X01_MODE_DISTANCE: DISTANCE mode
* TMF8X01_MODE_COMBINE: PROXIMITY and DISTANCE hybrid mode
* default mode: TMF8X01_MODE_COMBINE
* --------------------------------------------------------------------------------|
* | Type | suport ranging mode | ranging ranges | Accuracy |
* |---------------------------------------|-----------------|---------------------|
* | TMF8801 | PROXIMITY and DISTANCE | | 20~100mm: +/-15mm |
* | | hybrid mode(only one) | 20~240cm | 100~200mm: +/-10mm |
* | | | | >=200: +/-%5 |
* |---------------------------------------|-----------------|---------------------|
* | | PROXIMITY mode | 0~10cm | |
* | |---------------------------|-----------------| >=200: +/-%5 |
* | TMF8701 | DISTANCE mode | 10~60cm | 100~200mm: +/-10mm |
* | |---------------------------|-----------------| |
* | | PROXIMITY and DISTANCE | 0~60cm | |
* | | hybrid mode | | |
* |---------------------------------------|-----------------|----------------------
* *
* @n hardware conneted table:
* ------------------------------------------
* | TMF8x01 | MCU |
* |-----------------------------------------|
* | I2C | I2C Interface |
* |-----------------------------------------|
* | EN | not connected, floating |
* |-----------------------------------------|
* | INT | not connected, floating |
* |-----------------------------------------|
* | PIN0 | not connected, floating |
* |-----------------------------------------|
* | PIN1 | not connected, floating |
* |-----------------------------------------|
*
* @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
* @licence The MIT License (MIT)
* @author [Arya](xue.peng@dfrobot.com)
* @version V1.0
* @data 2021-03-26
* @get from https://www.dfrobot.com
* @url https://github.com/DFRobot/DFRobot_TMF8x01
*/
#include "DFRobot_TMF8x01.h"
#define EN -1 //EN pin of of TMF8x01 module is floating, not used in this demo
#define INT -1 //INT pin of of TMF8x01 module is floating, not used in this demo
DFRobot_TMF8701 tmf8x01(/*enPin =*/EN,/*intPin=*/INT);
//DFRobot_TMF8801 tmf8x01(/*enPin =*/EN,/*intPin=*/INT);
#define NUM_OF_MEASUREMENT 20 //20 measurements
#define SLEEP_TIME 2000 //sleep 2000ms
uint8_t count = 0; //Measurement count
void setup() {
Serial.begin(115200); //Serial Initialization
while(!Serial){ //Wait for serial port to connect. Needed for native USB port only
}
Serial.print("Initialization ranging sensor TMF8x01......");
while(tmf8x01.begin() != 0){ //Initialization sensor,sucess return 0, fail return -1
Serial.println("failed.");
delay(1000);
}
Serial.println("done.");
Serial.print("Sensor Version info: ");
Serial.println(tmf8x01.getVersion()); //Print sensor info, fomat:major_patch_HW_SERIAL NUMBER
tmf8x01.startMeasurement(/*cailbMode =*/tmf8x01.eModeCalib); //Enable measuring with Calibration data.
//tmf8x01.startMeasurement(/*cailbMode =*/tmf8x01.eModeNoCalib); //Enable measuring with no Calibration data.
//tmf8x01.startMeasurement(/*cailbMode =*/tmf8x01.eModeCalibAndAlgoState); //Enable measuring with Calibration data and Algorithm state.
}
void loop() {
if (tmf8x01.isDataReady()) { //Is check measuring data vaild, if vaild that print measurement data to USB Serial COM.
Serial.print("Distance = ");
Serial.print(tmf8x01.getDistance_mm()); //Print measurement data to USB Serial COM, unit mm, in TMF8X01_MODE_COMBINE mode.
Serial.println(" mm");
count++;
}
if(count > NUM_OF_MEASUREMENT){
count = 0;
tmf8x01.sleep(); //sensor enter sleep mode.
Serial.println("sleep...");
delay(SLEEP_TIME);
Serial.println("wakeup...");
tmf8x01.wakeup(); //wakeup sensor from sleep mode to enter ranging mode.
}
}
结果
![](https://img.dfrobot.com.cn/wiki/5d6782b68b3b1513c2f4da54/4bf8e0bad92e4aeb7bc7177f32e8fcb1.png
样例代码4 - 校准模式
这个演示告诉如何获得14字节校准,以及如何设置校准范围。
**注意:**本演示应用场景:在黑暗条件下,传感器周围40cm内无目标
/*!
/*!
* @file calibration.ino
* @brief This demo tells how to get 14 bytes calibration, and how to set calibration ranging.
* @n This demo application scenario: no target within 40cm of the sensor, in dark conditions.
* *
* Ranging mode configuration table:
* TMF8X01_MODE_PROXIMITY: PROXIMITY mode
* TMF8X01_MODE_DISTANCE: DISTANCE mode
* TMF8X01_MODE_COMBINE: PROXIMITY and DISTANCE hybrid mode
* default mode: TMF8X01_MODE_COMBINE
* --------------------------------------------------------------------------------|
* | Type | suport ranging mode | ranging ranges | Accuracy |
* |---------------------------------------|-----------------|---------------------|
* | TMF8801 | PROXIMITY and DISTANCE | | 20~100mm: +/-15mm |
* | | hybrid mode(only one) | 20~240cm | 100~200mm: +/-10mm |
* | | | | >=200: +/-%5 |
* |---------------------------------------|-----------------|---------------------|
* | | PROXIMITY mode | 0~10cm | |
* | |---------------------------|-----------------| >=200: +/-%5 |
* | TMF8701 | DISTANCE mode | 10~60cm | 100~200mm: +/-10mm |
* | |---------------------------|-----------------| |
* | | PROXIMITY and DISTANCE | 0~60cm | |
* | | hybrid mode | | |
* |---------------------------------------|-----------------|----------------------
* *
* @n hardware conneted table:
* ------------------------------------------
* | TMF8x01 | MCU |
* |-----------------------------------------|
* | I2C | I2C Interface |
* |-----------------------------------------|
* | EN | not connected, floating |
* |-----------------------------------------|
* | INT | not connected, floating |
* |-----------------------------------------|
* | PIN0 | not connected, floating |
* |-----------------------------------------|
* | PIN1 | not connected, floating |
* |-----------------------------------------|
*
* @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
* @licence The MIT License (MIT)
* @author [Arya](xue.peng@dfrobot.com)
* @version V1.0
* @data 2021-03-26
* @get from https://www.dfrobot.com
* @url https://github.com/DFRobot/DFRobot_TMF8x01
*/
#include "DFRobot_TMF8x01.h"
#define EN -1 //EN pin of of TMF8x01 module is floating, not used in this demo
#define INT -1 //INT pin of of TMF8x01 module is floating, not used in this demo
DFRobot_TMF8701 tmf8x01(/*enPin =*/EN,/*intPin=*/INT);
//DFRobot_TMF8801 tmf8x01(/*enPin =*/EN,/*intPin=*/INT);
uint8_t calibrationDataBuffer[14] = {0x41,0x57,0x01,0xFD,0x04,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x04}; //The calibration data needs to be obtained for every sensor by call the function getCalibrationData.
int distance = 0;
void setup() {
Serial.begin(115200); //Serial Initialization
while(!Serial){ //Wait for serial port to connect. Needed for native USB port only
}
Serial.print("Initialization ranging sensor TMF8x01......");
while(tmf8x01.begin() != 0){ //Initialization sensor,sucess return 0, fail return -1
Serial.println("failed.");
delay(1000);
}
Serial.println("done.");
Serial.print("Sensor Version info: ");
Serial.println(tmf8x01.getVersion()); //Print sensor info, fomat:major_patch_HW_SERIAL NUMBER
/*
while(tmf8x01.getCalibrationData(calibrationDataBuffer, sizeof(calibrationDataBuffer)) != true){ //get calibration data to update calibrationDataBuffer buffer. You needs to be obtained for every sensor by call the function getCalibrationData.
Serial.println("Get and print calibration data...");
delay(1000);
}
Serial.println("Get and print calibration...sucess");
for(int i = 0; i < sizeof(calibrationDataBuffer); i++){
Serial.print("0x");
if(calibrationDataBuffer[i] < 16) Serial.print("0");
Serial.print(calibrationDataBuffer[i]);
Serial.print(",");
}
Serial.println();
*/
tmf8x01.setCalibrationData(calibrationDataBuffer, sizeof(calibrationDataBuffer)); //Set calibration data to sensor.
tmf8x01.startMeasurement(/*cailbMode =*/tmf8x01.eModeCalib); //Enable measuring with Calibration data.
//tmf8x01.startMeasurement(/*cailbMode =*/tmf8x01.eModeCalibAndAlgoState); //Enable measuring with Calibration data and Algorithm state.
}
void loop() {
if (tmf8x01.isDataReady()) { //Is check measuring data vaild, if vaild that print measurement data to USB Serial COM.
Serial.print("Distance = ");
Serial.print(tmf8x01.getDistance_mm()); //Print measurement data to USB Serial COM, unit mm, in TMF8X01_MODE_COMBINE mode.
Serial.println(" mm");
}
}
结果
常见问题
还没有客户对此产品有任何问题,欢迎通过qq或者论坛联系我们!
更多问题及有趣的应用,可以 访问论坛 进行查阅或发帖。