Hi there, I have a project, which want to sample the temperature using two AM2302 sensors.
In the Loop function I write it below:
void loop()
{
unsigned long _us = millis();
int _delta = (_us - _lastTimeInLoop);
if (_delta > (1.05 * LOOP_DELAY))
_spark_error_count++;
// Launch the acquisition on the two sensors
DHTA.acquire();
DHTB.acquire();
// Print information for Sensor A
Serial.print("\n");
Serial.print(n);
Serial.print(" : ");
Serial.print((float) (_delta / 1000.0));
Serial.print("s");
if (_sensorA_error_count > 0 || _spark_error_count > 0) {
Serial.print(" : E=");
Serial.print(_sensorA_error_count);
Serial.print("/");
Serial.print(_spark_error_count);
}
Serial.print(", Retrieving information from sensor: ");
Serial.print("Read sensor A: ");
while (DHTA.acquiring()) ;
printSensorData(&DHTA);
// Print information for Sensor B
Serial.print("\n");
Serial.print(n);
Serial.print(" : ");
Serial.print((float) (_delta / 1000.0));
Serial.print("s");
if (_sensorB_error_count > 0 || _spark_error_count > 0) {
Serial.print(" : E=");
Serial.print(_sensorB_error_count);
Serial.print("/");
Serial.print(_spark_error_count);
}
Serial.print(", Retrieving information from sensor: ");
Serial.print("Read sensor B: ");
while (DHTB.acquiring()) ;
printSensorData(&DHTB);
n++;
_lastTimeInLoop = _us;
delay(LOOP_DELAY);
}
The point is when there is a bad senor in DHTB hardware. Serial port will be stop at the value as shown in the picture. I have changed the codes into one sensor condition, it works fine. Can anybody help to fix the code for jumping sensor B, if the hardware has problem and automatic jump to scan sensor A.
I’ve edited your post to properly format the code. Please check out this post, so you know how to do this yourself in the future. Thanks in advance! ~Jordy