VL53L1CB ranging example, using embedded sensor on X-Nucleo-53L1A2 expansion board, in interrupt mode.
Dependencies: X_NUCLEO_53L1A2
Diff: main.cpp
- Revision:
- 6:19d56b30bfa7
- Parent:
- 5:b233bdf91671
- Child:
- 7:242f30acc456
--- a/main.cpp Wed May 12 08:37:43 2021 +0000 +++ b/main.cpp Wed May 12 09:00:10 2021 +0000 @@ -45,6 +45,16 @@ #define NUM_SENSORS 3 +// define interrupt pins +PinName CentreIntPin = A2; +// the satellite pins depend on solder blobs on the back of the shield. +// they may not exist or may be one of two sets. +// the centre pin always exists +PinName LeftIntPin = D8; +PinName RightIntPin = D2; +// alternate set +//PinName LeftIntPin = D9; +//PinName RightIntPin = D4; static XNucleo53L1A2 *board=NULL; @@ -148,7 +158,7 @@ // create i2c interface ToF_DevI2C *dev_I2C = new ToF_DevI2C(I2C_SDA, I2C_SCL); /* creates the 53L1A2 expansion board singleton obj */ - board = XNucleo53L1A2::instance(dev_I2C, CentreIntPin, LeftIntPin, RightIntPin); + board = XNucleo53L1A2::instance(dev_I2C, CentreIntPin, LeftIntPin, RightIntPin); printf("board created!\r\n"); @@ -200,6 +210,8 @@ void print_results( int devNumber, VL53L1_MultiRangingData_t *pMultiRangingData ) { int no_of_object_found=pMultiRangingData->NumberOfObjectsFound; + int signal_rate = 0; + int ambient_rate = 0; int RoiNumber=pMultiRangingData->RoiNumber; @@ -207,12 +219,24 @@ 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)) { + signal_rate = pMultiRangingData->RangeData[j].SignalRateRtnMegaCps / 65535; + ambient_rate = pMultiRangingData->RangeData[j].AmbientRateRtnMegaCps / 65535; + printf("\t i2cAddr=%d \t RoiNumber=%d \t status=%d, \t D=%5dmm, \t Signal=%d Mcps, \t Ambient=%d Mcps \n", + devNumber, RoiNumber, + pMultiRangingData->RangeData[j].RangeStatus, + pMultiRangingData->RangeData[j].RangeMilliMeter, + signal_rate, + ambient_rate); +/* +// online compiler disables printf() / floating-point support, for code-size reasons. +// offline compiler can switch it on. 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))