-
Notifications
You must be signed in to change notification settings - Fork 2k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
tests: add VL53L1X ToF ranging sensor
- Loading branch information
Showing
2 changed files
with
58 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
include ../Makefile.tests_common | ||
|
||
USEMODULE += vl53l1x | ||
USEMODULE += periph_i2c | ||
USEMODULE += xtimer | ||
|
||
include $(RIOTBASE)/Makefile.include |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
/* | ||
* Copyright (C) 2018 Gunar Schorcht | ||
* | ||
* This file is subject to the terms and conditions of the GNU Lesser | ||
* General Public License v2.1. See the file LICENSE in the top level | ||
* directory for more details. | ||
*/ | ||
|
||
/** | ||
* @ingroup tests | ||
* @brief Test application for ST VL53L1X Time-of-Flight distance sensor | ||
* @author Gunar Schorcht <gunar@schorcht.net> | ||
* @file | ||
* | ||
*/ | ||
|
||
#include <stdio.h> | ||
#include "xtimer.h" | ||
|
||
#include "vl53l1x.h" | ||
#include "vl53l1x_params.h" | ||
|
||
int main(void) | ||
{ | ||
/* Initialize the sensor */ | ||
vl53l1x_t dev; | ||
|
||
/* initialize the sensor */ | ||
puts("VL53L1X Time-of-Flight distance sensor\n"); | ||
puts("Initializing VL53L1X sensor"); | ||
|
||
if (vl53l1x_init(&dev, &vl53l1x_params[0]) == VL53L1X_OK) { | ||
printf("[OK]\n"); | ||
} | ||
else { | ||
printf("[Failed]\n"); | ||
return 1; | ||
} | ||
|
||
while (1) { | ||
xtimer_usleep(50 * US_PER_MS); | ||
|
||
int16_t data; | ||
if (vl53l1x_data_ready(&dev) == VL53L1X_OK && | ||
vl53l1x_read(&dev, &data) == VL53L1X_OK) { | ||
printf("range=%d [mm]\n", data); | ||
} | ||
} | ||
|
||
return 0; | ||
} |