@@ -58,16 +58,9 @@ bool SCD30::begin(TwoWire &wirePort, bool autoCalibrate, bool measBegin)
58
58
_i2cPort->setClockStretchLimit (200000 );
59
59
#endif
60
60
61
- uint16_t fwVer;
62
- if (getFirmwareVersion (&fwVer) == false ) // Read the firmware version. Return false if the CRC check fails.
61
+ if (isConnected () == false )
63
62
return (false );
64
63
65
- if (_printDebug == true )
66
- {
67
- _debugPort->print (F (" SCD30 begin: got firmware version 0x" ));
68
- _debugPort->println (fwVer, HEX);
69
- }
70
-
71
64
if (measBegin == false ) // Exit now if measBegin is false
72
65
return (true );
73
66
@@ -83,6 +76,22 @@ bool SCD30::begin(TwoWire &wirePort, bool autoCalibrate, bool measBegin)
83
76
return (false ); // Something went wrong
84
77
}
85
78
79
+ // Returns true if device responds to a firmware request
80
+ bool SCD30::isConnected ()
81
+ {
82
+ uint16_t fwVer;
83
+ if (getFirmwareVersion (&fwVer) == false ) // Read the firmware version. Return false if the CRC check fails.
84
+ return (false );
85
+
86
+ if (_printDebug == true )
87
+ {
88
+ _debugPort->print (F (" Firmware version 0x" ));
89
+ _debugPort->println (fwVer, HEX);
90
+ }
91
+
92
+ return (true );
93
+ }
94
+
86
95
// Calling this function with nothing sets the debug port to Serial
87
96
// You can also call it with other streams like Serial1, SerialUSB, etc.
88
97
void SCD30::enableDebugging (Stream &debugPort)
@@ -96,7 +105,11 @@ void SCD30::enableDebugging(Stream &debugPort)
96
105
uint16_t SCD30::getCO2 (void )
97
106
{
98
107
if (co2HasBeenReported == true ) // Trigger a new read
99
- readMeasurement (); // Pull in new co2, humidity, and temp into global vars
108
+ {
109
+ if (readMeasurement () == false ) // Pull in new co2, humidity, and temp into global vars
110
+ co2 = 0 ; // Failed to read sensor
111
+ }
112
+
100
113
co2HasBeenReported = true ;
101
114
102
115
return (uint16_t )co2; // Cut off decimal as co2 is 0 to 10,000
@@ -107,7 +120,8 @@ uint16_t SCD30::getCO2(void)
107
120
float SCD30::getHumidity (void )
108
121
{
109
122
if (humidityHasBeenReported == true ) // Trigger a new read
110
- readMeasurement (); // Pull in new co2, humidity, and temp into global vars
123
+ if (readMeasurement () == false ) // Pull in new co2, humidity, and temp into global vars
124
+ humidity = 0 ; // Failed to read sensor
111
125
112
126
humidityHasBeenReported = true ;
113
127
@@ -119,7 +133,8 @@ float SCD30::getHumidity(void)
119
133
float SCD30::getTemperature (void )
120
134
{
121
135
if (temperatureHasBeenReported == true ) // Trigger a new read
122
- readMeasurement (); // Pull in new co2, humidity, and temp into global vars
136
+ if (readMeasurement () == false ) // Pull in new co2, humidity, and temp into global vars
137
+ temperature = 0 ; // Failed to read sensor
123
138
124
139
temperatureHasBeenReported = true ;
125
140
0 commit comments