37款傳感器與執(zhí)行器的提法,在網(wǎng)絡上廣泛流傳狭吼,其實Arduino能夠兼容的傳感器模塊肯定是不止這37種的层坠。鑒于本人手頭積累了一些傳感器和執(zhí)行器模塊,依照實踐出真知(一定要動手做)的理念搏嗡,以學習和交流為目的窿春,這里準備逐一動手嘗試系列實驗拉一,不管成功(程序走通)與否,都會記錄下來—小小的進步或是搞不掂的問題旧乞,希望能夠拋磚引玉蔚润。
【Arduino】168種傳感器模塊系列實驗(資料代碼+仿真編程+圖形編程)
實驗一百五十八:GY-530 VL53L0X 激光測距 ToF測距 飛行時間測距傳感器模塊 IIC通信協(xié)議
03--.jpg
【Arduino】168種傳感器模塊系列實驗(資料代碼+仿真編程+圖形編程)
實驗一百五十八:GY-530 VL53L0X 激光測距 ToF測距 飛行時間測距傳感器模塊 IIC通信協(xié)議
項目之七:查詢VL53L0X模塊和SSD1306 OLED模塊的IIC地址
實驗開源代碼
/*
【Arduino】168種傳感器模塊系列實驗(資料代碼+仿真編程+圖形編程)
實驗一百五十八:GY-530 VL53L0X 激光測距 ToF測距 飛行時間測距傳感器模塊 IIC通信協(xié)議
項目之七:查詢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通信協(xié)議
項目之八:使用 VL53L0X 進行范圍測量并在 SSD1306 OLED 上顯示(mm)
實驗開源代碼
/*
【Arduino】168種傳感器模塊系列實驗(資料代碼+仿真編程+圖形編程)
實驗一百五十八:GY-530 VL53L0X 激光測距 ToF測距 飛行時間測距傳感器模塊 IIC通信協(xié)議
項目之八:使用 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
WeChat_20210816123028.gif
實驗開源仿真編程(Linkboy V4.62)
項目之九:串口顯示VL53L0X測距
37.jpg
實驗串口輸出情況
38.jpg
實驗開源仿真編程(Linkboy V4.62)
項目之十:串口顯示VL53L0X測距波形
38-.jpg
實驗串口繪圖器返回情況
39.jpg