Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add getAltitudeCompensation() #18

Merged
merged 4 commits into from
Dec 31, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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