Start I2C sensor after power was activated

This commit is contained in:
Ollo
2023-03-10 22:50:16 +01:00
parent 712ef73a30
commit 1fad63a84d
2 changed files with 10 additions and 8 deletions

View File

@@ -329,11 +329,13 @@ void readPowerSwitchedSensors()
}
}
waterRawSensor.clear();
Wire.begin(SENSOR_TANK_SDA, SENSOR_TANK_SCL, 100000UL /* 100kHz */);
tankSensor.setTimeout(500);
tankSensor.setBus(&Wire);
long start = millis();
bool distanceReady = false;
while (start + 500 > millis())
delay(50);
while ((start + WATERSENSOR_TIMEOUT) > millis())
{
if (tankSensor.init())
{
@@ -347,12 +349,13 @@ void readPowerSwitchedSensors()
}
if (distanceReady)
{
waterRawSensor.clear();
tankSensor.setSignalRateLimit(0.1);
// increase laser pulse periods (defaults are 14 and 10 PCLKs)
tankSensor.setVcselPulsePeriod(VL53L0X::VcselPeriodPreRange, 18);
tankSensor.setVcselPulsePeriod(VL53L0X::VcselPeriodFinalRange, 14);
tankSensor.setMeasurementTimingBudget(200000);
for (int readCnt = 0; readCnt < 5; readCnt++)
for (int readCnt = 0; readCnt < WATERSENSOR_CYCLE; readCnt++)
{
if (!tankSensor.timeoutOccurred())
{
@@ -362,7 +365,7 @@ void readPowerSwitchedSensors()
waterRawSensor.add(distance);
}
}
delay(10);
delay(50);
}
Serial << "Distance sensor " << waterRawSensor.getMedian() << " mm" << endl;
}
@@ -802,7 +805,6 @@ void safeSetup()
{
mPlants[i].initSensors();
}
Wire.begin(SENSOR_TANK_SDA, SENSOR_TANK_SCL);
readPowerSwitchedSensors();
Homie.setup();