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