![](/media/cache/profiles/ibmfp2.jpg.50x50_q85.jpg)
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
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.
main.cpp@3:b3f70617a6b3, 2016-12-01 (annotated)
- Committer:
- johnAlexander
- Date:
- Thu Dec 01 14:19:01 2016 +0000
- Revision:
- 3:b3f70617a6b3
- Parent:
- 1:3483e701ec59
- Child:
- 4:c8932fb926d6
Simplify example, to be simplest possible ranging example. Print range measurements rather than send them to the 4-digit display.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
johnAlexander | 0:ce8359133ae6 | 1 | #include "mbed.h" |
johnAlexander | 0:ce8359133ae6 | 2 | #include "x_nucleo_53l0a1.h" |
johnAlexander | 0:ce8359133ae6 | 3 | #include <string.h> |
johnAlexander | 0:ce8359133ae6 | 4 | #include <stdlib.h> |
johnAlexander | 0:ce8359133ae6 | 5 | #include <stdio.h> |
johnAlexander | 0:ce8359133ae6 | 6 | #include <assert.h> |
johnAlexander | 0:ce8359133ae6 | 7 | |
johnAlexander | 1:3483e701ec59 | 8 | /* This VL53L0X Expansion board test application performs a range measurement in polling mode |
johnAlexander | 0:ce8359133ae6 | 9 | on the onboard embedded top sensor. |
johnAlexander | 1:3483e701ec59 | 10 | The measured data is displayed on the on-board 4-digit display. |
johnAlexander | 0:ce8359133ae6 | 11 | |
johnAlexander | 1:3483e701ec59 | 12 | User Blue button stops the current measurement and the entire program, releasing all resources. |
johnAlexander | 0:ce8359133ae6 | 13 | Reset button is used to restart the program. */ |
johnAlexander | 0:ce8359133ae6 | 14 | |
johnAlexander | 0:ce8359133ae6 | 15 | /* Polling operating modes don`t require callback function that handles IRQ |
johnAlexander | 0:ce8359133ae6 | 16 | Callback IRQ functions are used only for measure that require interrupt */ |
johnAlexander | 0:ce8359133ae6 | 17 | |
johnAlexander | 0:ce8359133ae6 | 18 | /* GetMeasurement is asynchronous! It returns NOT_READY if the measurement value |
johnAlexander | 0:ce8359133ae6 | 19 | is not ready to be read from the corresponding register. So you need to wait |
johnAlexander | 0:ce8359133ae6 | 20 | for the result to be ready */ |
johnAlexander | 0:ce8359133ae6 | 21 | |
johnAlexander | 0:ce8359133ae6 | 22 | #define VL53L0_I2C_SDA D14 |
johnAlexander | 0:ce8359133ae6 | 23 | #define VL53L0_I2C_SCL D15 |
johnAlexander | 0:ce8359133ae6 | 24 | |
johnAlexander | 0:ce8359133ae6 | 25 | static X_NUCLEO_53L0A1 *board=NULL; |
johnAlexander | 1:3483e701ec59 | 26 | |
johnAlexander | 0:ce8359133ae6 | 27 | |
johnAlexander | 0:ce8359133ae6 | 28 | /*=================================== Main ================================== |
johnAlexander | 0:ce8359133ae6 | 29 | =============================================================================*/ |
johnAlexander | 0:ce8359133ae6 | 30 | int main() |
johnAlexander | 0:ce8359133ae6 | 31 | { |
johnAlexander | 3:b3f70617a6b3 | 32 | int status; |
johnAlexander | 3:b3f70617a6b3 | 33 | uint32_t distance; |
johnAlexander | 3:b3f70617a6b3 | 34 | DevI2C *device_i2c =new DevI2C(VL53L0_I2C_SDA, VL53L0_I2C_SCL); |
johnAlexander | 3:b3f70617a6b3 | 35 | |
johnAlexander | 3:b3f70617a6b3 | 36 | /* creates the 53L0A1 expansion board singleton obj */ |
johnAlexander | 3:b3f70617a6b3 | 37 | board=X_NUCLEO_53L0A1::Instance(device_i2c, A2, D8, D2); |
johnAlexander | 3:b3f70617a6b3 | 38 | |
johnAlexander | 3:b3f70617a6b3 | 39 | /* init the 53L0A1 expansion board with default values */ |
johnAlexander | 3:b3f70617a6b3 | 40 | status=board->InitBoard(); |
johnAlexander | 3:b3f70617a6b3 | 41 | if(status) { printf("Failed to init board!\n\r"); return 0; } |
johnAlexander | 3:b3f70617a6b3 | 42 | while(1) |
johnAlexander | 3:b3f70617a6b3 | 43 | { |
johnAlexander | 3:b3f70617a6b3 | 44 | board->sensor_centre->GetDistance(&distance); |
johnAlexander | 3:b3f70617a6b3 | 45 | printf("Distance : %ld\n", distance); |
johnAlexander | 3:b3f70617a6b3 | 46 | } |
johnAlexander | 0:ce8359133ae6 | 47 | } |
johnAlexander | 0:ce8359133ae6 | 48 |