回到首页 返回首页
回到顶部 回到顶部
返回上一页 返回上一页

【雕爷学编程】Arduino动手做(158)---VL53L0X激光测距模块3 中等

头像 驴友花雕 2023.07.11 18 4

37款传感器与执行器的提法,在网络上广泛流传,其实Arduino能够兼容的传感器模块肯定是不止这37种的。鉴于本人手头积累了一些传感器和执行器模块,依照实践出真知(一定要动手做)的理念,以学习和交流为目的,这里准备逐一动手尝试系列实验,不管成功(程序走通)与否,都会记录下来—小小的进步或是搞不掂的问题,希望能够抛砖引玉。

 

【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)

实验一百五十八:GY-530 VL53L0X 激光测距 ToF测距 飞行时间测距传感器模块 IIC通信协议

 


03--.jpg

【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)

  实验一百五十八:GY-530 VL53L0X 激光测距 ToF测距 飞行时间测距传感器模块 IIC通信协议

  项目之七:查询VL53L0X模块和SSD1306 OLED模块的IIC地址

  实验开源代码


 

代码
/*

 【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)

  实验一百五十八:GY-530 VL53L0X 激光测距 ToF测距 飞行时间测距传感器模块 IIC通信协议

 项目之七:查询VL53L0X模块和SSD1306 OLED模块的IIC地址

 模块接线:

 VL53L0X Arduino

 VCC    5V

 GND    GND

 SCL    A5

 SDA    A4

*/



#include <Wire.h>

void setup()

{

 Wire.begin();

 Serial.begin(9600);

 while (!Serial);       // Leonardo: wait for serial monitor

 Serial.println("\nI2C Scanner");

}

void loop()

{

 byte error, address;

 int nDevices;

 Serial.println("Scanning...");

 nDevices = 0;

 for (address = 1; address < 127; address++ )

 {

  // The i2c_scanner uses the return value of

  // the Write.endTransmisstion to see if

  // a device did acknowledge to the address.

  Wire.beginTransmission(address);

  error = Wire.endTransmission();

  if (error == 0)

  {

   Serial.print("I2C device found at address 0x");

   if (address < 16)

    Serial.print("0");

   Serial.print(address, HEX);

   Serial.println(" !");

   nDevices++;

  }

  else if (error == 4)

  {

   Serial.print("Unknown error at address 0x");

   if (address < 16)

    Serial.print("0");

   Serial.println(address, HEX);

  }

 }

 if (nDevices == 0)

  Serial.println("No I2C devices found\n");

 else

  Serial.println("done\n");

 delay(5000);      // wait 5 seconds for next scan

}

实验串口返回情况


35.jpg

 【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)

  实验一百五十八:GY-530 VL53L0X 激光测距 ToF测距 飞行时间测距传感器模块 IIC通信协议

  项目之八:使用 VL53L0X 进行范围测量并在 SSD1306 OLED 上显示(mm)

  实验开源代码


 

代码
/*

 【Arduino】168种传感器模块系列实验(资料代码+仿真编程+图形编程)

 实验一百五十八:GY-530 VL53L0X 激光测距 ToF测距 飞行时间测距传感器模块 IIC通信协议

 项目之八:使用 VL53L0X 进行范围测量并在 SSD1306 OLED 上显示(mm)

 模块接线:SSD1306 OLED模块相同

 VL53L0X Arduino

 VCC    5V

 GND    GND

 SCL    A5

 SDA    A4

*/

#include <Wire.h>

#include "Adafruit_VL53L0X.h"

#include <SPI.h>

#include <Adafruit_GFX.h>

#include <Adafruit_SSD1306.h>

Adafruit_SSD1306 display = Adafruit_SSD1306();

Adafruit_VL53L0X lox = Adafruit_VL53L0X();

#if (SSD1306_LCDHEIGHT != 32)

#error("Height incorrect, please fix Adafruit_SSD1306.h!");

#endif

void setup() {

 Serial.begin(9600);

 display.begin(SSD1306_SWITCHCAPVCC, 0x3C); // initialize with the I2C addr 0x3C (for the 128x64)

 // init done

 display.display();

 delay(1000);

 Wire.begin();

 if (!lox.begin()) {

  Serial.println(F("Failed to boot VL53L0X"));

  while (1);

 }

 // text display big!

 display.setTextSize(4);

 display.setTextColor(WHITE);

}

void loop() {

 VL53L0X_RangingMeasurementData_t measure;

 lox.rangingTest(&measure, false); // pass in 'true' to get debug data printout!

 if (measure.RangeStatus != 4) { // phase failures have incorrect data

  display.clearDisplay();

  display.setCursor(0, 0);

  display.print(measure.RangeMilliMeter);

  display.print("mm");

  display.display();

  Serial.println();

  delay(50);

 } else {

  display.display();

  display.clearDisplay();

  return;

 }

}

Arduino实验场景图


36.jpg

实验开源仿真编程(Linkboy V4.62)

项目之九:串口显示VL53L0X测距

 

37.jpg

实验串口输出情况

 


38.jpg

实验开源仿真编程(Linkboy V4.62)

项目之十:串口显示VL53L0X测距波形


38-.jpg

实验串口绘图器返回情况


39.jpg

评论

user-avatar
  • 三春牛-创客

    三春牛-创客2024.03.24

    赞赞赞

    0
    • 三春牛-创客

      三春牛-创客2024.03.24

      不错不错

      0
      • 伦**

        伦**2024.03.20

        666

        0
        • hacker_

          hacker_2023.08.19

          666

          0
          icon 他的勋章
            展开更多