Sample application, using the X_Nucleo_53L0A1 library, to display range results from the X-NUCLEO-53L0A1 central sensor on the 4-digit LED display.

Dependencies:   mbed X_NUCLEO_53L0A1

Fork of Display_53L0A1 by ST Expansion SW Team

Sample application displaying range results on the 4-digit LED display. Uses the Centre sensor and ranges in singleshot_polling mode.

Committer:
johnAlexander
Date:
Mon Aug 07 14:33:34 2017 +0000
Revision:
2:4734d8c307b8
Parent:
1:c1c10e0c32b2
Child:
3:b8dbd5b99a02
Aligned to ARM mbed coding style.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
johnAlexander 2:4734d8c307b8 1 /*
johnAlexander 1:c1c10e0c32b2 2 * This VL53L0X Expansion board test application performs range measurements
johnAlexander 2:4734d8c307b8 3 * using the onboard embedded centre sensor, in singleshot, polling mode.
johnAlexander 1:c1c10e0c32b2 4 * Measured ranges are displayed on the on-board 4-digit display.
johnAlexander 1:c1c10e0c32b2 5 *
johnAlexander 2:4734d8c307b8 6 * The User Blue button stops the current measurement and entire program,
johnAlexander 1:c1c10e0c32b2 7 * releasing all resources.
johnAlexander 1:c1c10e0c32b2 8 *
johnAlexander 2:4734d8c307b8 9 * The Reset button can be used to restart the program.
johnAlexander 1:c1c10e0c32b2 10 */
johnAlexander 1:c1c10e0c32b2 11
johnAlexander 1:c1c10e0c32b2 12 #include <string.h>
johnAlexander 1:c1c10e0c32b2 13 #include <stdio.h>
johnAlexander 1:c1c10e0c32b2 14
johnAlexander 0:cd8e818d4288 15 #include "mbed.h"
johnAlexander 0:cd8e818d4288 16 #include "x_nucleo_53l0a1.h"
johnAlexander 2:4734d8c307b8 17 #include "vl53l0x_class.h"
johnAlexander 0:cd8e818d4288 18
johnAlexander 2:4734d8c307b8 19 #define VL53L0_I2C_SDA D14
johnAlexander 2:4734d8c307b8 20 #define VL53L0_I2C_SCL D15
johnAlexander 0:cd8e818d4288 21
johnAlexander 1:c1c10e0c32b2 22 static X_NUCLEO_53L0A1 *board = NULL;
johnAlexander 0:cd8e818d4288 23 VL53L0X_RangingMeasurementData_t data_sensor_centre;
johnAlexander 0:cd8e818d4288 24 OperatingMode operating_mode;
johnAlexander 2:4734d8c307b8 25
johnAlexander 0:cd8e818d4288 26 /* flags that handle interrupt request */
johnAlexander 2:4734d8c307b8 27 bool int_stop_measure = false;
johnAlexander 0:cd8e818d4288 28
johnAlexander 0:cd8e818d4288 29 /* ISR callback function of the user blue button to stop program */
johnAlexander 2:4734d8c307b8 30 void stop_measure_irq(void)
johnAlexander 0:cd8e818d4288 31 {
johnAlexander 2:4734d8c307b8 32 int_stop_measure = true;
johnAlexander 0:cd8e818d4288 33 }
johnAlexander 0:cd8e818d4288 34
johnAlexander 0:cd8e818d4288 35 /* On board 4 digit local display refresh */
johnAlexander 2:4734d8c307b8 36 void display_refresh(VL53L0X_RangingMeasurementData_t sensor_range_data)
johnAlexander 2:4734d8c307b8 37 {
johnAlexander 2:4734d8c307b8 38 char str[5];
johnAlexander 2:4734d8c307b8 39
johnAlexander 2:4734d8c307b8 40 if (sensor_range_data.RangeStatus == 0) { // we have a valid range.
johnAlexander 2:4734d8c307b8 41 sprintf(str, "%d", sensor_range_data.RangeMilliMeter);
johnAlexander 2:4734d8c307b8 42 } else {
johnAlexander 2:4734d8c307b8 43 sprintf(str, "%s", "----");
johnAlexander 2:4734d8c307b8 44 }
johnAlexander 2:4734d8c307b8 45
johnAlexander 2:4734d8c307b8 46 board->display->display_string(str);
johnAlexander 0:cd8e818d4288 47 }
johnAlexander 0:cd8e818d4288 48
johnAlexander 1:c1c10e0c32b2 49 /*=================================== Main ==================================
johnAlexander 2:4734d8c307b8 50 Press the blue user button to stop measurements in progress
johnAlexander 1:c1c10e0c32b2 51 =============================================================================*/
johnAlexander 1:c1c10e0c32b2 52 int main()
johnAlexander 1:c1c10e0c32b2 53 {
johnAlexander 1:c1c10e0c32b2 54 #if USER_BUTTON == PC_13 // we are cross compiling for Nucleo-f401
johnAlexander 2:4734d8c307b8 55 InterruptIn stop_button(USER_BUTTON);
johnAlexander 2:4734d8c307b8 56 stop_button.rise(&stop_measure_irq);
johnAlexander 2:4734d8c307b8 57 #endif
johnAlexander 2:4734d8c307b8 58
johnAlexander 2:4734d8c307b8 59 DevI2C *device_i2c = new DevI2C(VL53L0_I2C_SDA, VL53L0_I2C_SCL);
johnAlexander 2:4734d8c307b8 60 int status;
johnAlexander 2:4734d8c307b8 61
johnAlexander 2:4734d8c307b8 62 /* creates the 53L0A1 expansion board singleton obj */
johnAlexander 2:4734d8c307b8 63 board = X_NUCLEO_53L0A1::instance(device_i2c, A2, D8, D2);
johnAlexander 1:c1c10e0c32b2 64
johnAlexander 2:4734d8c307b8 65 board->display->display_string("53L0");
johnAlexander 2:4734d8c307b8 66 /* init the 53L0A1 expansion board with default values */
johnAlexander 2:4734d8c307b8 67 status = board->init_board();
johnAlexander 2:4734d8c307b8 68 if (status)
johnAlexander 2:4734d8c307b8 69 printf("Failed to init board!\n\r");
johnAlexander 2:4734d8c307b8 70 operating_mode = range_single_shot_polling;
johnAlexander 2:4734d8c307b8 71 /* start the measure on sensor centre */
johnAlexander 2:4734d8c307b8 72 status = board->sensor_centre->start_measurement(operating_mode, NULL);
johnAlexander 2:4734d8c307b8 73 if (!status) {
johnAlexander 2:4734d8c307b8 74 while (1) { // infinite loop. can be broken by pressing Blue (User) button.
johnAlexander 2:4734d8c307b8 75 status = board->sensor_centre->get_measurement(operating_mode, &data_sensor_centre);
johnAlexander 2:4734d8c307b8 76 display_refresh(data_sensor_centre);
johnAlexander 2:4734d8c307b8 77 if (int_stop_measure) { // Blue Button isr was triggered
johnAlexander 2:4734d8c307b8 78 status = board->sensor_centre->stop_measurement(operating_mode); // stop the measure and exit
johnAlexander 2:4734d8c307b8 79 int_stop_measure = false;
johnAlexander 2:4734d8c307b8 80 printf("\nProgram stopped!\n\n\r");
johnAlexander 2:4734d8c307b8 81 break;
johnAlexander 2:4734d8c307b8 82 }
johnAlexander 2:4734d8c307b8 83 }
johnAlexander 2:4734d8c307b8 84 }
johnAlexander 2:4734d8c307b8 85 board->display->display_string("BYE");
johnAlexander 2:4734d8c307b8 86 delete board;
johnAlexander 0:cd8e818d4288 87 }