Simple application showing central sensor on X_NUCLEO_53L0A1 expansion board being polled in singleshot mode, to display ranging measure on USB serial.

Dependencies:   X_NUCLEO_53L0A1 mbed

Fork of HelloWorld_53L0A1 by ST Expansion SW Team

X-Nucleo-53L0A1 Hello World Application

This application provides a simple example of usage of X_NUCLEO_53L0A1 library. It provides a measurement of:

  • Distance (millimeters) of an object in front of the on-board sensor.

The values are displayed on the Hyperterminal connected through COM port over USB.

Committer:
johnAlexander
Date:
Mon Aug 07 14:54:55 2017 +0000
Revision:
9:9733cfdb0a18
Align application & library to ARM mbed coding style.

Who changed what in which revision?

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