4.7 KiB
Detect proximity - Wio Terminal
For dis part of di lesson, you go add proximity sensor to your Wio Terminal, and read di distance wey e dey measure.
Hardware
Di Wio Terminal need one proximity sensor.
Di sensor wey you go use na Grove Time of Flight distance sensor. Dis sensor dey use laser ranging module to measure distance. E fit measure distance from 10mm to 2000mm (1cm - 2m), and e dey report di values for dat range well well, but if di distance pass 1000mm, e go report am as 8109mm.
Di laser rangefinder dey for di back of di sensor, di opposite side to di Grove socket.
Dis na I2C sensor.
Connect di time of flight sensor
Di Grove time of flight sensor fit connect to di Wio Terminal.
Task - connect di time of flight sensor
Connect di time of flight sensor.
-
Put one end of di Grove cable inside di socket for di time of flight sensor. E go only fit enter one way.
-
Make sure say di Wio Terminal no dey connect to your computer or any power supply, then connect di other end of di Grove cable to di left-hand side Grove socket for di Wio Terminal as you dey look di screen. Dis socket dey near di power button. E be combined digital and I2C socket.
- Now, you fit connect di Wio Terminal to your computer.
Program di time of flight sensor
Di Wio Terminal don ready to program make e use di time of flight sensor wey you connect.
Task - program di time of flight sensor
-
Create new Wio Terminal project with PlatformIO. Name di project
distance-sensor. Add code for disetupfunction to configure di serial port. -
Add library dependency for di Seeed Grove time of flight distance sensor library to di project
platformio.inifile:lib_deps = seeed-studio/Grove Ranging sensor - VL53L0X @ ^1.1.1 -
For
main.cpp, add dis code under di existing include directives to declare one instance of diSeeed_vl53l0xclass wey go interact with di time of flight sensor:#include "Seeed_vl53l0x.h" Seeed_vl53l0x VL53L0X; -
Add dis code to di bottom of di
setupfunction to initialize di sensor:VL53L0X.VL53L0X_common_init(); VL53L0X.VL53L0X_high_accuracy_ranging_init(); -
For di
loopfunction, read one value from di sensor:VL53L0X_RangingMeasurementData_t RangingMeasurementData; memset(&RangingMeasurementData, 0, sizeof(VL53L0X_RangingMeasurementData_t)); VL53L0X.PerformSingleRangingMeasurement(&RangingMeasurementData);Dis code dey initialize one data structure to read data inside, then e go pass am into di
PerformSingleRangingMeasurementmethod wey go populate am with di distance measurement. -
After dis one, write di distance measurement, then delay for 1 second:
Serial.print("Distance = "); Serial.print(RangingMeasurementData.RangeMilliMeter); Serial.println(" mm"); delay(1000); -
Build, upload and run dis code. You go fit see di distance measurements for di serial monitor. Put objects near di sensor and you go see di distance measurement:
Distance = 29 mm Distance = 28 mm Distance = 30 mm Distance = 151 mmDi rangefinder dey for di back of di sensor, so make sure say you use di correct side when you dey measure distance.
💁 You fit find dis code for di code-proximity/wio-terminal folder.
😀 Your proximity sensor program don work well!
Disclaimer:
Dis docu don use AI translation service Co-op Translator take translate am. Even though we dey try make e accurate, abeg no forget say automatic translation fit get mistake or no correct well. Di original docu for di language wey dem write am first na di main correct one. For important information, e good make una use professional human translation. We no go fit take blame for any misunderstanding or wrong interpretation wey fit happen because of dis translation.


