Skip to content

Commit 0d83a49

Browse files
committed
setTemperatureOffset can only be positive. Adding notes.
1 parent 79ed38c commit 0d83a49

File tree

1 file changed

+9
-8
lines changed

1 file changed

+9
-8
lines changed

src/SparkFun_SCD30_Arduino_Library.cpp

Lines changed: 9 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -162,17 +162,18 @@ float SCD30::getTemperatureOffset(void)
162162
return (((float)signedUnsigned.signed16) / 100.0);
163163
}
164164

165-
//Set the temperature offset. See 1.3.8.
165+
//Set the temperature offset to remove module heating from temp reading
166166
bool SCD30::setTemperatureOffset(float tempOffset)
167167
{
168-
union
169-
{
170-
int16_t signed16;
171-
uint16_t unsigned16;
172-
} signedUnsigned; // Avoid any ambiguity casting int16_t to uint16_t
173-
signedUnsigned.signed16 = tempOffset * 100;
168+
//Temp offset is only positive. See: https://github.com/sparkfun/SparkFun_SCD30_Arduino_Library/issues/27#issuecomment-971986826
169+
//"The SCD30 offset temperature is obtained by subtracting the reference temperature from the SCD30 output temperature"
170+
//https://www.sensirion.com/fileadmin/user_upload/customers/sensirion/Dokumente/9.5_CO2/Sensirion_CO2_Sensors_SCD30_Low_Power_Mode.pdf
171+
172+
if(tempOffset < 0.0) return(false);
173+
174+
uint16_t value = tempOffset * 100;
174175

175-
return sendCommand(COMMAND_SET_TEMPERATURE_OFFSET, signedUnsigned.unsigned16);
176+
return sendCommand(COMMAND_SET_TEMPERATURE_OFFSET, value);
176177
}
177178

178179
//Get the altitude compenstation. See 1.3.9.

0 commit comments

Comments
 (0)