Lilo mita ijinna laser VL53L0X pẹlu Arduino
Ninu ẹkọ yii, a yoo ṣawari bi o ṣe le lo mita ijinna laser VL53L0X pẹlu Arduino kan. Ẹrọ yii n gba ọ laaye lati wiwọn awọn ijinna ni deede nipa lilo laser kan, ṣiṣe ni apẹrẹ fun awọn ohun elo oriṣiriṣi bii awọn roboti ati adaṣe. Ni ipari ikẹkọ yii, iwọ yoo ni iṣeto iṣẹ ti o le wiwọn awọn ijinna ati ṣafihan wọn ni atẹle ni tẹlentẹle.

Fun iṣẹ akanṣe wa, a yoo lo ile-ikawe VL53L0X Adafruit, eyiti o ṣe irọrun ilana ibaraenisepo pẹlu sensọ naa. Ile-ikawe yii pese awọn iṣẹ ti o yẹ lati bẹrẹ sensọ naa, ka awọn wiwọn, ati mu eyikeyi awọn aṣiṣe ti o le dide. O le tọka si fidio fun itọsọna wiwo lori iṣeto (ni fidio ni 02:15).
Hardware Salaye
Awọn paati akọkọ ti iṣẹ akanṣe yii ni mita ijinna laser VL53L0X ati igbimọ Arduino. VL53L0X jẹ sensọ akoko-ti-flight ti o nlo lesa lati wiwọn awọn ijinna to awọn mita 2 pẹlu deede giga. O ṣiṣẹ nipasẹ ilana I2C, gbigba ibaraẹnisọrọ ti o rọrun pẹlu Arduino.
Igbimọ Arduino n ṣiṣẹ bi microcontroller ti o ṣe ilana data lati VL53L0X. O firanṣẹ awọn aṣẹ si sensọ ati gba awọn wiwọn ijinna, eyiti o le ṣe afihan tabi lo ninu awọn ohun elo miiran. O ṣe pataki lati ṣe idaniloju awọn kika ti o tọ lati inu sensọ naa.
Awọn alaye Datasheet
| Olupese | STMicroelectronics |
|---|---|
| Nọmba apakan | VL53L0X |
| Awọn ọna foliteji | 2.6 V si 3.5 V |
| Ibiti o | 30 mm si 2000 mm |
| Otitọ | ±3% aṣoju |
| Ni wiwo | I2C |
| Iwọn otutu ibiti o | -40 ° C si + 85 ° C |
| Lilo lọwọlọwọ | <1 mA (imurasilẹ), 20 mA (ti nṣiṣe lọwọ) |
| Package | VFLGA-8 |
- Rii daju pe sensọ naa ni agbara ti o tọ (2.6 V si 3.5 V).
- Ṣetọju awọn eto adirẹsi I2C ti o tọ lati yago fun awọn rogbodiyan.
- Jeki sensọ naa mọ fun awọn wiwọn ijinna deede.
- Ti o ba jẹ dandan, lo awọn ohun elo ti o yẹ lori awọn ila I2C ti o ba jẹ dandan.
- Yẹra fun oorun taara lori sensọ fun awọn kika ti o gbẹkẹle.
Awọn itọnisọna Wiring

Lati ṣe okun waya sensọ VL53L0X si Arduino, sopọ PIN VCC ti sensọ si pin 5V lori Arduino. O yẹ ki o wa ni asopọ pẹlu ilẹ (GND) ti Arduino. Fun ibaraẹnisọrọ I2C, sopọ PIN SDA ti VL53L0X si pin A4 lori Arduino, ki o so pin SCL pọ si PIN A5. Ti o ba nlo awoṣe Arduino ti o yatọ, tọka si awọn iṣẹ SDA ati SCL pin fun igbimọ yẹn.
Fun apẹẹrẹ, lori Arduino Mega, iwọ yoo sopọ SDA si pin 20 ati SCL si pin 21. Rii daju pe gbogbo awọn ibaraẹnisọrọ ti wa ni aabo lati yago fun awọn iṣoro ibaraẹnisọrọ. Ti sensọ naa ko ba dahun, ṣayẹwo lẹẹmeji okun waya ki o rii daju pe Arduino ti ni agbara daradara.
Awọn apẹẹrẹ koodu ati Walkthrough
Ni isalẹ ni snippet lati iṣẹ iṣeto ti o bẹrẹ sensọ VL53L0X:
void setup() {
Serial.begin(9600);
while (! Serial) {
delay(1);
}
Serial.println("Robojax Test");
if (!lox.begin()) {
Serial.println(F("Failed to boot VL53L0X"));
while(1);
}
}Koodu yii bẹrẹ ibaraẹnisọrọ ni tẹlentẹle ati gbìyànjú lati bẹrẹ sensọ VL53L0X. Ti sensọ naa ba kuna lati bata, yoo tẹ ifiranṣẹ aṣiṣe kan ki o da eto naa duro.
Nigbamii, eyi ni snippet lati iṣẹ lupu ti o ka wiwọn ijinna:
void loop() {
VL53L0X_RangingMeasurementData_t measure;
lox.rangingTest(&measure, false);
if (measure.RangeStatus != 4) {
Serial.print("Distance (mm): "); Serial.println(measure.RangeMilliMeter);
} else {
Serial.println(" out of range ");
}
delay(100);
}Àkọsílẹ yii nigbagbogbo ka wiwọn ijinna lati sensọ naa ki o tẹ sita si atẹle ni tẹlentẹle. Ti o ba ti o ba
Ifihan / Ohun ti o yẹ ki o reti
Nigbati o ba nṣiṣẹ eto naa, o yẹ ki o wo awọn wiwọn ijinna ti o han ni atẹle tẹlentẹle. Awọn kika yẹ ki o ṣe imudojuiwọn ni gbogbo 100 milliseconds. Ti sensọ ba tọka si ohun kan, yoo ṣe afihan ijinna ni milimita. Ti o ba ti o ba ti Rii daju lati ṣe idanwo sensọ laarin ibiti o ti ṣalaye fun awọn abajade ti o dara julọ (ni fidio ni 10:00).
Awọn akoko fidio
- 00:00- Ifihan
- 02:15- Wiring setup
- 05:30- Alaye koodu
- 10:00- Ifihan
/* This example shows how to use continuous mode to take
range measurements with the VL53L0X.
// Original source from Adafruit https://github.com/adafruit/Adafruit_VL53L0X
// Modified by Ahmad Shamshiri for RoboJax.com
// Date modified: Sep 26, 2017
// Nejrabi
* Get this code and other Arduino codes from Robojax.com
Learn Arduino step by step in a structured course with all material, wiring diagrams, and libraries
all in one place.
If you found this tutorial helpful, please support me so I can continue creating
content like this.
or make a donation using PayPal http://robojax.com/L/?id=64
* * This code is "AS IS" without warranty or liability. Free to be used as long as you keep this note intact.*
* This code has been downloaded from Robojax.com
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
Copyright (c) 2015, Majenko Technologies
All rights reserved.
Redistribution and use in source and binary forms, with or without modification,
are permitted provided that the following conditions are met:
* * Redistributions of source code must retain the above copyright notice, this
list of conditions and the following disclaimer.
* * Redistributions in binary form must reproduce the above copyright notice, this
list of conditions and the following disclaimer in the documentation and/or
other materials provided with the distribution.
* * Neither the name of Majenko Technologies nor the names of its
contributors may be used to endorse or promote products derived from
this software without specific prior written permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR
ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
*/
#include "Adafruit_VL53L0X.h"
Adafruit_VL53L0X lox = Adafruit_VL53L0X();
void setup() {
Serial.begin(9600);
// wait until serial port opens for native USB devices
while (! Serial) {
delay(1);
}
Serial.println("Robojax Test");
if (!lox.begin()) {
Serial.println(F("Failed to boot VL53L0X"));
while(1);
}
// power
Serial.println(F("VL53L0X API Simple Ranging example\n\n"));
}
void loop() {
VL53L0X_RangingMeasurementData_t measure;
Serial.print("Reading a measurement... ");
lox.rangingTest(&measure, false); // pass in 'true' to get debug data printout!
if (measure.RangeStatus != 4) { // phase failures have incorrect data
Serial.print("Distance (mm): "); Serial.println(measure.RangeMilliMeter);
} else {
Serial.println(" out of range ");
}
delay(100);
}
Orisun & itọkasi
-
Ita gbangbaVL53L0X datasheet (PDF)st.com
Fáìlìs📁
Fayile Fritzing
-
Adafruit VL6180X Time of Flight Distance SensorFritzing part for the Adafruit VL6180X Time of Flight distance sensor. This sensor measures absolute distance up to 100mm and ambient light, communicating via I2C. Includes the sensor breakout board and pin connections for use in Fritzing projects.
Adafruit VL6180X Time of Flight Distance Sensor-1.fzpz0.02 MB
Awọn faili miiran
-
Polou VL53L0X ile-ika
robojax-VL53L0X-polou-arduino-master.zip0.02 MB