diff --git a/README.md b/README.md index 11e44e7..56f6aa2 100644 --- a/README.md +++ b/README.md @@ -23,7 +23,7 @@ The library supports 2 types of interfaces, a synchronous and an asynchronous in The CO2 and TVOC values can be read up to once per second (1 Hz). Ethanol and H2, the raw data can be sampled up to 40 Hz. -It may take up to 10 seconds (maybe more) before the sensor produces real data. +The first 15 seconds the sensor needs to stabilize. Thereafter one gets real data. #### I2C performance @@ -109,6 +109,12 @@ Note: if the sensor has no reads done, these values tend to go to zero. This is - **void setBaseline(uint16_t CO2, uint16_t TVOC)** sets the baseline values. +For faster accurate results for the TVOC under bad air conditions, read **Inceptive Baseline for TVOC measurements** +(not tested) +- **bool getTVOCBaseline(uint16_t \*TVOC)** retrieves the TVOC start value from the sensor. +- **void setTVOCBaseline(uint16_t TVOC)** sets the TVOC start value. + + ### Misc - **int lastError()** returns last error. (needs rework) @@ -125,7 +131,7 @@ One should use these functions more as a relative indication than as an absolute - **float getH2()** gets the H2 concentration. Units ppm. - **float getEthanol()** gets the Ethanol concentration. Units ppm. -The used references are based upon (1) averaging raw data in outside air at 22°C @ 1 meter and (2) the assumption that this is 0.4 resp 0.5 ppm. (Note only 1 significant digit) as mentioned is datasheet P2. +The used references are based upon (1) averaging raw data in outside air at 22°C @ 1 meter and (2) the assumption that this is 0.4 resp 0.5 ppm. (Note only 1 significant digit) as mentioned in datasheet P2. - **void setSrefH2(uint16_t s = 13119)** // 13119 is my measurement. - **uint16_t getSrefH2()** returns value set. @@ -137,7 +143,6 @@ The used references are based upon (1) averaging raw data in outside air at 22° - redo **getID()** - redo **lastError()** -- implement the TVOC starter baseline. - test test test .... - CRC handling - error handling diff --git a/SGP30.cpp b/SGP30.cpp index 90ccc67..3ee6a2f 100644 --- a/SGP30.cpp +++ b/SGP30.cpp @@ -1,7 +1,7 @@ // // FILE: SGP30.cpp // AUTHOR: Rob Tillaart -// VERSION: 0.1.2 +// VERSION: 0.1.3 // DATE: 2021-06-24 // PURPOSE: SGP30 library for Arduino // URL: https://github.com/RobTillaart/SGP30 @@ -11,7 +11,7 @@ // 0.1.0 2021-06-24 initial version // 0.1.1 2021-06-26 add get/setBaseline ++ // 0.1.2 2021-06-26 experimental add units H2 + Ethanol -// +// 0.1.3 2021-06-26 add get/setTVOCbaseline() #include "SGP30.h" @@ -284,6 +284,28 @@ bool SGP30::getBaseline(uint16_t *CO2, uint16_t *TVOC) } +void SGP30::setTVOCBaseline(uint16_t TVOC) +{ + _command(0x2077, TVOC); +} + + +bool SGP30::getTVOCBaseline(uint16_t *TVOC) +{ + _command(0x20B3); + // TODO error handling + // TODO CRC + if (_wire->requestFrom(_address, (uint8_t)3) != 3) + { + return false; + } + *TVOC = _wire->read() << 8; + *TVOC += _wire->read(); + _wire->read(); // skip crc + return true; +} + + ///////////////////////////////////////////////////// // // MISC diff --git a/SGP30.h b/SGP30.h index eb2f9ef..3fded76 100644 --- a/SGP30.h +++ b/SGP30.h @@ -2,7 +2,7 @@ // // FILE: SGP30.h // AUTHOR: Rob Tillaart -// VERSION: 0.1.2 +// VERSION: 0.1.3 // DATE: 2021-06-24 // PURPOSE: SGP30 library for Arduino // URL: https://github.com/RobTillaart/SGP30 @@ -12,7 +12,7 @@ #include "Arduino.h" #include "Wire.h" -#define SGP30_LIB_VERSION (F("0.1.2")) +#define SGP30_LIB_VERSION (F("0.1.3")) #define SGP30_OK 0x00 @@ -69,12 +69,11 @@ class SGP30 void setBaseline(uint16_t CO2, uint16_t TVOC); bool getBaseline(uint16_t *CO2, uint16_t *TVOC); + + // See Inceptive Baseline for TVOC measurements in data sheet + void setTVOCBaseline(uint16_t TVOC); + bool getTVOCBaseline(uint16_t *TVOC); -/* - // faster startup - void setTVOCStarter() {}; // 0x2077 - void getTVOCStarter() {}; // 0x20B3 -*/ // experimental // 13119 = average raw measured outside 22°C (example) diff --git a/keywords.txt b/keywords.txt index 030e1e8..21dca79 100644 --- a/keywords.txt +++ b/keywords.txt @@ -34,6 +34,8 @@ setAbsHumidity KEYWORD2 setBaseline KEYWORD2 getBaseline KEYWORD2 +setTVOCBaseline KEYWORD2 +getTVOCBaseline KEYWORD2 setSrefH2 KEYWORD2 getSrefH2 KEYWORD2 diff --git a/library.json b/library.json index 8b26eec..22adfe1 100644 --- a/library.json +++ b/library.json @@ -15,7 +15,7 @@ "type": "git", "url": "https://github.com/RobTillaart/SGP30.git" }, - "version": "0.1.2", + "version": "0.1.3", "license": "MIT", "frameworks": "arduino", "platforms": "*" diff --git a/library.properties b/library.properties index b4f5565..3eed340 100644 --- a/library.properties +++ b/library.properties @@ -1,5 +1,5 @@ name=SGP30 -version=0.1.2 +version=0.1.3 author=Rob Tillaart maintainer=Rob Tillaart sentence=Arduino library for SGP30 environment sensor.