Skip to content

Commit

Permalink
Develop (#4)
Browse files Browse the repository at this point in the history
* 0.1.3 add set/getTVOCbaseline
  • Loading branch information
RobTillaart authored Jun 27, 2021
1 parent 5ea6d73 commit 1c41269
Show file tree
Hide file tree
Showing 6 changed files with 42 additions and 14 deletions.
11 changes: 8 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)
Expand All @@ -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.
Expand All @@ -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
Expand Down
26 changes: 24 additions & 2 deletions SGP30.cpp
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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"
Expand Down Expand Up @@ -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
Expand Down
13 changes: 6 additions & 7 deletions SGP30.h
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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)
Expand Down
2 changes: 2 additions & 0 deletions keywords.txt
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ setAbsHumidity KEYWORD2

setBaseline KEYWORD2
getBaseline KEYWORD2
setTVOCBaseline KEYWORD2
getTVOCBaseline KEYWORD2

setSrefH2 KEYWORD2
getSrefH2 KEYWORD2
Expand Down
2 changes: 1 addition & 1 deletion library.json
Original file line number Diff line number Diff line change
Expand Up @@ -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": "*"
Expand Down
2 changes: 1 addition & 1 deletion library.properties
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name=SGP30
version=0.1.2
version=0.1.3
author=Rob Tillaart <rob.tillaart@gmail.com>
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
sentence=Arduino library for SGP30 environment sensor.
Expand Down

0 comments on commit 1c41269

Please sign in to comment.