forked from arendst/Tasmota
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add support for SGP41 TVOC/NOx Sensor (arendst#18880)
* Initial support for SGP41 * Removing delay() use from SGP4x driver * Using i18n for TVOC/NOx raw values as well
- Loading branch information
Showing
18 changed files
with
1,795 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Changelog | ||
All notable changes to this project will be documented in this file. | ||
|
||
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), | ||
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). | ||
|
||
|
||
## [0.1.0] - 2021-11-17 | ||
|
||
Initial release | ||
|
||
[0.1.0]: https://github.com/Sensirion/arduino-i2c-sgp41/releases/tag/0.1.0 | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
BSD 3-Clause License | ||
|
||
Copyright (c) 2021, Sensirion AG | ||
All rights reserved. | ||
|
||
Redistribution and use in source and binary forms, with or without | ||
modification, are permitted provided that the following conditions are met: | ||
|
||
1. Redistributions of source code must retain the above copyright notice, this | ||
list of conditions and the following disclaimer. | ||
|
||
2. Redistributions in binary form must reproduce the above copyright notice, | ||
this list of conditions and the following disclaimer in the documentation | ||
and/or other materials provided with the distribution. | ||
|
||
3. Neither the name of the copyright holder nor the names of its | ||
contributors may be used to endorse or promote products derived from | ||
this software without specific prior written permission. | ||
|
||
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | ||
DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE | ||
FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | ||
DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR | ||
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER | ||
CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, | ||
OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | ||
OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
# Sensirion I2C SGP41 Arduino Library | ||
|
||
This is the Sensirion SGP41 library for Arduino using the | ||
modules I2C interface. | ||
|
||
[<center><img src="images/SGP41.png" width="300px"></center>](https://www.sensirion.com/en/environmental-sensors/gas-sensors/sgp41) | ||
|
||
Click [here](https://www.sensirion.com/en/environmental-sensors/gas-sensors/sgp41) to learn more about the SGP41 sensor. | ||
|
||
|
||
# Installation | ||
|
||
To install, download the latest release as .zip file and add it to your | ||
[Arduino IDE](http://www.arduino.cc/en/main/software) via | ||
|
||
Sketch => Include Library => Add .ZIP Library... | ||
|
||
Don't forget to **install the dependencies** listed below the same way via `Add | ||
.ZIP Library` | ||
|
||
Note: Installation via the Arduino Library Manager is coming soon. | ||
|
||
# Dependencies | ||
|
||
* [Sensirion Core](https://github.com/Sensirion/arduino-core) | ||
|
||
|
||
# Quick Start | ||
|
||
1. Connect the SGP41 Sensor to your Arduino board's standard | ||
I2C bus. Check the pinout of your Arduino board to find the correct pins. | ||
The pinout of the SGP41 Sensor board can be found in the | ||
data sheet. | ||
|
||
* **VDD** of the SEK-SGP41 to the **3.3V** of your Arduino board | ||
* **GND** of the SEK-SGP41 to the **GND** of your Arduino board | ||
* **SCL** of the SEK-SGP41 to the **SCL** of your Arduino board | ||
* **SDA** of the SEK-SGP41 to the **SDA** of your Arduino board | ||
|
||
2. Open the `exampleUsage` sample project within the Arduino IDE | ||
|
||
File => Examples => Sensirion I2C SGP41 => exampleUsage | ||
|
||
3. Click the `Upload` button in the Arduino IDE or | ||
|
||
Sketch => Upload | ||
|
||
4. When the upload process has finished, open the `Serial Monitor` or `Serial | ||
Plotter` via the `Tools` menu to observe the measurement values. Note that | ||
the `Baud Rate` in the corresponding window has to be set to `115200 baud`. | ||
|
||
# Contributing | ||
|
||
**Contributions are welcome!** | ||
|
||
We develop and test this driver using our company internal tools (version | ||
control, continuous integration, code review etc.) and automatically | ||
synchronize the master branch with GitHub. But this doesn't mean that we don't | ||
respond to issues or don't accept pull requests on GitHub. In fact, you're very | ||
welcome to open issues or create pull requests :) | ||
|
||
This Sensirion library uses | ||
[`clang-format`](https://releases.llvm.org/download.html) to standardize the | ||
formatting of all our `.cpp` and `.h` files. Make sure your contributions are | ||
formatted accordingly: | ||
|
||
The `-i` flag will apply the format changes to the files listed. | ||
|
||
```bash | ||
clang-format -i src/*.cpp src/*.h | ||
``` | ||
|
||
Note that differences from this formatting will result in a failed build until | ||
they are fixed. | ||
|
||
# License | ||
|
||
See [LICENSE](LICENSE). |
124 changes: 124 additions & 0 deletions
124
lib/lib_i2c/arduino-i2c-sgp41/examples/exampleUsage/exampleUsage.ino
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,124 @@ | ||
/* | ||
* I2C-Generator: 0.3.0 | ||
* Yaml Version: 0.1.0 | ||
* Template Version: 0.7.0-62-g3d691f9 | ||
*/ | ||
/* | ||
* Copyright (c) 2021, Sensirion AG | ||
* All rights reserved. | ||
* | ||
* Redistribution and use in source and binary forms, with or without | ||
* modification, are permitted provided that the following conditions are met: | ||
* | ||
* * Redistributions of source code must retain the above copyright notice, this | ||
* list of conditions and the following disclaimer. | ||
* | ||
* * Redistributions in binary form must reproduce the above copyright notice, | ||
* this list of conditions and the following disclaimer in the documentation | ||
* and/or other materials provided with the distribution. | ||
* | ||
* * Neither the name of Sensirion AG nor the names of its | ||
* contributors may be used to endorse or promote products derived from | ||
* this software without specific prior written permission. | ||
* | ||
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | ||
* AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | ||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | ||
* ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE | ||
* LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | ||
* CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | ||
* SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | ||
* INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | ||
* CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | ||
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | ||
* POSSIBILITY OF SUCH DAMAGE. | ||
*/ | ||
|
||
#include <Arduino.h> | ||
#include <SensirionI2CSgp41.h> | ||
#include <Wire.h> | ||
|
||
SensirionI2CSgp41 sgp41; | ||
|
||
// time in seconds needed for NOx conditioning | ||
uint16_t conditioning_s = 10; | ||
|
||
void setup() { | ||
|
||
Serial.begin(115200); | ||
while (!Serial) { | ||
delay(100); | ||
} | ||
|
||
Wire.begin(); | ||
|
||
uint16_t error; | ||
char errorMessage[256]; | ||
|
||
sgp41.begin(Wire); | ||
|
||
uint16_t serialNumber[3]; | ||
uint8_t serialNumberSize = 3; | ||
|
||
error = sgp41.getSerialNumber(serialNumber, serialNumberSize); | ||
|
||
if (error) { | ||
Serial.print("Error trying to execute getSerialNumber(): "); | ||
errorToString(error, errorMessage, 256); | ||
Serial.println(errorMessage); | ||
} else { | ||
Serial.print("SerialNumber:"); | ||
Serial.print("0x"); | ||
for (size_t i = 0; i < serialNumberSize; i++) { | ||
uint16_t value = serialNumber[i]; | ||
Serial.print(value < 4096 ? "0" : ""); | ||
Serial.print(value < 256 ? "0" : ""); | ||
Serial.print(value < 16 ? "0" : ""); | ||
Serial.print(value, HEX); | ||
} | ||
Serial.println(); | ||
} | ||
|
||
uint16_t testResult; | ||
error = sgp41.executeSelfTest(testResult); | ||
if (error) { | ||
Serial.print("Error trying to execute executeSelfTest(): "); | ||
errorToString(error, errorMessage, 256); | ||
Serial.println(errorMessage); | ||
} else if (testResult != 0xD400) { | ||
Serial.print("executeSelfTest failed with error: "); | ||
Serial.println(testResult); | ||
} | ||
} | ||
|
||
void loop() { | ||
uint16_t error; | ||
char errorMessage[256]; | ||
uint16_t defaultRh = 0x8000; | ||
uint16_t defaultT = 0x6666; | ||
uint16_t srawVoc = 0; | ||
uint16_t srawNox = 0; | ||
|
||
delay(1000); | ||
|
||
if (conditioning_s > 0) { | ||
// During NOx conditioning (10s) SRAW NOx will remain 0 | ||
error = sgp41.executeConditioning(defaultRh, defaultT, srawVoc); | ||
conditioning_s--; | ||
} else { | ||
// Read Measurement | ||
error = sgp41.measureRawSignals(defaultRh, defaultT, srawVoc, srawNox); | ||
} | ||
|
||
if (error) { | ||
Serial.print("Error trying to execute measureRawSignals(): "); | ||
errorToString(error, errorMessage, 256); | ||
Serial.println(errorMessage); | ||
} else { | ||
Serial.print("SRAW_VOC:"); | ||
Serial.print(srawVoc); | ||
Serial.print("\t"); | ||
Serial.print("SRAW_NOx:"); | ||
Serial.println(srawNox); | ||
} | ||
} |
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
####################################### | ||
# Syntax Coloring Map | ||
####################################### | ||
|
||
####################################### | ||
# Datatypes (KEYWORD1) | ||
####################################### | ||
|
||
SensirionI2CSgp41 KEYWORD1 | ||
|
||
####################################### | ||
# Methods and Functions (KEYWORD2) | ||
####################################### | ||
executeConditioning KEYWORD2 | ||
measureRawSignals KEYWORD2 | ||
executeSelfTest KEYWORD2 | ||
turnHeaterOff KEYWORD2 | ||
getSerialNumber KEYWORD2 | ||
####################################### | ||
# Instances (KEYWORD2) | ||
####################################### | ||
|
||
sgp41 KEYWORD2 | ||
|
||
####################################### | ||
# Constants (LITERAL1) | ||
####################################### |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
name=Sensirion I2C SGP41 | ||
version=0.1.0 | ||
author=Sensirion | ||
maintainer=Sensirion | ||
sentence=Library for the SGP41 sensor family by Sensirion | ||
paragraph=Enables you to use the SGP41 via I2C. | ||
url=https://github.com/Sensirion/arduino-i2c-sgp41 | ||
category=Sensors | ||
depends=Sensirion Core | ||
includes=SensirionI2CSgp41.h |
Oops, something went wrong.