Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: X_NUCLEO_53L1A2
Revision 12:140677759b2c, committed 2021-06-18
- Comitter:
- johnAlexander
- Date:
- Fri Jun 18 10:23:52 2021 +0000
- Parent:
- 11:818b711eb4ae
- Commit message:
- Initial release, using VL53L1 sensor class.
Changed in this revision
| X_NUCLEO_53L1A2.lib | Show annotated file Show diff for this revision Revisions of this file |
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
--- a/X_NUCLEO_53L1A2.lib Fri Jun 11 17:20:34 2021 +0100 +++ b/X_NUCLEO_53L1A2.lib Fri Jun 18 10:23:52 2021 +0000 @@ -1,1 +1,1 @@ -https://os.mbed.com/teams/ST-Expansion-SW-Team/code/X_NUCLEO_53L1A2/#3e19c89acda7 +https://os.mbed.com/teams/ST-Expansion-SW-Team/code/X_NUCLEO_53L1A2/#57998dc85ed4
--- a/main.cpp Fri Jun 11 17:20:34 2021 +0100
+++ b/main.cpp Fri Jun 18 10:23:52 2021 +0000
@@ -69,9 +69,15 @@
VL53L1_Dev_t devCentre;
-VL53L1_DEV Dev = &devCentre;
+VL53L1_DEV DevC = &devCentre;
+
+VL53L1_Dev_t devLeft;
+VL53L1_DEV DevL = &devLeft;
-VL53L1CB *Sensor;
+VL53L1_Dev_t devRight;
+VL53L1_DEV DevR = &devRight;
+
+VL53L1 *Sensor;
@@ -91,30 +97,55 @@
{
int status = 0;
- Dev=&devCentre;
- Sensor=board->sensor_centre;
+ DevC=&devCentre;
+ DevC->comms_speed_khz = 400;
+ DevC->comms_type = 1;
+ DevC->i2c_slave_address = NEW_SENSOR_CENTRE_ADDRESS;
+ devCentre.i2c_slave_address = NEW_SENSOR_CENTRE_ADDRESS;
+// Sensor=board->sensor_centre;
+ DevL=&devLeft;
+// Sensor=board->sensor_left;
// configure the sensors
- Dev->comms_speed_khz = 400;
- Dev->comms_type = 1;
- Dev->i2c_slave_address = NEW_SENSOR_CENTRE_ADDRESS;
+ DevL->comms_speed_khz = 400;
+ DevL->comms_type = 1;
+ DevL->i2c_slave_address = NEW_SENSOR_LEFT_ADDRESS;
+ devLeft.i2c_slave_address = NEW_SENSOR_LEFT_ADDRESS;
- printf("configuring centre channel \n");
+ DevR=&devLeft;
+ // configure the sensors
+ DevR->comms_speed_khz = 400;
+ DevR->comms_type = 1;
+ DevR->i2c_slave_address = NEW_SENSOR_RIGHT_ADDRESS;
+ devRight.i2c_slave_address = NEW_SENSOR_RIGHT_ADDRESS;
- /* Device Initialization and setting */
- status = Sensor->VL53L1CB_DataInit();
- status = Sensor->VL53L1CB_StaticInit();
-
- status = Sensor->VL53L1CB_SetPresetMode(VL53L1_PRESETMODE_AUTONOMOUS);
- status = Sensor->VL53L1CB_SetDistanceMode(VL53L1_DISTANCEMODE_LONG);
+ for (int i = 0; i < 3; i++)
+ {
+ if (i == 0) { Sensor=board->sensor_centre; }
+ if (i == 1) { Sensor=board->sensor_left; }
+ if (i == 2) { Sensor=board->sensor_right; }
+
+ if (Sensor != NULL)
+ {
+ if (i == 0) { printf("configuring centre channel \n"); }
+ if (i == 1) { printf("configuring left channel \n"); }
+ if (i == 2) { printf("configuring right channel \n"); }
+
+ /* Device Initialization and setting */
+ status = Sensor->vl53L1_DataInit();
+ status = Sensor->vl53L1_StaticInit();
- status = Sensor->VL53L1CB_SetInterMeasurementPeriodMilliSeconds(500);
+ status = Sensor->vl53L1_SetPresetMode(VL53L1_PRESETMODE_AUTONOMOUS);
+ status = Sensor->vl53L1_SetDistanceMode(VL53L1_DISTANCEMODE_LONG);
- status = Sensor->VL53L1CB_SetMeasurementTimingBudgetMicroSeconds(45000);
+ status = Sensor->vl53L1_SetInterMeasurementPeriodMilliSeconds(500);
- status = Sensor->VL53L1CB_SetSequenceStepEnable(VL53L1_SEQUENCESTEP_MM1, 0);
- status = Sensor->VL53L1CB_SetSequenceStepEnable(VL53L1_SEQUENCESTEP_MM2, 0);
+ status = Sensor->vl53L1_SetMeasurementTimingBudgetMicroSeconds(45000);
+ 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) {
@@ -123,11 +154,38 @@
return status;
}
- status = Sensor->VL53L1CB_StartMeasurement();
+ status = board->sensor_centre->vl53L1_StartMeasurement();
if (status != 0) {
return status;
}
}
+
+ // create interrupt handler and start measurements
+ if (board->sensor_left!= NULL) {
+ status = board->sensor_left->stop_measurement();
+ if (status != 0) {
+ return status;
+ }
+
+ status = board->sensor_left->vl53L1_StartMeasurement();
+ if (status != 0) {
+ return status;
+ }
+ }
+
+ // create interrupt handler and start measurements
+ if (board->sensor_right!= NULL) {
+ status = board->sensor_right->stop_measurement();
+ if (status != 0) {
+ return status;
+ }
+
+ status = board->sensor_right->vl53L1_StartMeasurement();
+ if (status != 0) {
+ return status;
+ }
+ }
+
return status;
}
@@ -178,16 +236,39 @@
while (true) {
pMultiRangingData = &MultiRangingData;
- status = board->sensor_centre->VL53L1CB_WaitMeasurementDataReady();
-// if (int_sensor) {
-// int_sensor = false;
- status = board->sensor_centre->VL53L1CB_GetMultiRangingData( pMultiRangingData);
-
- print_results( devCentre.i2c_slave_address, pMultiRangingData );
-
- status = board->sensor_centre->VL53L1CB_ClearInterrupt();
-// board->sensor_centre->enable_interrupt_measure_detection_irq();
-// }
+ if (board->sensor_centre!= NULL) {
+ printf("Range result from Centre sensor\n");
+ status = board->sensor_centre->vl53L1_WaitMeasurementDataReady();
+
+ status = board->sensor_centre->vl53L1_GetMultiRangingData( pMultiRangingData);
+
+ print_results( devCentre.i2c_slave_address, pMultiRangingData );
+
+ status = board->sensor_centre->VL53L1_ClearInterrupt();
+ }
+
+ if (board->sensor_left!= NULL) {
+ printf("Range result from Left Satellite\n");
+ status = board->sensor_left->vl53L1_WaitMeasurementDataReady();
+
+ status = board->sensor_left->vl53L1_GetMultiRangingData( pMultiRangingData);
+
+ print_results( devLeft.i2c_slave_address, pMultiRangingData );
+
+ status = board->sensor_left->VL53L1_ClearInterrupt();
+ }
+
+ // create interrupt handler and start measurements
+ if (board->sensor_right!= NULL) {
+ printf("Range result from Right Satellite\n");
+ status = board->sensor_right->vl53L1_WaitMeasurementDataReady();
+
+ status = board->sensor_right->vl53L1_GetMultiRangingData( pMultiRangingData);
+
+ print_results( devRight.i2c_slave_address, pMultiRangingData );
+
+ status = board->sensor_right->VL53L1_ClearInterrupt();
+ }
}
printf("Terminating.\n");
@@ -202,9 +283,12 @@
int ambient_rate = 0;
int RoiNumber = pMultiRangingData->RoiNumber;
+
+ printf("no_of_object_found : %d\n", no_of_object_found);
if (( no_of_object_found < 10 ) && ( no_of_object_found != 0)) {
for(int j=0; j<no_of_object_found; j++) {
+ printf("RangeStatus : %d\n", pMultiRangingData->RangeData[j].RangeStatus);
if ((pMultiRangingData->RangeData[j].RangeStatus == VL53L1_RANGESTATUS_RANGE_VALID) ||
(pMultiRangingData->RangeData[j].RangeStatus == VL53L1_RANGESTATUS_RANGE_VALID_NO_WRAP_CHECK_FAIL)) {
signal_rate = pMultiRangingData->RangeData[j].SignalRateRtnMegaCps / 65535;