Skip to content

Commit 000eb4a

Browse files
authored
Merge pull request #18 from awatterott/master
Add getAltitudeCompensation()
2 parents 42692be + 89a0530 commit 000eb4a

File tree

3 files changed

+18
-4
lines changed

3 files changed

+18
-4
lines changed

examples/Example2_SetOptions/Example2_SetOptions.ino

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -42,18 +42,25 @@ void setup()
4242

4343
airSensor.setMeasurementInterval(4); //Change number of seconds between measurements: 2 to 1800 (30 minutes)
4444

45+
//Read altitude compensation value
46+
unsigned int altitude = airSensor.getAltitudeCompensation();
47+
Serial.print("Current altitude: ");
48+
Serial.print(altitude);
49+
Serial.println("m");
50+
4551
//My desk is ~1600m above sealevel
46-
airSensor.setAltitudeCompensation(1600); //Set altitude of the sensor in m
52+
airSensor.setAltitudeCompensation(1600); //Set altitude of the sensor in m, stored in non-volatile memory of SCD30
4753

4854
//Pressure in Boulder, CO is 24.65inHg or 834.74mBar
49-
airSensor.setAmbientPressure(835); //Current ambient pressure in mBar: 700 to 1200
55+
airSensor.setAmbientPressure(835); //Current ambient pressure in mBar: 700 to 1200, will overwrite altitude compensation
5056

57+
//Read temperature offset
5158
float offset = airSensor.getTemperatureOffset();
5259
Serial.print("Current temp offset: ");
5360
Serial.print(offset, 2);
5461
Serial.println("C");
5562

56-
//airSensor.setTemperatureOffset(5); //Optionally we can set temperature offset to 5°C
63+
//airSensor.setTemperatureOffset(5); //Optionally we can set temperature offset to 5°C, stored in non-volatile memory of SCD30
5764
}
5865

5966
void loop()

src/SparkFun_SCD30_Arduino_Library.cpp

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ bool SCD30::setForcedRecalibrationFactor(uint16_t concentration)
123123
}
124124

125125
//Get the temperature offset. See 1.3.8.
126-
float SCD30::getTemperatureOffset()
126+
float SCD30::getTemperatureOffset(void)
127127
{
128128
uint16_t response = readRegister(COMMAND_SET_TEMPERATURE_OFFSET);
129129
return (float)response / 100;
@@ -136,6 +136,12 @@ bool SCD30::setTemperatureOffset(float tempOffset)
136136
return sendCommand(COMMAND_SET_TEMPERATURE_OFFSET, tickOffset);
137137
}
138138

139+
//Get the altitude compenstation. See 1.3.9.
140+
uint16_t SCD30::getAltitudeCompensation(void)
141+
{
142+
return readRegister(COMMAND_SET_ALTITUDE_COMPENSATION);
143+
}
144+
139145
//Set the altitude compenstation. See 1.3.9.
140146
bool SCD30::setAltitudeCompensation(uint16_t altitude)
141147
{

src/SparkFun_SCD30_Arduino_Library.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ class SCD30
6161
float getHumidity(void);
6262
float getTemperature(void);
6363
float getTemperatureOffset(void);
64+
uint16_t getAltitudeCompensation(void);
6465

6566
bool setMeasurementInterval(uint16_t interval);
6667
bool setAmbientPressure(uint16_t pressure_mbar);

0 commit comments

Comments
 (0)