Wíwọ̀n Ààyè pẹ̀lú Ẹ̀rọ̀ Laser Time-of-Flight VL53L0X Sensor Ní Lílò Arduino
Nínú ẹ̀kọ́ yìí, a óò ṣàwárí bí a ṣe ń wọn ààyè pẹ̀lú ẹ̀rọ ìmọ̀ VL53L0X laser time-of-flight pẹ̀lú Arduino. Ẹ̀rọ yìí ń gba ìwọ̀n ààyè pípéye, ó sì lè ṣe àkópọ̀ rẹ̀ sínú àwọn iṣẹ́ oríṣiríṣi, bíi robotics tàbí automation systems. Ní ìparí ẹ̀kọ́ yìí, ìwọ yóò lè ṣètò ẹ̀rọ náà, so ó pọ̀ dáradára, kí o sì kọ kóòdù tí ó pọn dandan láti gba àwọn ìwọ̀n ààyè.
A óò ṣàlàyé àwọn ẹ̀rọ tí a nílò, bí a ṣe ń so wọ́n pọ̀, àti àlàyé kíkún nípa kóòdù tí ń ṣiṣẹ́ pẹ̀lú ẹ̀rọ VL53L0X. Fún ìrísí tí ó hàn kedere síi, rí i pé o wo fídíò tí ó bá ọ lọ́wọ́ (nínú fídíò ní 00:15).
Àlàyé Ẹ̀rọ
Ẹ̀rọ pàtàkì jùlọ nínú iṣẹ́ yìí ni VL53L0X. Èyí jẹ́ ẹ̀rọ ìwọ̀n ààyè time-of-flight tí ó ń ṣiṣẹ́ nípa gbígbé ìtànṣán laser jáde àti wíwọ̀n àkókò tí ìmọ́lẹ̀ tí ó ṣe àfihàn bá padà dé ọ̀dọ̀ ẹ̀rọ náà. Ó ń pèsè àwọn ìwọ̀n ààyè ní millimeters, ó sì lè ṣiṣẹ́ lórí ọ̀pọ̀lọpọ̀ ààyè, tí ó mú un dára fún àwọn ìlò oríṣiríṣi.
Yàtọ̀ sí VL53L0X, ìwọ yóò nílò Arduino board láti ṣe ìmúṣẹ data ẹ̀rọ náà. Arduino yóò bá ẹ̀rọ náà sọ̀rọ̀ nípa I2C protocol, èyí tí ó rọrùn fún ìsopọ̀ àti ìdarí. Ìwọ yóò tún nílò jumper wires láti fi ìsopọ̀ ṣẹ̀dá láàárín ẹ̀rọ náà àti Arduino.
Àwọn Àlàyé Datasheet
| Olùṣelọ́pọ̀ | STMicroelectronics |
|---|---|
| Nọ́mbà apá | VL53L0X |
| Fóltì Logic/IO | 1.8 V sí 3.6 V |
| Fóltì ìpèsè | 2.6 V sí 3.6 V |
| Ìwọ̀n ìjàde (fún ikanni) | … |
| Ìwọ̀n tí ó ga jùlọ (fún ikanni) | … |
| Ìtọ́sọ́nà ìgbohùnsáfẹ́fẹ́ PWM | … |
| Àwọn ìpele ìwọ̀n input logic | … |
| Ìdìndìndìndìn fóltì / RDS(on) / saturation | … |
| Àwọn ìwọ̀n ìgbóná | -40 °C sí 85 °C |
| Àpótí | QFN-16 |
| Àwọn àkíyèsí / àwọn oríṣi | Ẹ̀rọ time-of-flight, I2C interface |
- Rí i pé àwọn ìpele fóltì tọ́, kí o má ba à ba ẹ̀rọ náà jẹ́.
- Lo àwọn pull-up resistors lórí àwọn ìlà I2C bí ó bá pọn dandan.
- Jẹ́ kí ẹ̀rọ náà mọ́, kí o sì má ṣe dí i lọ́nà, fún àwọn ìwọ̀n tí ó péye.
- Ṣe calibration fún ẹ̀rọ náà fún àwọn àyíká pàtó láti mú ìwọ̀n dára síi.
- Ṣàyẹ̀wò fún àwọn àṣìṣe timeout nínú kóòdù láti kojú àwọn ìṣòro ìwọ̀n.
Àwọn Ìtọ́sọ́nà Ìsopọ̀
Láti so VL53L0X pọ̀ mọ́ Arduino, bẹ̀rẹ̀ nípa sísopọ̀ pin VCC lórí ẹ̀rọ náà sí pin 5V lórí Arduino. Èyí jẹ́ àìléwu nítorí pé ẹ̀rọ náà ní regulator inú rẹ̀ tí ó jẹ́ kí ó lè ṣiṣẹ́ pẹ̀lú ìpèsè 5V nígbà tí ó ṣì ń ṣiṣẹ́ ní àwọn ìpele 3.3V. Nígbà tí o bá ṣe èyí, so pin GND lórí ẹ̀rọ náà sí pin ilẹ̀ lórí Arduino.
Nísinsin yìí, so pin SDA lórí ẹ̀rọ náà sí pin A4 lórí Arduino, èyí tí ó jẹ́ ìlà data I2C àìṣàtúnṣe. Lẹ́yìn náà, so pin SCL lórí ẹ̀rọ náà sí pin A5 lórí Arduino, èyí tí ó jẹ́ ìlà aago I2C àìṣàtúnṣe. Fún àwọn Arduino mìíràn, àwọn pin SDA àti SCL lè yàtọ̀; fún àpẹẹrẹ, lórí Arduino Mega, lo àwọn pin 20 àti 21, ní ọ̀nà yẹn. Rí i pé gbogbo àwọn ìsopọ̀ mú dáradára kí o tó tan iná sí eto náà.
Àwọn Àpẹẹrẹ Kóòdù & Ìtọ́sọ́nà
Nínú kóòdù Arduino, a bẹ̀rẹ̀ nípa fífi àwọn ilé-ìkàwé pọn dandan sí i àti ṣíṣe initialization fún ẹ̀rọ VL53L0X. Nínú iṣẹ́ setup(), a ṣètò ìbánisọ̀rọ̀ serial àti ṣíṣe initialization fún ẹ̀rọ náà:
void setup() {
Serial.begin(9600);
Wire.begin();
sensor.init();
sensor.setTimeout(500);
sensor.startContinuous();
}
Àkójọpọ̀ yìí ṣe initialization fún ẹ̀rọ náà, ó sì bẹ̀rẹ̀ ipo ìwọ̀n lílọ̀tọ̀ọ̀tọ̀. Iṣẹ́ setTimeout(500) ṣe àmúlò láti rí i pé ẹ̀rọ náà kò ní dúró títí láé bí ó bá kùnà láti ka ààyè kan.
Nínú iṣẹ́ loop(), a ka ààyè náà, a sì tẹ̀ ẹ́ jáde sí ibi ìṣàkíyèsí serial:
void loop() {
int distance = sensor.readRangeContinuousMillimeters();
distance = distance - 55; // Ṣe àtúnṣe fún àṣìṣe
Serial.print("Distance: ");
Serial.print(distance);
Serial.print("mm");
if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT"); }
Serial.println();
}
Apá yìí ti kóòdù náà gba ìwọ̀n ààyè, ó sì ṣe àtúnṣe fún àṣìṣe ètò èyíkéyìí nípa yíyọ nọ́mbà kan tí ó dúró ṣinṣin kúrò. Ó tún ṣàyẹ̀wò fún àwọn timeout bí ẹ̀rọ náà bá kùnà láti gba ìwọ̀n kan.
Ìfihàn / Ohun Tí O Lè Retí
Nígbà tí o bá ṣiṣẹ́ eto náà, ìwọ yóò rí àwọn ìmúdójúìwọ̀n lílọ̀tọ̀ọ̀tọ̀ ti ààyè tí ẹ̀rọ VL53L0X wọn nínú ibi ìṣàkíyèsí serial. Àwọn ìwọ̀n náà yóò hàn ní millimeters. Bí o bá gbé ohun kan súnmọ́ ẹ̀rọ náà tàbí kó o jìnnà sí i, àwọn iye ààyè yóò yípadà ní ìbámu. Bí timeout bá wáyé, ìwọ yóò rí ifiranṣẹ́ "TIMEOUT" tí ó ń fi hàn pé ẹ̀rọ náà kùnà láti ka ààyè (nínú fídíò ní 05:30).
Àwọn Àkókò Fídíò
- 00:00 - Ìfáàrà
- 00:15 - Àkópọ̀ àwọn ẹ̀rọ
- 01:00 - Àwọn ìtọ́sọ́nà ìsopọ̀
- 02:30 - Ìtọ́sọ́nà kóòdù
- 05:30 - Ìfihàn
/* This example shows how to use continuous mode to take
range measurements with the VL53L0X. It is based on
vl53l0x_ContinuousRanging_Example.c from the VL53L0X API.
The range readings are in units of mm.
Original source: https://github.com/pololu/vl53l0x-arduino
Modified by Ahmad Shamshiri for RoboJax.com
Date modified: Sep 26, 2017
*/
#include <Wire.h>
#include <VL53L0X.h>
VL53L0X sensor;
void setup()
{
Serial.begin(9600);
Wire.begin();
sensor.init();
sensor.setTimeout(500);
// Start continuous back-to-back mode (take readings as
// fast as possible). To use continuous timed mode
// instead, provide a desired inter-measurement period in
// ms (e.g. sensor.startContinuous(100)).
sensor.startContinuous();
}
void loop()
{
int distance =sensor.readRangeContinuousMillimeters();
distance = distance -55;// -55 is to compensate for error. Change or set it to zero to make it work for your sensor
Serial.print("Distance: ");
Serial.print(distance);
Serial.print("mm");
if (sensor.timeoutOccurred()) { Serial.print(" TIMEOUT"); }
Serial.println();
}
++
/* This example shows how to use continuous mode to take
range measurements with two VL53L0X sensors. It is based on
vl53l0x_ContinuousRanging_Example.c from the VL53L0X API.
The range readings are in units of mm.
Original source: https://github.com/pololu/vl53l0x-arduino
Modified by Ahmad Shamshiri for RoboJax.com
Date modified: June 06, 2018
Dennis from YouTube requested this code on June 06, 2018
*/
#include <Wire.h>
#include <VL53L0X.h>
VL53L0X sensor1;// define object for sensor 1
VL53L0X sensor2;// define object for sensor 2
void setup()
{
Serial.begin(9600);
Wire.begin();
sensor1.init();// initialize sensor 1
sensor1.setTimeout(500);// set time out for sensor 1
sensor2.init();// initialize sensor 2
sensor2.setTimeout(500);// set time out for sensor 2
// Start continuous back-to-back mode (take readings as
// fast as possible). To use continuous timed mode
// instead, provide a desired inter-measurement period in
// ms (e.g. sensor.startContinuous(100)).
sensor1.startContinuous();// measure continuously for sensor 1
sensor2.startContinuous();// measure continuously for sensor 2
}
void loop()
{
int distance1 =sensor1.readRangeContinuousMillimeters();// get distance for sensor 1
int distance2 =sensor2.readRangeContinuousMillimeters();// get distance for sensor 2
distance1 = distance1 -55;// -55 is to compensate for error. Change or set it to zero to make it work for your sensor
distance2 = distance2 -34;// -35 is to compensate for error. Change or set it to zero to make it work for your sensor
Serial.print("Distance 1: ");
Serial.print(distance1);// print distance from sensor 1
Serial.print("mm Distance 2: ");
Serial.print(distance2);// print distance from sensor 2
Serial.print("mm");
if (sensor1.timeoutOccurred()) { Serial.print(" TIMEOUT 1"); }
if (sensor2.timeoutOccurred()) { Serial.print(" TIMEOUT 2"); }
Serial.println();
}
Orisun & itọkasi
Ko si awọn orisun sibẹsibẹ.
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 -
Adafruit VL6180X Time of Flight Distance SensorFritzing part file for the Adafruit VL6180X Time of Flight distance sensor. This module measures absolute distance up to 100mm and ambient light, communicating over I2C. Includes the sensor breakout board with pins for power, ground, SDA, SCL, and interrupt.
Adafruit VL6180X Time of Flight Distance Sensor.fzpz0.02 MB
Awọn faili miiran
-
Polou VL53L0X ile-ika
robojax-VL53L0X-polou-arduino-master.zip0.02 MB