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:
Fri Jun 09 07:21:19 2017 +0000
Revision:
0:cd8e818d4288
Child:
1:c1c10e0c32b2
Sample application, using the X_Nucleo_53L0A1 library, to display range results from the central sensor of X-NUCLEO-53L0A1 board on the 4-digit LED display.

Who changed what in which revision?

UserRevisionLine numberNew contents of line
johnAlexander 0:cd8e818d4288 1 #include "mbed.h"
johnAlexander 0:cd8e818d4288 2 #include "x_nucleo_53l0a1.h"
johnAlexander 0:cd8e818d4288 3 #include <string.h>
johnAlexander 0:cd8e818d4288 4 #include <stdlib.h>
johnAlexander 0:cd8e818d4288 5 #include <stdio.h>
johnAlexander 0:cd8e818d4288 6 #include <assert.h>
johnAlexander 0:cd8e818d4288 7
johnAlexander 0:cd8e818d4288 8 /* This VL53L0X Expansion board test application performs a range measurement in polling mode
johnAlexander 0:cd8e818d4288 9 on the onboard embedded top sensor.
johnAlexander 0:cd8e818d4288 10 The measured data is displayed on the on-board 4-digit display.
johnAlexander 0:cd8e818d4288 11
johnAlexander 0:cd8e818d4288 12 User Blue button stops the current measurement and the entire program, releasing all resources.
johnAlexander 0:cd8e818d4288 13 Reset button is used to restart the program. */
johnAlexander 0:cd8e818d4288 14
johnAlexander 0:cd8e818d4288 15 /* Polling operating modes don`t require callback function that handles IRQ
johnAlexander 0:cd8e818d4288 16 Callback IRQ functions are used only for measure that require interrupt */
johnAlexander 0:cd8e818d4288 17
johnAlexander 0:cd8e818d4288 18 /* GetMeasurement is asynchronous! It returns NOT_READY if the measurement value
johnAlexander 0:cd8e818d4288 19 is not ready to be read from the corresponding register. So you need to wait
johnAlexander 0:cd8e818d4288 20 for the result to be ready */
johnAlexander 0:cd8e818d4288 21
johnAlexander 0:cd8e818d4288 22 #define VL53L0_I2C_SDA D14
johnAlexander 0:cd8e818d4288 23 #define VL53L0_I2C_SCL D15
johnAlexander 0:cd8e818d4288 24
johnAlexander 0:cd8e818d4288 25 #define RANGE 0
johnAlexander 0:cd8e818d4288 26
johnAlexander 0:cd8e818d4288 27 static X_NUCLEO_53L0A1 *board=NULL;
johnAlexander 0:cd8e818d4288 28 VL53L0X_RangingMeasurementData_t data_sensor_centre;
johnAlexander 0:cd8e818d4288 29 OperatingMode operating_mode;
johnAlexander 0:cd8e818d4288 30
johnAlexander 0:cd8e818d4288 31 /* flags that handle interrupt request */
johnAlexander 0:cd8e818d4288 32 bool int_sensor_centre=false, int_stop_measure=false;
johnAlexander 0:cd8e818d4288 33
johnAlexander 0:cd8e818d4288 34 /* ISR callback function of the sensor_centre */
johnAlexander 0:cd8e818d4288 35 void SensorTopIRQ(void)
johnAlexander 0:cd8e818d4288 36 {
johnAlexander 0:cd8e818d4288 37 int_sensor_centre=true;
johnAlexander 0:cd8e818d4288 38 board->sensor_centre->DisableInterruptMeasureDetectionIRQ();
johnAlexander 0:cd8e818d4288 39 }
johnAlexander 0:cd8e818d4288 40
johnAlexander 0:cd8e818d4288 41 /* ISR callback function of the user blue button to stop program */
johnAlexander 0:cd8e818d4288 42 void StopMeasureIRQ(void)
johnAlexander 0:cd8e818d4288 43 {
johnAlexander 0:cd8e818d4288 44 int_stop_measure=true;
johnAlexander 0:cd8e818d4288 45 }
johnAlexander 0:cd8e818d4288 46
johnAlexander 0:cd8e818d4288 47 /* On board 4 digit local display refresh */
johnAlexander 0:cd8e818d4288 48 void DisplayRefresh(OperatingMode op_mode)
johnAlexander 0:cd8e818d4288 49 {
johnAlexander 0:cd8e818d4288 50 char str[5];
johnAlexander 0:cd8e818d4288 51
johnAlexander 0:cd8e818d4288 52 if (op_mode==range_single_shot_polling || op_mode==range_continuous_interrupt || op_mode==range_continuous_polling)
johnAlexander 0:cd8e818d4288 53 {
johnAlexander 0:cd8e818d4288 54 if (data_sensor_centre.RangeStatus == 0) // we have a valid range.
johnAlexander 0:cd8e818d4288 55 {
johnAlexander 0:cd8e818d4288 56 sprintf(str,"%d",data_sensor_centre.RangeMilliMeter);
johnAlexander 0:cd8e818d4288 57 }
johnAlexander 0:cd8e818d4288 58 else
johnAlexander 0:cd8e818d4288 59 {
johnAlexander 0:cd8e818d4288 60 sprintf(str,"%s","----");
johnAlexander 0:cd8e818d4288 61 }
johnAlexander 0:cd8e818d4288 62 }
johnAlexander 0:cd8e818d4288 63
johnAlexander 0:cd8e818d4288 64 board->display->DisplayString(str);
johnAlexander 0:cd8e818d4288 65 }
johnAlexander 0:cd8e818d4288 66
johnAlexander 0:cd8e818d4288 67 void RangeMeasure(DevI2C *device_i2c) {
johnAlexander 0:cd8e818d4288 68 int status;
johnAlexander 0:cd8e818d4288 69
johnAlexander 0:cd8e818d4288 70 /* creates the 53L0A1 expansion board singleton obj */
johnAlexander 0:cd8e818d4288 71 board=X_NUCLEO_53L0A1::Instance(device_i2c, A2, D8, D2);
johnAlexander 0:cd8e818d4288 72
johnAlexander 0:cd8e818d4288 73 board->display->DisplayString("53L0");
johnAlexander 0:cd8e818d4288 74 /* init the 53L0A1 expansion board with default values */
johnAlexander 0:cd8e818d4288 75 status=board->InitBoard();
johnAlexander 0:cd8e818d4288 76 if(status)
johnAlexander 0:cd8e818d4288 77 printf("Failed to init board!\n\r");
johnAlexander 0:cd8e818d4288 78 operating_mode=range_single_shot_polling;
johnAlexander 0:cd8e818d4288 79 /* start the measure on sensor top */
johnAlexander 0:cd8e818d4288 80 status=board->sensor_centre->StartMeasurement(operating_mode, SensorTopIRQ);
johnAlexander 0:cd8e818d4288 81 if(!status)
johnAlexander 0:cd8e818d4288 82 {
johnAlexander 0:cd8e818d4288 83 while(1)
johnAlexander 0:cd8e818d4288 84 {
johnAlexander 0:cd8e818d4288 85 status=board->sensor_centre->GetMeasurement(operating_mode, &data_sensor_centre);
johnAlexander 0:cd8e818d4288 86 DisplayRefresh(operating_mode);
johnAlexander 0:cd8e818d4288 87 if(int_stop_measure) // Blue Button isr was triggered
johnAlexander 0:cd8e818d4288 88 {
johnAlexander 0:cd8e818d4288 89 status=board->sensor_centre->StopMeasurement(operating_mode); // stop the measure and exit
johnAlexander 0:cd8e818d4288 90 int_stop_measure = false;
johnAlexander 0:cd8e818d4288 91 printf("\nProgram stopped!\n\n\r");
johnAlexander 0:cd8e818d4288 92 break;
johnAlexander 0:cd8e818d4288 93 }
johnAlexander 0:cd8e818d4288 94 }
johnAlexander 0:cd8e818d4288 95 }
johnAlexander 0:cd8e818d4288 96 board->display->DisplayString("BYE");
johnAlexander 0:cd8e818d4288 97 delete board;
johnAlexander 0:cd8e818d4288 98 }
johnAlexander 0:cd8e818d4288 99
johnAlexander 0:cd8e818d4288 100 /*=================================== Main ==================================
johnAlexander 0:cd8e818d4288 101 Press the blue user button to stop the measurements in progress
johnAlexander 0:cd8e818d4288 102 =============================================================================*/
johnAlexander 0:cd8e818d4288 103 int main()
johnAlexander 0:cd8e818d4288 104 {
johnAlexander 0:cd8e818d4288 105 #if USER_BUTTON==PC_13 // we are cross compiling for Nucleo-f401
johnAlexander 0:cd8e818d4288 106 InterruptIn stop_button (USER_BUTTON);
johnAlexander 0:cd8e818d4288 107 stop_button.rise (&StopMeasureIRQ);
johnAlexander 0:cd8e818d4288 108 #endif
johnAlexander 0:cd8e818d4288 109 DevI2C *device_i2c =new DevI2C(VL53L0_I2C_SDA, VL53L0_I2C_SCL);
johnAlexander 0:cd8e818d4288 110
johnAlexander 0:cd8e818d4288 111 RangeMeasure(device_i2c); // start continuous measures
johnAlexander 0:cd8e818d4288 112 }
johnAlexander 0:cd8e818d4288 113