arduino 只有.h没有.cpp_VL53L0X激光测距传感器.Arduino使用篇

d7e2c72ff8b20c0abd3419d4bfb4b796.png

这里因为DF家的demo是Arduino的,我这里就先用Arduino做演示~后面用手头别的开发板来演示.

https://github.com/DFRobot/DFRobot_VL53L0X

ec79ad69d30a2795e7d1d1c99ae7297b.png

下载库,我这里解压了.建议个人使用不解压

f8d9011b3864ff583cfe2d5bb912229d.png

解压的样子,h+cpp+ino.标配,这里还有数据手册

187994c8be17bf47b724ebcd4b3c60dc.png

接下来导入库,以驱动传感器

  1. 项目

  2. 加载

  3. 添加.zip库

860e2e45880a21cd5b14cf658b7d1449.png

刚刚在GitHub下载的文件,不要解压.zip文件

892dbdafaf5147e1931f6ab2aaefef23.png

左下角提示成功

c0fff3c347e237292e802db50e0e091c.png

我们在看库,成功导入

555b3535adc89c3b62b5f7e0e0ac9d3b.png

点击过以后,在当前ino引入头文件

96c17924ae8c4435dcc67729f33234a0.png

example也有一个了

d201147a4dd195e83a3d27cadf0eb24c.png

就是它

/*! * @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);}

这个就是例子,我放到这里了

9934f83e91d92c0ac5eb36feece08611.png

这个是一个Arduino的板子

dbb7f1f201dd40f182823e7040575cc4.png

I2C的线连接在这里

b3153feb17abd35e5c754dd1f245ac8e.png

DF家的板子4口做在了一起,比较方便.用其他的开发板时注意连线

9ab5469ca11cb87fdb4ca96fdb577cf9.png

测试数据表(单位: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();

1cf6890dda87fe97c45cffa66c747b75.png

在传感器封装库的头文件里面有api的列表

cpp文件时具体实现

78ff67c79ba231bcc4e84e27f1e1f0a2.png

我这里第一次选的5V,没有出现结果.第二次是3.3V出结果了

37c529c0696b71f1af311d6b89a80e81.png

注意I2C的连接位置

e874494b3310faff435427c945493dc4.png

09f9b054b04964afea09268697217c41.png

15200c57e0fa6296289d946aeea0e6d8.png

也可以绘图看

d7e2c72ff8b20c0abd3419d4bfb4b796.png

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值