Used distance reading time to stabilize temperature sensors

This commit is contained in:
Ollo 2020-12-21 17:55:57 +01:00
parent 6f5c5536cc
commit bd5fc9839f
2 changed files with 43 additions and 50 deletions

View File

@ -46,7 +46,7 @@
/** \addtogroup Configuration
* @{
*/
#define FIRMWARE_VERSION "1.0.9"
#define FIRMWARE_VERSION "1.0.10"
#define ADC_TO_VOLT(adc) ((adc) * 3.3 ) / 4095)
#define ADC_TO_VOLT_WITH_MULTI(adc, multi) (((adc)*3.3 * (multi)) / 4095)

View File

@ -437,6 +437,9 @@ void readDistance()
bool readSensors()
{
bool leaveMode1 = false;
int sensorCount = 0;
int timeoutTemp = millis() + 2000;
Serial << "Read Sensors" << endl;
readSystemSensors();
@ -456,6 +459,7 @@ bool readSensors()
}
delay(10);
}
for (int i = 0; i < MAX_PLANTS; i++)
{
long current = mPlants[i].getCurrentMoisture();
@ -486,10 +490,6 @@ bool readSensors()
rtcLastBatteryVoltage = getBatteryVoltage();
rtcLastSolarVoltage = getSolarVoltage();
readDistance();
Serial << "Distance sensor " << waterRawSensor.getAverage() << " cm" << endl;
int sensorCount = 0;
int timeoutTemp = millis() + 2000;
while (sensorCount == 0 && millis() < timeoutTemp)
{
sensors.begin();
@ -498,8 +498,16 @@ bool readSensors()
delay(200);
}
Serial << "One wire count: " << sensorCount << endl;
/* Measure temperature */
if (sensorCount > 0)
{
sensors.requestTemperatures();
}
/* Read the distance and give the temperature sensors some time */
readDistance();
Serial << "Distance sensor " << waterRawSensor.getAverage() << " cm" << endl;
/* Required to read the temperature once */
int readAgain = 5;
while (readAgain > 0)
@ -527,20 +535,6 @@ bool readSensors()
Serial << "waterTempCurrent: " << temp2Raw << endl;
waterTempSensor.add(temp2Raw);
}
if ((lipoTempSensor.getAverage() - rtcLastLipoTemp > TEMPERATURE_DELTA_TRIGGER_IN_C) ||
(rtcLastLipoTemp - lipoTempSensor.getAverage() > TEMPERATURE_DELTA_TRIGGER_IN_C))
{
leaveMode1 = true;
}
if ((waterTempSensor.getAverage() - rtcLastWaterTemp > TEMPERATURE_DELTA_TRIGGER_IN_C) ||
(rtcLastWaterTemp - waterTempSensor.getAverage() > TEMPERATURE_DELTA_TRIGGER_IN_C))
{
leaveMode1 = true;
}
if (!leaveMode1)
{
readAgain = 0;
}
readAgain--;
delay(50);
@ -549,7 +543,6 @@ bool readSensors()
{
Serial << "OnwWire sensor " << i << " has value " << sensors.getTempCByIndex(i) << endl;
}
}
if (abs(lipoTempSensor.getAverage() - rtcLastLipoTemp) > TEMPERATURE_DELTA_TRIGGER_IN_C)
{