Skip to content

Instantly share code, notes, and snippets.

@Andrew-rw
Created February 3, 2018 15:49
Show Gist options
  • Save Andrew-rw/19e0bd651af51ed51a89f65fa6423256 to your computer and use it in GitHub Desktop.
Save Andrew-rw/19e0bd651af51ed51a89f65fa6423256 to your computer and use it in GitHub Desktop.
Arduino test bench for VL53L0X vs HC-SR04
#include "Adafruit_VL53L0X.h"
#include "HC_SR04.h"
#define TRIG_PIN 3
#define ECHO_PIN 2
#define ECHO_INT 0
HC_SR04 sensor(TRIG_PIN, ECHO_PIN, ECHO_INT);
Adafruit_VL53L0X lox = Adafruit_VL53L0X();
double o;
double s;
void setup() {
sensor.begin();
Serial.begin(115200);
// wait until serial port opens for native USB devices
while (! Serial) {
delay(1);
}
Serial.println("Adafruit VL53L0X test");
if (!lox.begin()) {
Serial.println(F("Failed to boot VL53L0X"));
while(1);
}
}
void loop() {
humanReadable();
delay(200);
}
void humanReadable(){
Serial.println("------------------------------");
VL53L0X_RangingMeasurementData_t measure;
Serial.print("Reading laser measurement... ");
lox.rangingTest(&measure, false); // pass in 'true' to get debug data printout!
if (measure.RangeStatus != 4) { // phase failures have incorrect data
Serial.print("Distance (cm): "); Serial.println(measure.RangeMilliMeter/10);
} else {
Serial.println(" out of range ");
}
sensor.start();
Serial.print("Reading sonic measurement... ");
while(!sensor.isFinished()) continue;
Serial.print("Distance (cm): "); Serial.println(sensor.getRange());
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment