pololu / vl53l0x-arduino

Pololu Arduino library for VL53L0X time-of-flight distance sensor
https://www.pololu.com/product/2490
Other
345 stars 163 forks source link

ESP8266 divide by 0 reboot when device not present #34

Closed jstuewe closed 4 years ago

jstuewe commented 5 years ago

On my ESP8266, this library caused reboots during init when the device wasn't found on the I2C bus. I tracked it down to the 'setMeasurementTimingBudget' call and then to the return line in the timeoutMicrosecondsToMclks routine. 1016: return (((timeout_period_us * 1000) + (macro_period_ns / 2)) / macro_period_ns);

The 'macro_period_ns' variable was zero which generated a Div0 error\crash. I added the line below to fix it, but I'm sure there is a better way. if (!macro_period_ns) macro_period_ns++; //avoid divide by zero

Great library, Thanks for contributing it.

kevin-pololu commented 4 years ago

init() now starts by checking an ID register to make sure a VL53L0X is connected (and immediately returns false if it isn't), so I think this shouldn't be an issue anymore.