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

Adding some of the features of paulvha's version of the library #20

Merged
merged 1 commit into from
Feb 1, 2021
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
129 changes: 129 additions & 0 deletions examples/Example5_GetSettings/Example5_GetSettings.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
/*
Reading CO2, humidity and temperature from the SCD30
By: Nathan Seidle
SparkFun Electronics
Date: May 22nd, 2018
License: MIT. See license file for more information but you can
basically do whatever you want with this code.

Feel like supporting open source hardware?
Buy a board from SparkFun! https://www.sparkfun.com/products/15112

This example gets the SCD30's settings using the new getSettingValue function (thank you paulvha)

Hardware Connections:
Attach RedBoard to computer using a USB cable.
Connect SCD30 to RedBoard using Qwiic cable.
Open Serial Monitor at 115200 baud.
*/

#include <Wire.h>

#include "SparkFun_SCD30_Arduino_Library.h" //Click here to get the library: http://librarymanager/All#SparkFun_SCD30
SCD30 airSensor;

void setup()
{
Serial.begin(115200);
Serial.println("SCD30 Example");
Wire.begin();

//Start sensor using the Wire port, but disable the auto-calibration
if (airSensor.begin(Wire, false) == false)
{
Serial.println("Air sensor not detected. Please check wiring. Freezing...");
while (1)
;
}

uint16_t settingVal; // The settings will be returned in settingVal

if (airSensor.getForcedRecalibration(&settingVal) == true) // Get the setting
{
Serial.print("Forced recalibration factor (ppm) is ");
Serial.println(settingVal);
}
else
{
Serial.print("getForcedRecalibration failed! Freezing...");
while (1)
; // Do nothing more
}

if (airSensor.getMeasurementInterval(&settingVal) == true) // Get the setting
{
Serial.print("Measurement interval (s) is ");
Serial.println(settingVal);
}
else
{
Serial.print("getMeasurementInterval failed! Freezing...");
while (1)
; // Do nothing more
}

if (airSensor.getTemperatureOffset(&settingVal) == true) // Get the setting
{
Serial.print("Temperature offfset (C) is ");
Serial.println(((float)settingVal) / 100.0, 2);
}
else
{
Serial.print("getTemperatureOffset failed! Freezing...");
while (1)
; // Do nothing more
}

if (airSensor.getAltitudeCompensation(&settingVal) == true) // Get the setting
{
Serial.print("Altitude offset (m) is ");
Serial.println(settingVal);
}
else
{
Serial.print("getAltitudeCompensation failed! Freezing...");
while (1)
; // Do nothing more
}

if (airSensor.getFirmwareVersion(&settingVal) == true) // Get the setting
{
Serial.print("Firmware version is 0x");
Serial.println(settingVal, HEX);
}
else
{
Serial.print("getFirmwareVersion! Freezing...");
while (1)
; // Do nothing more
}

Serial.print("Auto calibration set to ");
if (airSensor.getAutoSelfCalibration() == true)
Serial.println("true");
else
Serial.println("false");

//The SCD30 has data ready every two seconds
}

void loop()
{
if (airSensor.dataAvailable())
{
Serial.print("co2(ppm):");
Serial.print(airSensor.getCO2());

Serial.print(" temp(C):");
Serial.print(airSensor.getTemperature(), 1);

Serial.print(" humidity(%):");
Serial.print(airSensor.getHumidity(), 1);

Serial.println();
}
else
Serial.println("Waiting for new data");

delay(500);
}
20 changes: 14 additions & 6 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -14,26 +14,31 @@ SCD30 KEYWORD1

SCD30 KEYWORD2
begin KEYWORD2
enableDebugging KEYWORD2
beginMeasuring KEYWORD2
StopMeasurement KEYWORD2
getSettingValue KEYWORD2
getForcedRecalibration KEYWORD2
getMeasurementInterval KEYWORD2
getTemperatureOffset KEYWORD2
getAltitudeCompensation KEYWORD2
getFirmwareVersion KEYWORD2
getCO2 KEYWORD2
getHumidity KEYWORD2
getTemperature KEYWORD2
getTemperatureOffset KEYWORD2
setMeasurementInterval KEYWORD2
setAmbientPressure KEYWORD2
setAltitudeCompensation KEYWORD2
getAltitudeCompensation KEYWORD2
setAutoSelfCalibration KEYWORD2
setTemperatureOffset KEYWORD2
setForcedRecalibrationFactor KEYWORD2
setTemperatureOffset KEYWORD2
getAutoSelfCalibration KEYWORD2
dataAvailable KEYWORD2
readMeasurement KEYWORD2
sendCommand KEYWORD2
reset KEYWORD2
sendCommand KEYWORD2
readRegister KEYWORD2
computeCRC8 KEYWORD2
getAutoSelfCalibration KEYWORD2
reset KEYWORD2

#######################################
# Constants (LITERAL1)
Expand All @@ -48,3 +53,6 @@ COMMAND_AUTOMATIC_SELF_CALIBRATION LITERAL1
COMMAND_SET_FORCED_RECALIBRATION_FACTOR LITERAL1
COMMAND_SET_TEMPERATURE_OFFSET LITERAL1
COMMAND_SET_ALTITUDE_COMPENSATION LITERAL1
COMMAND_RESET LITERAL1
COMMAND_STOP_MEAS LITERAL1
COMMAND_READ_FW_VER LITERAL1
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=SparkFun SCD30 Arduino Library
version=1.0.10
version=1.0.11
author=SparkFun Electronics
maintainer=SparkFun Electronics <sparkfun.com>
sentence=Library for the Sensirion SCD30 CO2 Sensor
Expand Down
Loading