Sample MBed program for use with ST XNucleo VL53L1CB board. Uses interrupts to cope with up to 3 sensors in lite ranging mode. Includes MBed V6.4

Dependencies:   X_NUCLEO_53L1A2

Fork of VL53L1CB_shield_3sensors_interrupt_lite_ranging_MB6 by charles macneill

Files at this revision

API Documentation at this revision

Comitter:
charlesmn
Date:
Mon Jun 14 08:14:59 2021 +0000
Parent:
3:e6741cadb1f1
Commit message:
change from vl53l1 library to vl53l1cb

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
diff -r e6741cadb1f1 -r 8c96fc85fa6b X_NUCLEO_53L1A2.lib
--- a/X_NUCLEO_53L1A2.lib	Fri Jun 11 18:00:10 2021 +0100
+++ b/X_NUCLEO_53L1A2.lib	Mon Jun 14 08:14:59 2021 +0000
@@ -1,1 +1,1 @@
-https://os.mbed.com/teams/ST-Expansion-SW-Team/code/X_NUCLEO_53L1A2/#adc4775416b0
+https://os.mbed.com/teams/ST-Expansion-SW-Team/code/X_NUCLEO_53L1A2/#52b8d3f21faa
diff -r e6741cadb1f1 -r 8c96fc85fa6b main.cpp
--- a/main.cpp	Fri Jun 11 18:00:10 2021 +0100
+++ b/main.cpp	Mon Jun 14 08:14:59 2021 +0000
@@ -40,7 +40,7 @@
 
 // MBed V6.4 has renamed wait_ms and UnbufferedSerial replaces Serial
 #if (MBED_VERSION  > 60300) 
-UnbufferedSerial  pc(SERIAL_TX, SERIAL_RX); 
+UnbufferedSerial  pc(USBTX, USBRX); 
 extern "C" void wait_ms(int ms);
 #else
 Serial pc(SERIAL_TX, SERIAL_RX); 
@@ -120,7 +120,7 @@
 int main()
 {   
     int status;
-    VL53L1 * Sensor;
+    VL53L1CB * Sensor;
     uint16_t wordData;
     uint8_t ToFSensor = 1;   // loop count
   
@@ -186,10 +186,10 @@
             Dev->comms_type = 1;
     
     /* Device Initialization and setting */  
-            status = Sensor->vl53L1_DataInit();
-            status = Sensor->vl53L1_StaticInit();
-            status = Sensor->vl53L1_SetPresetMode( VL53L1_PRESETMODE_LITE_RANGING);
-            status = Sensor->vl53L1_SetDistanceMode( VL53L1_DISTANCEMODE_LONG);
+            status = Sensor->VL53L1CB_DataInit();
+            status = Sensor->VL53L1CB_StaticInit();
+            status = Sensor->VL53L1CB_SetPresetMode( VL53L1_PRESETMODE_LITE_RANGING);
+            status = Sensor->VL53L1CB_SetDistanceMode( VL53L1_DISTANCEMODE_LONG);
    //         status = Sensor->vl53L1_SetMeasurementTimingBudgetMicroSeconds( 50000);
     //        status = Sensor->vl53L1_SetInterMeasurementPeriodMilliSeconds( 100);
         }  // end of sensor loop
@@ -201,7 +201,7 @@
             Sensor=board->sensor_centre;
             devCentre.i2c_slave_address = NEW_SENSOR_CENTRE_ADDRESS;
             int1 =  new WaitForMeasurement(CentreIntPin,&devCentre);  // initialise sensor interrupts
-            status = Sensor->vl53L1_StartMeasurement();
+            status = Sensor->VL53L1CB_StartMeasurement();
             printf("started interrupt centre %d\n",status);
         }
         
@@ -211,7 +211,7 @@
             Sensor=board->sensor_left;
             devLeft.i2c_slave_address = NEW_SENSOR_LEFT_ADDRESS;
             int2 = new WaitForMeasurement(LeftIntPin,&devLeft);
-            status = Sensor->vl53L1_StartMeasurement();
+            status = Sensor->VL53L1CB_StartMeasurement();
             printf("started interrupt left %d\n",status);
         }
 
@@ -220,7 +220,7 @@
             Sensor=board->sensor_right;
             devRight.i2c_slave_address = NEW_SENSOR_RIGHT_ADDRESS;
             int3 = new WaitForMeasurement(RightIntPin,&devRight);
-            status = board->sensor_right->vl53L1_StartMeasurement();
+            status = board->sensor_right->VL53L1CB_StartMeasurement();
             printf("started interrupt sensor_right  %d\n",status);
         }
         
@@ -236,42 +236,42 @@
             if (int_centre_result != 0)
             {
                 // read result
-                status = board->sensor_centre->vl53L1_GetRangingMeasurementData( &RangingData);
+                status = board->sensor_centre->VL53L1CB_GetRangingMeasurementData( &RangingData);
                 // if valid result print it
                 if (RangingData.RangeStatus != 255)
                     printf("c %d,%d \n",RangingData.RangeStatus,RangingData.RangeMilliMeter);
                 // clear interrupt flag
                 int_centre_result = 0;
                 // clear theinterrupt and wait for another result
-                status = board->sensor_centre->vl53L1_ClearInterruptAndStartMeasurement();
+                status = board->sensor_centre->VL53L1CB_ClearInterruptAndStartMeasurement();
             }
 
 
             if (int_left_result != 0)
             {
                 // read result
-                status = board->sensor_left->vl53L1_GetRangingMeasurementData( &RangingData);
+                status = board->sensor_left->VL53L1CB_GetRangingMeasurementData( &RangingData);
                 // if valid result print it 
                 if (RangingData.RangeStatus != 255)
                     printf("l %d,%d\n",RangingData.RangeStatus,RangingData.RangeMilliMeter);
                 // clear interrupt flag                
                 int_left_result = 0;
                 // clear theinterrupt and wait for another result
-                status = board->sensor_left->vl53L1_ClearInterruptAndStartMeasurement();
+                status = board->sensor_left->VL53L1CB_ClearInterruptAndStartMeasurement();
             }
             
             
             if (int_right_result != 0)
             {   
                 // read result
-                status = board->sensor_right->vl53L1_GetRangingMeasurementData( &RangingData);
+                status = board->sensor_right->VL53L1CB_GetRangingMeasurementData( &RangingData);
                 // if valid result print it
                 if (RangingData.RangeStatus != 255)
                     printf("r %d,%d\n",RangingData.RangeStatus,RangingData.RangeMilliMeter);
                 // clear interrupt flag
                 int_right_result = 0;
                 // clear theinterrupt and wait for another result
-                status = board->sensor_right->vl53L1_ClearInterruptAndStartMeasurement();
+                status = board->sensor_right->VL53L1CB_ClearInterruptAndStartMeasurement();
             }
             
         }