This library allows you to read from multiple VL53L1X sensors.

Dependencies:   mbed

Fork of VL53L1X_Pololu by Jesus Fausto

Files at this revision

API Documentation at this revision

Comitter:
jvfausto
Date:
Thu Aug 09 19:39:36 2018 +0000
Parent:
2:f570ff03fb81
Commit message:
Faster frequency

Changed in this revision

VL53L1X.cpp 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 f570ff03fb81 -r 7777bbcf11f6 VL53L1X.cpp
--- a/VL53L1X.cpp	Thu Aug 09 18:12:38 2018 +0000
+++ b/VL53L1X.cpp	Thu Aug 09 19:39:36 2018 +0000
@@ -591,7 +591,7 @@
 //  _i2c.requestFrom(address, (uint8_t)17);
   _i2c.read(address, infoToRead, 17, 0);
  
-  wait(.02);
+  wait(.005);
   results.range_status = infoToRead[0];
  
 //  infoToRead[1]; // report_status: not used
@@ -679,7 +679,7 @@
   // Basically, this appears to scale the result by 2011/2048, or about 98%
   // (with the 1024 added for proper rounding).
   ranging_data.range_mm = ((uint32_t)range * 2011 + 0x0400) / 0x0800;
-  wait(.01);
+  wait(.005);
   // VL53L1_copy_sys_and_core_results_to_range_results() end
  
   // set range_status in ranging_data based on value of RESULT__RANGE_STATUS register
@@ -839,6 +839,7 @@
  // setDistanceMode(VL53L1X::Short);//Short Medium Long
   setAddress(addr);//change I2C address for next sensor
   setMeasurementTimingBudget(timing_budget);//min 20ms for Short, 33ms for Medium and Long
+  startContinuous(50);
   wait_ms(100);
   didInitialize = true;
   return true;
@@ -869,12 +870,8 @@
 }
 int VL53L1X::readFromOneSensor(void)
 {
-    startContinuous(50);
-    int variable;
     if (didInitialize)   //create bool
-        variable = read();
+        return read();
     else 
-        variable = -1;  
-    stopContinuous();   
-    return variable; 
+        return -1;  
 }
\ No newline at end of file
diff -r f570ff03fb81 -r 7777bbcf11f6 main.cpp
--- a/main.cpp	Thu Aug 09 18:12:38 2018 +0000
+++ b/main.cpp	Thu Aug 09 19:39:36 2018 +0000
@@ -2,7 +2,10 @@
 #include "VL53L1X.h"
 
 Serial pc(USBTX,USBRX);
-
+bool s1_init = false;
+bool s2_init = false;
+bool s3_init = false;
+bool s4_init = false;
 VL53L1X sensor1(D14, D15, D0);
 VL53L1X sensor2(D14, D15, D1);
 VL53L1X sensor3(D14, D15, D2);
@@ -10,16 +13,16 @@
 
 int main()
 {  
-    sensor1.initReading(0x25,25000);
-    sensor2.initReading(0x27,25000);
-    sensor3.initReading(0x35,25000);
-    sensor4.initReading(0x37,25000);
+    sensor1.initReading(0x25,50000);
+    sensor2.initReading(0x27,50000);
+    sensor3.initReading(0x35,50000);
+    sensor4.initReading(0x37,50000);
 
     while(1)
-    {       
+    {
       pc.printf("%d, ", sensor1.readFromOneSensor());
       pc.printf("%d, ", sensor2.readFromOneSensor());
       pc.printf("%d, ", sensor3.readFromOneSensor());
-      pc.printf("%d, \r\n", sensor4.readFromOneSensor()); 
+      pc.printf("%d\r\n", sensor4.readFromOneSensor()); 
     }
 }