VL53L1CB expansion board example, showing multi-ranges in an autonomous setup & polling mode. Uses the onboard sensor. Targets MbedOS v6.10.0.
Dependencies: X_NUCLEO_53L1A2
Diff: main.cpp
- Revision:
- 7:242f30acc456
- Parent:
- 6:19d56b30bfa7
- Child:
- 8:ac303cd2d35f
--- a/main.cpp Wed May 12 09:00:10 2021 +0000 +++ b/main.cpp Fri May 21 08:38:45 2021 +0000 @@ -50,10 +50,10 @@ // the satellite pins depend on solder blobs on the back of the shield. // they may not exist or may be one of two sets. // the centre pin always exists -PinName LeftIntPin = D8; +//PinName LeftIntPin = D8; PinName RightIntPin = D2; // alternate set -//PinName LeftIntPin = D9; +PinName LeftIntPin = D9; //PinName RightIntPin = D4; static XNucleo53L1A2 *board=NULL; @@ -104,24 +104,17 @@ /* Device Initialization and setting */ status = Sensor->vl53L1_DataInit(); status = Sensor->vl53L1_StaticInit(); + status = Sensor->vl53L1_SetPresetMode(VL53L1_PRESETMODE_AUTONOMOUS); status = Sensor->vl53L1_SetDistanceMode(VL53L1_DISTANCEMODE_LONG); - status = Sensor->vl53L1_SetMeasurementTimingBudgetMicroSeconds( 200 * 1000); - - // set the ranging and signal rate filter - VL53L1_DetectionConfig_t thresholdconfig; + status = Sensor->vl53L1_SetInterMeasurementPeriodMilliSeconds(500); - thresholdconfig.DetectionMode = VL53L1_DETECTION_DISTANCE_ONLY; /// type VL53L1_DetectionMode in vl53l1_def.h - thresholdconfig.Distance.CrossMode = VL53L1_THRESHOLD_IN_WINDOW; // type VL53L1_ThresholdMode. ignore if distance outside high and low - thresholdconfig.Distance.High = 300; // high distance in mm - thresholdconfig.Distance.Low = 200; // low distance in mm - thresholdconfig.Rate.CrossMode=0; // type VL53L1_ThresholdMode VL53L1_THRESHOLD_CROSSED_LOW VL53L1_THRESHOLD_CROSSED_HIGH VL53L1_THRESHOLD_OUT_OF_WINDOW VL53L1_THRESHOLD_IN_WINDOW - thresholdconfig.Rate.High = 0; - thresholdconfig.Rate.Low = 0; - thresholdconfig.IntrNoTarget = 0 ;// if 1 produce an interrupt even if there is no target found e.g out of range + status = Sensor->vl53L1_SetMeasurementTimingBudgetMicroSeconds(45000); - status = Sensor->vl53L1_SetThresholdConfig(&thresholdconfig); + status = Sensor->vl53L1_SetSequenceStepEnable(VL53L1_SEQUENCESTEP_MM1, 0); + status = Sensor->vl53L1_SetSequenceStepEnable(VL53L1_SEQUENCESTEP_MM2, 0); + // create interrupt handler and start measurements if (board->sensor_centre!= NULL) { @@ -188,17 +181,12 @@ if (int_sensor) { int_sensor = false; - status = board->sensor_centre->vl53L1_GetMultiRangingData( pMultiRangingData); - if (status == 0) { + status = board->sensor_centre->vl53L1_GetMultiRangingData( pMultiRangingData); + print_results( devCentre.i2c_slave_address, pMultiRangingData ); - } - status = board->sensor_centre->VL53L1_ClearInterrupt(); - board->sensor_centre->enable_interrupt_measure_detection_irq(); - } - if (int_stop) { - printf("\r\nEnding loop mode \r\n"); - break; + status = board->sensor_centre->VL53L1_ClearInterrupt(); + board->sensor_centre->enable_interrupt_measure_detection_irq(); } } @@ -209,11 +197,11 @@ // print what ever results are required void print_results( int devNumber, VL53L1_MultiRangingData_t *pMultiRangingData ) { - int no_of_object_found=pMultiRangingData->NumberOfObjectsFound; + int no_of_object_found = pMultiRangingData->NumberOfObjectsFound; int signal_rate = 0; int ambient_rate = 0; - int RoiNumber=pMultiRangingData->RoiNumber; + int RoiNumber = pMultiRangingData->RoiNumber; if (( no_of_object_found < 10 ) && ( no_of_object_found != 0)) { for(int j=0; j<no_of_object_found; j++) {