这里因为DF家的demo是Arduino的,我这里就先用Arduino做演示~后面用手头别的开发板来演示.
https://github.com/DFRobot/DFRobot_VL53L0X
下载库,我这里解压了.建议个人使用不解压
解压的样子,h+cpp+ino.标配,这里还有数据手册
接下来导入库,以驱动传感器
项目
加载
添加.zip库
刚刚在GitHub下载的文件,不要解压.zip文件
左下角提示成功
我们在看库,成功导入
点击过以后,在当前ino引入头文件
example也有一个了
就是它
/*! * @file DFRobot_VL53L0X.ino * @brief DFRobot's Laser rangefinder library * @n The example shows the usage of VL53L0X in a simple way. * @copyright [DFRobot](http://www.dfrobot.com), 2016 * @copyright GNU Lesser General Public License * @author [LiXin] * @version V1.0 * @date 2017-8-21 * @https://github.com/DFRobot/DFRobot_VL53L0X timer*/#include "Arduino.h"#include "Wire.h"#include "DFRobot_VL53L0X.h"/*****************Keywords instruction*****************///Continuous--->Continuous measurement model//Single------->Single measurement mode//High--------->Accuracy of 0.25 mm//Low---------->Accuracy of 1 mm/*****************Function instruction*****************///setMode(ModeState mode, PrecisionState precision) //*This function is used to set the VL53L0X mode //*mode: Set measurement mode Continuous or Single //*precision: Set the precision High or Low//void start() //*This function is used to enabled VL53L0X//float getDistance() //*This function is used to get the distance//uint16_t getAmbientCount() //*This function is used to get the ambient count//uint16_t getSignalCount() //*This function is used to get the signal count//uint8_t getStatus(); //*This function is used to get the status//void stop() //*This function is used to stop measuringDFRobotVL53L0X sensor;void setup() { //initialize serial communication at 9600 bits per second: Serial.begin(115200); //join i2c bus (address optional for master) Wire.begin(); //Set I2C sub-device address sensor.begin(0x50); //Set to Back-to-back mode and high precision mode sensor.setMode(Continuous,High); //Laser rangefinder begins to work sensor.start();}void loop() { //Get the distance Serial.print("Distance: ");Serial.println(sensor.getDistance()); //The delay is added to demonstrate the effect, and if you do not add the delay, //it will not affect the measurement accuracy delay(500);}
这个就是例子,我放到这里了
这个是一个Arduino的板子
I2C的线连接在这里
DF家的板子4口做在了一起,比较方便.用其他的开发板时注意连线
测试数据表(单位:mm)
#include DFRobotVL53L0X sensor //创建一个VL53L0X对象/* @函数功能:设置测距模式。 @参数1 mode: 测距模式。 Single: 单次测距。 Continuous: 连续测距。 @参数2 precision: 测量精度 High: 高精度(0.25mm)。 Low: 标准精度(1mm)。*/void setMode(uint8_t mode, uint8_t precision);/* @函数功能:开始测量距离。*/void start();/* @函数功能:停止测量。*/void stop();/* @函数功能:获取距离。*/uint16_t getDistance();/* @函数功能:获取环境量。*/uint16_t getAmbientCount();/* @函数功能:获取信号数。*/uint16_t getSignalCount();
在传感器封装库的头文件里面有api的列表
cpp文件时具体实现
我这里第一次选的5V,没有出现结果.第二次是3.3V出结果了
注意I2C的连接位置
也可以绘图看