Hello,
I have recently embarked on a project to try and not hit my car on the side of the garage by using a VL53L0X sensor and outputting to a TM1637 display. However I have an issue when I output to the display I cannot get a reading from the sensor.
This project is running on a Pro Micro board
#include "Adafruit_VL53L0X.h"
#include <Arduino.h>
#include <TM1637Display.h>
// Module connection pins (Digital Pins)
#define CLK 5
#define DIO 7
Adafruit_VL53L0X lox = Adafruit_VL53L0X();
VL53L0X_RangingMeasurementData_t measure;
TM1637Display display = TM1637Display(CLK, DIO);
void setup() {
Serial.begin(115200);
display = TM1637Display(CLK, DIO);
display.setBrightness(7, true); // Turn on
display.clear();
// 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);
}
// power
Serial.println(F("Started\n\n"));
}
void loop() {
int distance = getDistance();
Serial.print("Distance (mm): "); Serial.println(distance);
showValue(distance);
delay(100);
}
void showValue(int distance) {
// display.showNumberDec(distance, false);
}
int getDistance() {
lox.rangingTest(&measure, false); // pass in 'true' to get debug data printout!
int distance = measure.RangeMilliMeter;
if(measure.RangeStatus != 4 && distance <= 2000) { // if not out of range
return distance;
} else {
return 2000;
}
}
The code above works fine outputting to the serial monitor however as soon as I uncomment
// display.showNumberDec(distance, false);
The sensor stops being read and Its debug output is always "Range Status: 4 : Phase Fail". I have tested the TM1637 without issue.
Any ideas much welcome