Skip to content

Commit

Permalink
1.3.0 (#5)
Browse files Browse the repository at this point in the history
* - add resetEEPROM()
- move code to src folder
- prepare for platformIO

* -update and rewrite comments
-refactor functions and remove unused variables
-update readme

* Update README.md

* - add .clang format

* Update Formatting

---------

Co-authored-by: CDFER <cdirksfer@gamil.com>
  • Loading branch information
CDFER and CDFER authored Aug 17, 2024
1 parent 5002e0e commit 3490d06
Show file tree
Hide file tree
Showing 7 changed files with 464 additions and 360 deletions.
190 changes: 190 additions & 0 deletions .clang-format
Original file line number Diff line number Diff line change
@@ -0,0 +1,190 @@
# Source: https://github.com/arduino/tooling-project-assets/tree/main/other/clang-format-configuration
---
AccessModifierOffset: -2
AlignAfterOpenBracket: Align
AlignArrayOfStructures: None
AlignConsecutiveAssignments: None
AlignConsecutiveBitFields: None
AlignConsecutiveDeclarations: None
AlignConsecutiveMacros: None
AlignEscapedNewlines: DontAlign
AlignOperands: Align
AlignTrailingComments: true
AllowAllArgumentsOnNextLine: true
AllowAllConstructorInitializersOnNextLine: true
AllowAllParametersOfDeclarationOnNextLine: true
AllowShortBlocksOnASingleLine: Always
AllowShortCaseLabelsOnASingleLine: true
AllowShortEnumsOnASingleLine: true
AllowShortFunctionsOnASingleLine: Empty
AllowShortIfStatementsOnASingleLine: AllIfsAndElse
AllowShortLambdasOnASingleLine: Empty
AllowShortLoopsOnASingleLine: true
AlwaysBreakAfterDefinitionReturnType: None
AlwaysBreakAfterReturnType: None
AlwaysBreakBeforeMultilineStrings: false
AlwaysBreakTemplateDeclarations: No
AttributeMacros:
- __capability
BasedOnStyle: LLVM
BinPackArguments: true
BinPackParameters: true
BitFieldColonSpacing: Both
BraceWrapping:
AfterCaseLabel: false
AfterClass: false
AfterControlStatement: Never
AfterEnum: false
AfterFunction: false
AfterNamespace: false
AfterObjCDeclaration: false
AfterStruct: false
AfterUnion: false
AfterExternBlock: false
BeforeCatch: false
BeforeElse: false
BeforeLambdaBody: false
BeforeWhile: false
IndentBraces: false
SplitEmptyFunction: true
SplitEmptyRecord: true
SplitEmptyNamespace: true
BreakAfterJavaFieldAnnotations: false
BreakBeforeBinaryOperators: NonAssignment
BreakBeforeBraces: Attach
BreakBeforeConceptDeclarations: false
BreakBeforeInheritanceComma: false
BreakBeforeTernaryOperators: true
BreakConstructorInitializers: BeforeColon
BreakConstructorInitializersBeforeComma: false
BreakInheritanceList: BeforeColon
BreakStringLiterals: false
ColumnLimit: 0
CommentPragmas: ''
CompactNamespaces: false
ConstructorInitializerAllOnOneLineOrOnePerLine: false
ConstructorInitializerIndentWidth: 4
ContinuationIndentWidth: 4
Cpp11BracedListStyle: false
DeriveLineEnding: true
DerivePointerAlignment: true
DisableFormat: false
EmptyLineAfterAccessModifier: Leave
EmptyLineBeforeAccessModifier: Leave
ExperimentalAutoDetectBinPacking: false
FixNamespaceComments: false
ForEachMacros:
- foreach
- Q_FOREACH
- BOOST_FOREACH
IfMacros:
- KJ_IF_MAYBE
IncludeBlocks: Preserve
IncludeCategories:
- Regex: '^"(llvm|llvm-c|clang|clang-c)/'
Priority: 2
SortPriority: 0
CaseSensitive: false
- Regex: '^(<|"(gtest|gmock|isl|json)/)'
Priority: 3
SortPriority: 0
CaseSensitive: false
- Regex: '.*'
Priority: 1
SortPriority: 0
CaseSensitive: false
IncludeIsMainRegex: ''
IncludeIsMainSourceRegex: ''
IndentAccessModifiers: false
IndentCaseBlocks: true
IndentCaseLabels: true
IndentExternBlock: Indent
IndentGotoLabels: false
IndentPPDirectives: None
IndentRequires: true
IndentWidth: 4
IndentWrappedFunctionNames: false
InsertTrailingCommas: None
JavaScriptQuotes: Leave
JavaScriptWrapImports: true
KeepEmptyLinesAtTheStartOfBlocks: true
LambdaBodyIndentation: Signature
Language: Cpp
MacroBlockBegin: ''
MacroBlockEnd: ''
MaxEmptyLinesToKeep: 100000
NamespaceIndentation: None
ObjCBinPackProtocolList: Auto
ObjCBlockIndentWidth: 4
ObjCBreakBeforeNestedBlockParam: true
ObjCSpaceAfterProperty: false
ObjCSpaceBeforeProtocolList: true
PPIndentWidth: -1
PackConstructorInitializers: BinPack
PenaltyBreakAssignment: 1
PenaltyBreakBeforeFirstCallParameter: 1
PenaltyBreakComment: 1
PenaltyBreakFirstLessLess: 1
PenaltyBreakOpenParenthesis: 1
PenaltyBreakString: 1
PenaltyBreakTemplateDeclaration: 1
PenaltyExcessCharacter: 1
PenaltyIndentedWhitespace: 1
PenaltyReturnTypeOnItsOwnLine: 1
PointerAlignment: Right
QualifierAlignment: Leave
ReferenceAlignment: Pointer
ReflowComments: false
RemoveBracesLLVM: false
SeparateDefinitionBlocks: Leave
ShortNamespaceLines: 0
SortIncludes: Never
SortJavaStaticImport: Before
SortUsingDeclarations: false
SpaceAfterCStyleCast: false
SpaceAfterLogicalNot: false
SpaceAfterTemplateKeyword: false
SpaceAroundPointerQualifiers: Default
SpaceBeforeAssignmentOperators: true
SpaceBeforeCaseColon: false
SpaceBeforeCpp11BracedList: false
SpaceBeforeCtorInitializerColon: true
SpaceBeforeInheritanceColon: true
SpaceBeforeParens: ControlStatements
SpaceBeforeParensOptions:
AfterControlStatements: true
AfterForeachMacros: true
AfterFunctionDefinitionName: false
AfterFunctionDeclarationName: false
AfterIfMacros: true
AfterOverloadedOperator: false
BeforeNonEmptyParentheses: false
SpaceBeforeRangeBasedForLoopColon: true
SpaceBeforeSquareBrackets: false
SpaceInEmptyBlock: false
SpaceInEmptyParentheses: false
SpacesBeforeTrailingComments: 2
SpacesInAngles: Leave
SpacesInCStyleCastParentheses: false
SpacesInConditionalStatement: false
SpacesInContainerLiterals: false
SpacesInLineCommentPrefix:
Minimum: 0
Maximum: -1
SpacesInParentheses: false
SpacesInSquareBrackets: false
Standard: Auto
StatementAttributeLikeMacros:
- Q_EMIT
StatementMacros:
- Q_UNUSED
- QT_REQUIRE_VERSION
TabWidth: 4
UseCRLF: false
UseTab: Always
WhitespaceSensitiveMacros:
- STRINGIZE
- PP_STRINGIZE
- BOOST_PP_STRINGIZE
- NS_SWIFT_NAME
- CF_SWIFT_NAME
63 changes: 30 additions & 33 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,82 +1,75 @@
# SCD4x Library
# SCD4x CO2 Library

The SCD4x Library provides an interface to interact with Sensirion SCD4x true CO2 sensors using the I2C protocol in Arduino.

## Warning: Auto-Calibration Issue and Recommended Actions
## Important Notice: Auto-Calibration Issue and Recommended Actions
---------------------------------------------------------------

The SCD4x CO2 sensors come with a default auto-calibrate mode that assumes the lowest CO2 level from the past week as 400ppm. However, it's crucial to be aware that this auto-calibration can result in inaccurate readings if the sensor is placed in an environment that doesn't reach 400ppm CO2 within a week. This issue is particularly important to note when using the sensor for scientific purposes.
When using the SCD4x CO2 sensor, it is essential to be aware of the auto-calibration issue. The default calibration mode assumes a CO2 level of 400ppm, which may not accurately reflect the actual environmental conditions. This can lead to inaccurate readings.

To address this issue, it is recommended to permanently disable the auto-calibration mode by using the provided code snippet:
To address this issue, we recommend disabling the auto-calibration mode by using the provided code snippet:

```cpp
```c++
#include "scd4x.h"

SCD4X co2;

void setup() {
// Initialize the SCD4x library
co2.begin();

// Disable auto-calibration
co2.setCalibrationMode(false);

// Save the settings to EEPROM
co2.saveSettings();
}

void loop() {
// Your code here
}
```

Please exercise caution when using the `saveSettings()` command as it writes to the EEPROM, which has a limited lifespan of approximately 2000 write cycles before potential failure.

Despite the auto-calibration issue, the Sensirion SCD4x CO2 Sensors remain an excellent choice for monitoring indoor air quality, as they have proven to be more accurate than other popular eCO2 sensors.
Please note that exercising caution when using the `saveSettings()` command, as it writes to the EEPROM, which has a limited lifespan of approximately 2000 write cycles before potential failure.

## Factory Calibration with Auto-Calibration Off for 3 test units
![Co Location Calibration](/images/cal.png)

## Features
* Supports multiple I2C busses: scd4x.begin(Wire1);
---------

* Supports multiple I2C busses: `scd4x.begin(Wire1);`
* No extra dependencies required
* Implements only necessary functions
* Uses doubles (64-bit floating-point numbers) for accurate data calculations

## Warnings
- not all functions are implemented
- not compatible with other SCD4x Arduino libraries
- only tested with the esp32
---------

- Not all functions are implemented
- Not compatible with other SCD4x Arduino libraries
- Only tested with the ESP32

### Setup
```c++
#include "scd4x.h"
SCD4X co2;
double CO2 = 0, temperature = 0, humidity = 0;

Wire.begin();
co2.begin(Wire);
co2.startPeriodicMeasurement();
```
### Loop
```c++
while (co2.isDataReady() == false) {
vTaskDelay(50 / portTICK_PERIOD_MS); //check every 50ms
vTaskDelay(50 / portTICK_PERIOD_MS); //check every 50ms
}

if (co2.readMeasurement(CO2, temperature, humidity) == 0) {
Serial.printf("%4.0f,%2.1f,%1.0f\n", CO2, temperature, humidity); //nice formatting of data
}
vTaskDelay(4750 / portTICK_PERIOD_MS); //new data available after approx 5 seconds
Serial.printf("%4.0f,%2.1f,%1.0f\n", CO2, temperature, humidity); //nice formatting of data
} vTaskDelay(4750 / portTICK_PERIOD_MS); //new data available after approx 5 seconds
```

## 🖼️ Schematic
## Schematic
------------

![Schematic](/images/schematic.png)
* The SCD4x sensor can draw up to 205mA peaks at 3.3V (only 18mA average), so ensure you have a robust power source (the above schematic has been tested to work).

* The SCD4x sensor can draw up to 205mA peaks at 3.3V (only 18mA average), so ensure you have a robust power source.
* You only need to solder the 6 shown pins and the thermal pad on the underside to get it working.
* Unfortunately, soldering these sensors with a soldering iron is not easy; an oven or hotplate seems to be the only way.
* Watch out for a temperature offset if you place the sensor in a case or enclosure.

## Function Refreence
## Function Reference
--------------------

| Function | Description |
| ---------------------------- | -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
| `begin()` | Initializes the library. Must be called before any other library functions. |
Expand All @@ -91,8 +84,12 @@ vTaskDelay(4750 / portTICK_PERIOD_MS); //new data available after approx 5 secon
| `getErrorText()` | Converts an error code into descriptive text. Returns a pointer to a constant character array containing the descriptive text of the error. If the error code is not recognized, "Unknown error" is returned. |

## Credits
---------

Based on the work of Raphael Nestler and everyone at Sensirion AG.

Originally created by Raphael Nestler in 2021.

https://github.com/Sensirion/arduino-i2c-scd4x

To help support my work, check out my store: https://keastudios.co.nz/
6 changes: 3 additions & 3 deletions library.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "scd4x-CO2",
"version": "1.2.0",
"version": "1.3.0",
"description": "An Arduino library for interfacing ESP chips with SCD4x CO2 sensors using the I2C protocol.",
"keywords": [
"co2",
Expand All @@ -13,12 +13,12 @@
"type": "git",
"url": "https://github.com/CDFER/scd4x-CO2.git"
},
"author": {
"authors": {
"name": "Chris Dirks",
"url": "https://keastudios.co.nz/about.htm",
"maintainer": true
},
"license": "Other",
"license": "BSD 3-Clause",
"homepage": "https://github.com/CDFER/scd4x-CO2",
"frameworks": "arduino",
"platforms": "*"
Expand Down
21 changes: 0 additions & 21 deletions platformio.ini

This file was deleted.

Loading

0 comments on commit 3490d06

Please sign in to comment.