Test an Adafruit single VL53L0X breakout board using the mbed LPC1768 and print distance measurement to PC

Dependencies:   X_NUCLEO_53L0A1 mbed

Fork of HelloWorld_53L0A1 by ST

https://os.mbed.com/users/kbeck8/notebook/alternative-control-for-remote-control-vehicle/ has a more complex example using three LIDAR breakouts for gesture detection on the same I2C bus using the shutdown pin (solves the issue of them having the same I2C address). The driver has support for three, but an AND gate is required unless the driver is changed. DigitalOut pins turn shutdown on/off on each LIDAR.

Committer:
johnAlexander
Date:
Mon Aug 07 14:45:59 2017 +0000
Revision:
7:c8087e7333b8
Parent:
4:c8932fb926d6
Child:
9:9733cfdb0a18
Align to ARM mbed coding style.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
johnAlexander 0:ce8359133ae6 1 #include "mbed.h"
johnAlexander 0:ce8359133ae6 2 #include "x_nucleo_53l0a1.h"
johnAlexander 0:ce8359133ae6 3 #include <stdio.h>
johnAlexander 0:ce8359133ae6 4
johnAlexander 1:3483e701ec59 5 /* This VL53L0X Expansion board test application performs a range measurement in polling mode
johnAlexander 4:c8932fb926d6 6 on the onboard embedded top sensor. */
johnAlexander 0:ce8359133ae6 7
johnAlexander 0:ce8359133ae6 8 #define VL53L0_I2C_SDA D14
johnAlexander 0:ce8359133ae6 9 #define VL53L0_I2C_SCL D15
johnAlexander 0:ce8359133ae6 10
johnAlexander 0:ce8359133ae6 11 static X_NUCLEO_53L0A1 *board=NULL;
johnAlexander 1:3483e701ec59 12
johnAlexander 0:ce8359133ae6 13
johnAlexander 0:ce8359133ae6 14 /*=================================== Main ==================================
johnAlexander 0:ce8359133ae6 15 =============================================================================*/
johnAlexander 0:ce8359133ae6 16 int main()
johnAlexander 0:ce8359133ae6 17 {
johnAlexander 4:c8932fb926d6 18 int status;
johnAlexander 4:c8932fb926d6 19 uint32_t distance;
johnAlexander 3:b3f70617a6b3 20
johnAlexander 7:c8087e7333b8 21 DevI2C *device_i2c = new DevI2C(VL53L0_I2C_SDA, VL53L0_I2C_SCL);
johnAlexander 4:c8932fb926d6 22
johnAlexander 7:c8087e7333b8 23 /* creates the 53L0A1 expansion board singleton obj */
johnAlexander 7:c8087e7333b8 24 board = X_NUCLEO_53L0A1::instance(device_i2c, A2, D8, D2);
johnAlexander 3:b3f70617a6b3 25
johnAlexander 7:c8087e7333b8 26 /* init the 53L0A1 expansion board with default values */
johnAlexander 7:c8087e7333b8 27 status = board->init_board();
johnAlexander 7:c8087e7333b8 28 if (status)
johnAlexander 7:c8087e7333b8 29 {
johnAlexander 7:c8087e7333b8 30 printf("Failed to init board!\n\r");
johnAlexander 7:c8087e7333b8 31 return 0;
johnAlexander 7:c8087e7333b8 32 }
johnAlexander 4:c8932fb926d6 33
johnAlexander 4:c8932fb926d6 34 while(1)
johnAlexander 4:c8932fb926d6 35 {
johnAlexander 7:c8087e7333b8 36 status = board->sensor_centre->get_distance(&distance);
johnAlexander 7:c8087e7333b8 37 if (status == VL53L0X_ERROR_NONE)
johnAlexander 7:c8087e7333b8 38 {
johnAlexander 4:c8932fb926d6 39 printf("Distance : %ld\n", distance);
johnAlexander 7:c8087e7333b8 40 }
johnAlexander 4:c8932fb926d6 41 }
johnAlexander 4:c8932fb926d6 42
johnAlexander 0:ce8359133ae6 43 }
johnAlexander 0:ce8359133ae6 44