I’ve started using Lidar-LITE V3hp together with an Arduino UNO to measure some distances. The sensor is hooked up according to sparkfun’s guide. It generally works, but after a few minutes of measurements the sensor returns “nack” instead of a distance. “nack” is also mentioned in the hookup guide and indicates that the I2C connection is lost.
The problem is: I only get one “nack” and then everything freezes forever. The program does not continue with measurements after the first nack. If I re-upload the same script to the Arduino again, or restart it, the measurements work again. But then the same thing happens again after some time.
So my question is: how can I tell the Arduino to ignore the nack value and try taking a new measurement? Instead of freezing everything indefinitely.
I have attached my program here. It controls 2 stepper motors which turn the lidar in two directions, measuring distance at each turn.
LidarProgram.ino (12.4 KB)