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:
4180_1
Date:
Thu Sep 07 00:01:45 2017 +0000
Revision:
11:5186cc367be0
Parent:
10:891e10d3b4a6
ver 1.0

Who changed what in which revision?

UserRevisionLine numberNew contents of line
johnAlexander 0:ce8359133ae6 1 #include "mbed.h"
Davidroid 10:891e10d3b4a6 2 #include "XNucleo53L0A1.h"
johnAlexander 0:ce8359133ae6 3 #include <stdio.h>
4180_1 11:5186cc367be0 4 Serial pc(USBTX,USBRX);
4180_1 11:5186cc367be0 5 DigitalOut shdn(p26);
4180_1 11:5186cc367be0 6 // This VL53L0X board test application performs a range measurement in polling mode
4180_1 11:5186cc367be0 7 // Use 3.3(Vout) for Vin, p28 for SDA, p27 for SCL, P26 for shdn on mbed LPC1768
johnAlexander 0:ce8359133ae6 8
4180_1 11:5186cc367be0 9 //I2C sensor pins
4180_1 11:5186cc367be0 10 #define VL53L0_I2C_SDA p28
4180_1 11:5186cc367be0 11 #define VL53L0_I2C_SCL p27
johnAlexander 0:ce8359133ae6 12
Davidroid 10:891e10d3b4a6 13 static XNucleo53L0A1 *board=NULL;
johnAlexander 1:3483e701ec59 14
johnAlexander 0:ce8359133ae6 15 int main()
4180_1 11:5186cc367be0 16 {
4180_1 11:5186cc367be0 17 int status;
4180_1 11:5186cc367be0 18 uint32_t distance;
johnAlexander 7:c8087e7333b8 19 DevI2C *device_i2c = new DevI2C(VL53L0_I2C_SDA, VL53L0_I2C_SCL);
johnAlexander 7:c8087e7333b8 20 /* creates the 53L0A1 expansion board singleton obj */
Davidroid 10:891e10d3b4a6 21 board = XNucleo53L0A1::instance(device_i2c, A2, D8, D2);
4180_1 11:5186cc367be0 22 shdn = 0; //must reset sensor for an mbed reset to work
4180_1 11:5186cc367be0 23 wait(0.1);
4180_1 11:5186cc367be0 24 shdn = 1;
4180_1 11:5186cc367be0 25 wait(0.1);
4180_1 11:5186cc367be0 26 /* init the 53L0A1 board with default values */
johnAlexander 7:c8087e7333b8 27 status = board->init_board();
4180_1 11:5186cc367be0 28 while (status) {
4180_1 11:5186cc367be0 29 pc.printf("Failed to init board! \r\n");
4180_1 11:5186cc367be0 30 status = board->init_board();
johnAlexander 7:c8087e7333b8 31 }
4180_1 11:5186cc367be0 32 //loop taking and printing distance
4180_1 11:5186cc367be0 33 while (1) {
johnAlexander 7:c8087e7333b8 34 status = board->sensor_centre->get_distance(&distance);
johnAlexander 9:9733cfdb0a18 35 if (status == VL53L0X_ERROR_NONE) {
4180_1 11:5186cc367be0 36 pc.printf("D=%ld mm\r\n", distance);
johnAlexander 7:c8087e7333b8 37 }
4180_1 11:5186cc367be0 38 }
johnAlexander 0:ce8359133ae6 39 }