I use Pololu's VL53L0X for this Lab.
Pololu - VL53L0X Time-of-Flight Distance Sensor Carrier with Voltage Regulator, 200cm Max
https://github.com/pololu/vl53l0x-arduino
On Arduino Nano, A4 pin is for SDA, and A5 pin is for SCL.
I use the code from Pololu's VL53L0X. The code for basic continuous range measurement shows below:
#include <Wire.h>
#include <VL53L0X.h>
VL53L0X sensor;
void setup() {
Serial.begin(9600);
Wire.begin();
sensor.setTimeout(500);
if (!sensor.init())
{
Serial.println("Failed to detect and initialize sensor!");
while (1) {}. // Is while(1) the same as while(true)?
}
sensor.startContinuous();
}
void loop() {
Serial.println(sensor.readRangeContinuousMillimeters());
//delay(10);
if (sensor.timeoutOccurred()) {
Serial.print(" TIMEOUT");
}
//Serial.println();
}
Readings from Long Range mode
I use Adafruit SSD 1306 for this lab, links below are its library and graphics tutorial:
https://github.com/adafruit/Adafruit_SSD1306
Basic display methods
display.print(); //display text
display.write(); //display ASCII
for ( int i = 0; i < 10; i++) {
display.drawRect(i*6, i*3, SCREEN_WIDTH - 2 -i*12, SCREEN_HEIGHT-2 -i*6, WHITE);
} //display Rect