Skip to content

Commit

Permalink
Merge pull request #18 from awatterott/master
Browse files Browse the repository at this point in the history
Add getAltitudeCompensation()
  • Loading branch information
nseidle authored Dec 31, 2020
2 parents 42692be + 89a0530 commit 000eb4a
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 4 deletions.
13 changes: 10 additions & 3 deletions examples/Example2_SetOptions/Example2_SetOptions.ino
Original file line number Diff line number Diff line change
Expand Up @@ -42,18 +42,25 @@ void setup()

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

//Read altitude compensation value
unsigned int altitude = airSensor.getAltitudeCompensation();
Serial.print("Current altitude: ");
Serial.print(altitude);
Serial.println("m");

//My desk is ~1600m above sealevel
airSensor.setAltitudeCompensation(1600); //Set altitude of the sensor in m
airSensor.setAltitudeCompensation(1600); //Set altitude of the sensor in m, stored in non-volatile memory of SCD30

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

//Read temperature offset
float offset = airSensor.getTemperatureOffset();
Serial.print("Current temp offset: ");
Serial.print(offset, 2);
Serial.println("C");

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

void loop()
Expand Down
8 changes: 7 additions & 1 deletion src/SparkFun_SCD30_Arduino_Library.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ bool SCD30::setForcedRecalibrationFactor(uint16_t concentration)
}

//Get the temperature offset. See 1.3.8.
float SCD30::getTemperatureOffset()
float SCD30::getTemperatureOffset(void)
{
uint16_t response = readRegister(COMMAND_SET_TEMPERATURE_OFFSET);
return (float)response / 100;
Expand All @@ -136,6 +136,12 @@ bool SCD30::setTemperatureOffset(float tempOffset)
return sendCommand(COMMAND_SET_TEMPERATURE_OFFSET, tickOffset);
}

//Get the altitude compenstation. See 1.3.9.
uint16_t SCD30::getAltitudeCompensation(void)
{
return readRegister(COMMAND_SET_ALTITUDE_COMPENSATION);
}

//Set the altitude compenstation. See 1.3.9.
bool SCD30::setAltitudeCompensation(uint16_t altitude)
{
Expand Down
1 change: 1 addition & 0 deletions src/SparkFun_SCD30_Arduino_Library.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@ class SCD30
float getHumidity(void);
float getTemperature(void);
float getTemperatureOffset(void);
uint16_t getAltitudeCompensation(void);

bool setMeasurementInterval(uint16_t interval);
bool setAmbientPressure(uint16_t pressure_mbar);
Expand Down

0 comments on commit 000eb4a

Please sign in to comment.