Reset sensor on bad values

This commit is contained in:
Ollo 2023-03-22 20:50:25 +01:00
parent 939a5fe21a
commit 66f61a69db

View File

@ -11,16 +11,7 @@
VL53L0X tankSensor;
void setup()
{
Serial.begin(115200);
pinMode(OUTPUT_SENSOR, OUTPUT);
tankSensor.setTimeout(500);
digitalWrite(OUTPUT_SENSOR, HIGH);
Serial.println("Nodemcu ESP32 Start done");
tankSensor.setTimeout(500);
void initializeTanksensor() {
Wire.begin(SENSOR_TANK_SDA, SENSOR_TANK_SCL, 100000UL /* 100kHz */);
tankSensor.setTimeout(500);
tankSensor.setBus(&Wire);
@ -48,11 +39,23 @@ void setup()
tankSensor.setVcselPulsePeriod(VL53L0X::VcselPeriodPreRange, 18);
tankSensor.setVcselPulsePeriod(VL53L0X::VcselPeriodFinalRange, 14);
tankSensor.setMeasurementTimingBudget(200000);
tankSensor.startContinuous();
} else {
Serial.println("Sensor init failed");
}
}
void setup()
{
Serial.begin(115200);
pinMode(OUTPUT_SENSOR, OUTPUT);
digitalWrite(OUTPUT_SENSOR, HIGH);
Serial.println("Nodemcu ESP32 Start done");
initializeTanksensor();
}
void loop() {
delay(500);
@ -61,9 +64,21 @@ void loop() {
if (!tankSensor.timeoutOccurred())
{
uint16_t distance = tankSensor.readRangeSingleMillimeters();
if (distance == 8191) {
Serial.println("Reset due to 8.191 meter");
tankSensor.stopContinuous();
Wire.end();
delay(100);
initializeTanksensor();
} else {
Serial.print("Distance");
Serial.println(distance);
}
} else {
Serial.println("Timeout");
tankSensor.stopContinuous();
Wire.end();
delay(100);
initializeTanksensor();
}
}