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

Revision:
2:f0ec92af4b5f
Parent:
1:ff48a20de191
Child:
3:c1e893e6752f
--- a/main.cpp	Mon Nov 09 17:36:20 2020 +0000
+++ b/main.cpp	Fri May 07 14:15:27 2021 +0000
@@ -1,21 +1,27 @@
 /*
- *  This VL53L1X Expansion board test application performs range measurements
- *  using the onboard embedded centre sensor and two satelites, in autonomous, interrupt mode.
- *  Measured ranges are ouput on the Serial Port, running at 115200 baud.
+ * This VL53L1X Expansion board test application performs range measurements
+ * using the onboard embedded centre sensor and two satelites, in autonomous, interrupt mode.
+ * Measured ranges are ouput on the Serial Port, running at 115200 baud.
  *
-*
  * This is designed to work with MBed V2 , MBed V5 and MBed V6.
  *
+ *  The Reset button can be used to restart the program.
  *
- *  The Reset button can be used to restart the program.
+ * *** Note : 
+ * Default Mbed build system settings disable print floating-point support.
+ * Offline builds can enable this, again.
+ * https://github.com/ARMmbed/mbed-os/blob/master/platform/source/minimal-printf/README.md
+ * .\mbed-os\platform\mbed_lib.json
+ *
  */
  
 #include <stdio.h>
+#include <time.h>
 
 #include "mbed.h"
+
 #include "XNucleo53L1A2.h"
 #include "ToF_I2C.h"
-#include <time.h>
 
 // i2c comms port pins
 #define I2C_SDA   D14 
@@ -39,12 +45,11 @@
 
 static XNucleo53L1A2 *board=NULL;
 
-// MBed V6.4 has renamed wait_ms and UnbufferedSerial replaces Serial
 #if (MBED_VERSION  > 60300) 
-UnbufferedSerial  pc(SERIAL_TX, SERIAL_RX); 
-extern "C" void wait_ms(int ms);
+    UnbufferedSerial  pc(USBTX, USBRX);
+    extern "C" void wait_ms(int ms);
 #else
-Serial pc(SERIAL_TX, SERIAL_RX); 
+    Serial pc(SERIAL_TX, SERIAL_RX); 
 #endif
 
 // flags to indicate an interrupt has happened
@@ -57,7 +62,7 @@
 static int int_left_dropped = 0;
 static int int_right_dropped = 0;
 
-void print_results( int devSpiNumber, VL53L1_MultiRangingData_t *pMultiRangingData );
+void print_results( int devNumber, VL53L1_MultiRangingData_t *pMultiRangingData );
 
 class WaitForMeasurement {
 public:
@@ -78,7 +83,7 @@
          Devlocal = Dev;
          pinlocal = pin;
          
-         #include "mbed.h"
+//         #include "mbed.h"
  
 
         _interrupt.rise(callback(this, &WaitForMeasurement::got_interrupt)); // if interrupt happens read data
@@ -328,37 +333,27 @@
     
     
  // print what ever results are required   
-void print_results( int devSpiNumber, VL53L1_MultiRangingData_t *pMultiRangingData )
+void print_results( int devNumber, VL53L1_MultiRangingData_t *pMultiRangingData )
 {
-            int no_of_object_found=pMultiRangingData->NumberOfObjectsFound;
+    int no_of_object_found=pMultiRangingData->NumberOfObjectsFound;
             
-            int RoiNumber=pMultiRangingData->RoiNumber;
- //           int RoiStatus=pMultiRangingData->RoiStatus;
+    int RoiNumber=pMultiRangingData->RoiNumber;
 
-            if (( no_of_object_found < 10 ) &&  ( no_of_object_found != 0)) 
+    if (( no_of_object_found < 10 ) &&  ( no_of_object_found != 0)) 
+    {
+        for(int j=0;j<no_of_object_found;j++){
+            if ((pMultiRangingData->RangeData[j].RangeStatus == VL53L1_RANGESTATUS_RANGE_VALID) || 
+                (pMultiRangingData->RangeData[j].RangeStatus == VL53L1_RANGESTATUS_RANGE_VALID_NO_WRAP_CHECK_FAIL))
             {
-                for(int j=0;j<no_of_object_found;j++){
-                    if ((pMultiRangingData->RangeData[j].RangeStatus == VL53L1_RANGESTATUS_RANGE_VALID) || 
-                        (pMultiRangingData->RangeData[j].RangeStatus == VL53L1_RANGESTATUS_RANGE_VALID_NO_WRAP_CHECK_FAIL))
-                    {
-                        printf("\t spiAddr=%d \t RoiNumber=%d  \t D=%5dmm \n",
-                                devSpiNumber,
-                                RoiNumber,
-                                pMultiRangingData->RangeData[j].RangeMilliMeter);
-                        /*
-                                                printf("\t spiAddr=%d \t RoiNumber=%d   \t status=%d, \t D=%5dmm, \t Signal=%2.2f Mcps, \t Ambient=%2.2f Mcps \n",
-                        devSpiNumber,
-                        RoiNumber,
-                        pMultiRangingData->RangeData[j].RangeStatus,
-                        pMultiRangingData->RangeData[j].RangeMilliMeter,
-                        pMultiRangingData->RangeData[j].SignalRateRtnMegaCps/65536.0,
-                        pMultiRangingData->RangeData[j].AmbientRateRtnMegaCps/65536.0);
-                        */
-                    }
-
-                }
-            } // if (( no_of_object_found < 10 ) &&  ( no_of_object_found != 0)) 
-
+                printf("\t i2cAddr=%d \t RoiNumber=%d   \t status=%d, \t D=%5dmm, \t Signal=%2.2f Mcps, \t Ambient=%2.2f Mcps \n",
+                    devNumber, RoiNumber,
+                    pMultiRangingData->RangeData[j].RangeStatus,
+                    pMultiRangingData->RangeData[j].RangeMilliMeter,
+                    pMultiRangingData->RangeData[j].SignalRateRtnMegaCps / 65535.0,
+                    pMultiRangingData->RangeData[j].AmbientRateRtnMegaCps / 65535.0);   
+            }
+        }
+    } // if (( no_of_object_found < 10 ) &&  ( no_of_object_found != 0)) 
 }