A sample program to control one VL53L1 ToF sensor in multizone mode using polling to find out if a measurement is available. Mbed V6.3 but will run any MBed version by dropping replacing this one. Maint6 release.
Dependencies: X_NUCLEO_53L1A2
Diff: main.cpp
- Revision:
- 18:2d1f16e92a8e
- Parent:
- 16:9fd42eb225c5
--- a/main.cpp Mon Jun 14 09:46:02 2021 +0000 +++ b/main.cpp Wed Jun 16 14:24:47 2021 +0000 @@ -37,6 +37,8 @@ static XNucleo53L1A2 *board=NULL; + + #if (MBED_VERSION > 60300) UnbufferedSerial pc(USBTX, USBRX); extern "C" void wait_ms(int ms); @@ -61,7 +63,6 @@ VL53L1CB * Sensor; uint16_t wordData; - pc.baud(115200); // baud rate is important as printf statements take a lot of time printf("Polling single multizone mbed = %d \r\n",MBED_VERSION); @@ -79,13 +80,10 @@ printf("Failed to init board!\r\n"); return 0; } - printf("board initiated! - %d\r\n", status); + // create the sensor controller classes - - - Dev=&devCentre; Sensor=board->sensor_centre; Dev->i2c_slave_address = NEW_SENSOR_CENTRE_ADDRESS; @@ -156,39 +154,34 @@ // prints the range result seen above void print_results( int devSpiNumber, VL53L1_MultiRangingData_t *pMultiRangingData ) { - int no_of_object_found=pMultiRangingData->NumberOfObjectsFound; - - int RoiNumber=pMultiRangingData->RoiNumber; -// int RoiStatus=pMultiRangingData->RoiStatus; + int no_of_object_found=pMultiRangingData->NumberOfObjectsFound; + + 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)) { - - // printf("MZI Count=%5d, ", pMultiRangingData->StreamCount); - // printf("RoiNumber%1d, ", RoiNumber); - // printf("RoiStatus=%1d, \n", RoiStatus); - 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 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); - } - else - { -// printf("RangeStatus %d %d\n",j, pMultiRangingData->RangeData[j].RangeStatus); - } - } - } // if (( no_of_object_found < 10 ) && ( no_of_object_found != 0)) + 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); + } else { + + } + } + } // if (( no_of_object_found < 10 ) && ( no_of_object_found != 0)) + else + { // printf("no_of_object_found %d \n",no_of_object_found); - } + } }