Multiple VL53L1X and memory problems

I need to make an array using 20 vl53l1x. I’m using the arduino-compiled ST library instead of the streamlined one because I need to define the ROI. I’m finding that calling the function ( status = VL53L1_ClearInterruptAndStartMeasurement(Dev); ) consumes a significant amount of memory. So much that setting up all 20 and getting measurements for only 2 of the 20 fills up more than 200% of the sram memory on an Arduino Mega 2560 during building.
However if I don’t call the function the memory consumption is manageable. The documentation specifies that we do need to call it in order to get accurate readings. Any idea why this is happening? or an alternative to resetting the data ready flag?

Thanks in advance

Hi, acevedo.

The ST API keeps a copy of the sensor’s settings in memory, and most of the configuration functions only change those cached values. It is not until you actually start a measurement that the settings are encoded and written to the sensor (specfically in the function VL53L1_init_and_start_range(), which is called from VL53L1_ClearInterruptAndStartMeasurement()). So I don’t think there’s really a way for you to avoid calling that function, since it’s doing a lot of the real work.

I would like to add the ability to change the ROI to our Arduino library in the future, and that might help for what you are trying to do, but unfortunately I don’t have a definite timeframe for when I can work on it. As an alternative, have you considered using a more capable controller with more memory like an Arduino Due or a Raspberry Pi, or splitting up your 20 sensors among multiple controllers?