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:
Davidroid
Date:
Tue Aug 22 14:42:10 2017 +0000
Revision:
10:891e10d3b4a6
Parent:
9:9733cfdb0a18
Updating with the new version of the library.

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>
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
Davidroid 10:891e10d3b4a6 11 static XNucleo53L0A1 *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 9:9733cfdb0a18 22
johnAlexander 7:c8087e7333b8 23 /* creates the 53L0A1 expansion board singleton obj */
Davidroid 10:891e10d3b4a6 24 board = XNucleo53L0A1::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 9:9733cfdb0a18 28 if (status) {
Davidroid 10:891e10d3b4a6 29 printf("Failed to init board!\r\n");
johnAlexander 7:c8087e7333b8 30 return 0;
johnAlexander 7:c8087e7333b8 31 }
johnAlexander 4:c8932fb926d6 32
johnAlexander 9:9733cfdb0a18 33 while (1) {
johnAlexander 7:c8087e7333b8 34 status = board->sensor_centre->get_distance(&distance);
johnAlexander 9:9733cfdb0a18 35 if (status == VL53L0X_ERROR_NONE) {
Davidroid 10:891e10d3b4a6 36 printf("Distance : %ld\r\n", distance);
johnAlexander 7:c8087e7333b8 37 }
johnAlexander 4:c8932fb926d6 38 }
johnAlexander 0:ce8359133ae6 39 }