mirror of
https://github.com/arendst/Tasmota.git
synced 2025-07-24 19:26:37 +00:00
update adafruit sgp30 lib
This commit is contained in:
parent
d40a9b96d7
commit
22a4410280
0
lib/Adafruit_SGP30-1.0.0.13/.github/ISSUE_TEMPLATE.md → lib/Adafruit_SGP30-1.0.3/.github/ISSUE_TEMPLATE.md
vendored
Normal file → Executable file
0
lib/Adafruit_SGP30-1.0.0.13/.github/ISSUE_TEMPLATE.md → lib/Adafruit_SGP30-1.0.3/.github/ISSUE_TEMPLATE.md
vendored
Normal file → Executable file
0
lib/Adafruit_SGP30-1.0.0.13/.github/PULL_REQUEST_TEMPLATE.md → lib/Adafruit_SGP30-1.0.3/.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file → Executable file
0
lib/Adafruit_SGP30-1.0.0.13/.github/PULL_REQUEST_TEMPLATE.md → lib/Adafruit_SGP30-1.0.3/.github/PULL_REQUEST_TEMPLATE.md
vendored
Normal file → Executable file
0
lib/Adafruit_SGP30-1.0.0.13/.gitignore → lib/Adafruit_SGP30-1.0.3/.gitignore
vendored
Normal file → Executable file
0
lib/Adafruit_SGP30-1.0.0.13/.gitignore → lib/Adafruit_SGP30-1.0.3/.gitignore
vendored
Normal file → Executable file
0
lib/Adafruit_SGP30-1.0.0.13/.travis.yml → lib/Adafruit_SGP30-1.0.3/.travis.yml
Normal file → Executable file
0
lib/Adafruit_SGP30-1.0.0.13/.travis.yml → lib/Adafruit_SGP30-1.0.3/.travis.yml
Normal file → Executable file
58
lib/Adafruit_SGP30-1.0.0.13/Adafruit_SGP30.cpp → lib/Adafruit_SGP30-1.0.3/Adafruit_SGP30.cpp
Normal file → Executable file
58
lib/Adafruit_SGP30-1.0.0.13/Adafruit_SGP30.cpp → lib/Adafruit_SGP30-1.0.3/Adafruit_SGP30.cpp
Normal file → Executable file
@ -37,7 +37,7 @@
|
|||||||
//#define I2C_DEBUG
|
//#define I2C_DEBUG
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
/*!
|
/*!
|
||||||
@brief Instantiates a new SGP30 class
|
@brief Instantiates a new SGP30 class
|
||||||
*/
|
*/
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
@ -45,7 +45,7 @@ Adafruit_SGP30::Adafruit_SGP30() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
/*!
|
/*!
|
||||||
@brief Setups the hardware and detects a valid SGP30. Initializes I2C
|
@brief Setups the hardware and detects a valid SGP30. Initializes I2C
|
||||||
then reads the serialnumber and checks that we are talking to an SGP30
|
then reads the serialnumber and checks that we are talking to an SGP30
|
||||||
@param theWire Optional pointer to I2C interface, otherwise use Wire
|
@param theWire Optional pointer to I2C interface, otherwise use Wire
|
||||||
@ -60,31 +60,32 @@ boolean Adafruit_SGP30::begin(TwoWire *theWire) {
|
|||||||
_i2c = theWire;
|
_i2c = theWire;
|
||||||
}
|
}
|
||||||
|
|
||||||
_i2c->begin();
|
// assume i2c initialized already to avoid resetting clock stretching
|
||||||
|
// _i2c->begin();
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
uint8_t command[2];
|
uint8_t command[2];
|
||||||
command[0] = 0x36;
|
command[0] = 0x36;
|
||||||
command[1] = 0x82;
|
command[1] = 0x82;
|
||||||
if (! readWordFromCommand(command, 2, 10, serialnumber, 3))
|
if (! readWordFromCommand(command, 2, 10, serialnumber, 3))
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
uint16_t featureset;
|
uint16_t featureset;
|
||||||
command[0] = 0x20;
|
command[0] = 0x20;
|
||||||
command[1] = 0x2F;
|
command[1] = 0x2F;
|
||||||
if (! readWordFromCommand(command, 2, 10, &featureset, 1))
|
if (! readWordFromCommand(command, 2, 10, &featureset, 1))
|
||||||
return false;
|
return false;
|
||||||
//Serial.print("Featureset 0x"); Serial.println(featureset, HEX);
|
//Serial.print("Featureset 0x"); Serial.println(featureset, HEX);
|
||||||
if (featureset != SGP30_FEATURESET)
|
if (featureset != SGP30_FEATURESET)
|
||||||
return false;
|
return false;
|
||||||
if (! IAQinit())
|
if (! IAQinit())
|
||||||
return false;
|
return false;
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
/*!
|
/*!
|
||||||
@brief Commands the sensor to begin the IAQ algorithm. Must be called after startup.
|
@brief Commands the sensor to begin the IAQ algorithm. Must be called after startup.
|
||||||
@returns True if command completed successfully, false if something went wrong!
|
@returns True if command completed successfully, false if something went wrong!
|
||||||
*/
|
*/
|
||||||
@ -97,7 +98,7 @@ boolean Adafruit_SGP30::IAQinit(void) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
/*!
|
/*!
|
||||||
@brief Commands the sensor to take a single eCO2/VOC measurement. Places results in {@link TVOC} and {@link eCO2}
|
@brief Commands the sensor to take a single eCO2/VOC measurement. Places results in {@link TVOC} and {@link eCO2}
|
||||||
@returns True if command completed successfully, false if something went wrong!
|
@returns True if command completed successfully, false if something went wrong!
|
||||||
*/
|
*/
|
||||||
@ -113,9 +114,9 @@ boolean Adafruit_SGP30::IAQmeasure(void) {
|
|||||||
eCO2 = reply[0];
|
eCO2 = reply[0];
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
/*!
|
/*!
|
||||||
@brief Request baseline calibration values for both CO2 and TVOC IAQ calculations. Places results in parameter memory locaitons.
|
@brief Request baseline calibration values for both CO2 and TVOC IAQ calculations. Places results in parameter memory locaitons.
|
||||||
@param eco2_base A pointer to a uint16_t which we will save the calibration value to
|
@param eco2_base A pointer to a uint16_t which we will save the calibration value to
|
||||||
@param tvoc_base A pointer to a uint16_t which we will save the calibration value to
|
@param tvoc_base A pointer to a uint16_t which we will save the calibration value to
|
||||||
@ -135,7 +136,7 @@ boolean Adafruit_SGP30::getIAQBaseline(uint16_t *eco2_base, uint16_t *tvoc_base)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
/*!
|
/*!
|
||||||
@brief Assign baseline calibration values for both CO2 and TVOC IAQ calculations.
|
@brief Assign baseline calibration values for both CO2 and TVOC IAQ calculations.
|
||||||
@param eco2_base A uint16_t which we will save the calibration value from
|
@param eco2_base A uint16_t which we will save the calibration value from
|
||||||
@param tvoc_base A uint16_t which we will save the calibration value from
|
@param tvoc_base A uint16_t which we will save the calibration value from
|
||||||
@ -157,7 +158,30 @@ boolean Adafruit_SGP30::setIAQBaseline(uint16_t eco2_base, uint16_t tvoc_base) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
/*!
|
/*!
|
||||||
|
@brief Set the absolute humidity value [mg/m^3] for compensation to increase precision of TVOC and eCO2.
|
||||||
|
@param absolute_humidity A uint32_t [mg/m^3] which we will be used for compensation. If the absolute humidity is set to zero, humidity compensation will be disabled.
|
||||||
|
@returns True if command completed successfully, false if something went wrong!
|
||||||
|
*/
|
||||||
|
/**************************************************************************/
|
||||||
|
boolean Adafruit_SGP30::setHumidity(uint32_t absolute_humidity) {
|
||||||
|
if (absolute_humidity > 256000) {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
uint16_t ah_scaled = (uint16_t)(((uint64_t)absolute_humidity * 256 * 16777) >> 24);
|
||||||
|
uint8_t command[5];
|
||||||
|
command[0] = 0x20;
|
||||||
|
command[1] = 0x61;
|
||||||
|
command[2] = ah_scaled >> 8;
|
||||||
|
command[3] = ah_scaled & 0xFF;
|
||||||
|
command[4] = generateCRC(command+2, 2);
|
||||||
|
|
||||||
|
return readWordFromCommand(command, 5, 10);
|
||||||
|
}
|
||||||
|
|
||||||
|
/**************************************************************************/
|
||||||
|
/*!
|
||||||
@brief I2C low level interfacing
|
@brief I2C low level interfacing
|
||||||
*/
|
*/
|
||||||
/**************************************************************************/
|
/**************************************************************************/
|
||||||
@ -186,16 +210,16 @@ boolean Adafruit_SGP30::readWordFromCommand(uint8_t command[], uint8_t commandLe
|
|||||||
|
|
||||||
delay(delayms);
|
delay(delayms);
|
||||||
|
|
||||||
if (readlen == 0)
|
if (readlen == 0)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
uint8_t replylen = readlen * (SGP30_WORD_LEN +1);
|
uint8_t replylen = readlen * (SGP30_WORD_LEN +1);
|
||||||
if (_i2c->requestFrom(_i2caddr, replylen) != replylen)
|
if (_i2c->requestFrom(_i2caddr, replylen) != replylen)
|
||||||
return false;
|
return false;
|
||||||
uint8_t replybuffer[replylen];
|
uint8_t replybuffer[replylen];
|
||||||
#ifdef I2C_DEBUG
|
#ifdef I2C_DEBUG
|
||||||
Serial.print("\t\t<- ");
|
Serial.print("\t\t<- ");
|
||||||
#endif
|
#endif
|
||||||
for (uint8_t i=0; i<replylen; i++) {
|
for (uint8_t i=0; i<replylen; i++) {
|
||||||
replybuffer[i] = _i2c->read();
|
replybuffer[i] = _i2c->read();
|
||||||
#ifdef I2C_DEBUG
|
#ifdef I2C_DEBUG
|
1
lib/Adafruit_SGP30-1.0.0.13/Adafruit_SGP30.h → lib/Adafruit_SGP30-1.0.3/Adafruit_SGP30.h
Normal file → Executable file
1
lib/Adafruit_SGP30-1.0.0.13/Adafruit_SGP30.h → lib/Adafruit_SGP30-1.0.3/Adafruit_SGP30.h
Normal file → Executable file
@ -42,6 +42,7 @@ class Adafruit_SGP30 {
|
|||||||
|
|
||||||
boolean getIAQBaseline(uint16_t *eco2_base, uint16_t *tvoc_base);
|
boolean getIAQBaseline(uint16_t *eco2_base, uint16_t *tvoc_base);
|
||||||
boolean setIAQBaseline(uint16_t eco2_base, uint16_t tvoc_base);
|
boolean setIAQBaseline(uint16_t eco2_base, uint16_t tvoc_base);
|
||||||
|
boolean setHumidity(uint32_t absolute_humidity);
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* The last measurement of the IAQ-calculated Total Volatile Organic Compounds in ppb. This value is set when you call {@link IAQmeasure()}
|
* The last measurement of the IAQ-calculated Total Volatile Organic Compounds in ppb. This value is set when you call {@link IAQmeasure()}
|
0
lib/Adafruit_SGP30-1.0.0.13/README.md → lib/Adafruit_SGP30-1.0.3/README.md
Normal file → Executable file
0
lib/Adafruit_SGP30-1.0.0.13/README.md → lib/Adafruit_SGP30-1.0.3/README.md
Normal file → Executable file
16
lib/Adafruit_SGP30-1.0.0.13/examples/sgp30test/sgp30test.ino → lib/Adafruit_SGP30-1.0.3/examples/sgp30test/sgp30test.ino
Normal file → Executable file
16
lib/Adafruit_SGP30-1.0.0.13/examples/sgp30test/sgp30test.ino → lib/Adafruit_SGP30-1.0.3/examples/sgp30test/sgp30test.ino
Normal file → Executable file
@ -3,6 +3,17 @@
|
|||||||
|
|
||||||
Adafruit_SGP30 sgp;
|
Adafruit_SGP30 sgp;
|
||||||
|
|
||||||
|
/* return absolute humidity [mg/m^3] with approximation formula
|
||||||
|
* @param temperature [°C]
|
||||||
|
* @param humidity [%RH]
|
||||||
|
*/
|
||||||
|
uint32_t getAbsoluteHumidity(float temperature, float humidity) {
|
||||||
|
// approximation formula from Sensirion SGP30 Driver Integration chapter 3.15
|
||||||
|
const float absoluteHumidity = 216.7f * ((humidity / 100.0f) * 6.112f * exp((17.62f * temperature) / (243.12f + temperature)) / (273.15f + temperature)); // [g/m^3]
|
||||||
|
const uint32_t absoluteHumidityScaled = static_cast<uint32_t>(1000.0f * absoluteHumidity); // [mg/m^3]
|
||||||
|
return absoluteHumidityScaled;
|
||||||
|
}
|
||||||
|
|
||||||
void setup() {
|
void setup() {
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
Serial.println("SGP30 test");
|
Serial.println("SGP30 test");
|
||||||
@ -22,6 +33,11 @@ void setup() {
|
|||||||
|
|
||||||
int counter = 0;
|
int counter = 0;
|
||||||
void loop() {
|
void loop() {
|
||||||
|
// If you have a temperature / humidity sensor, you can set the absolute humidity to enable the humditiy compensation for the air quality signals
|
||||||
|
//float temperature = 22.1; // [°C]
|
||||||
|
//float humidity = 45.2; // [%RH]
|
||||||
|
//sgp.setHumidity(getAbsoluteHumidity(temperature, humidity));
|
||||||
|
|
||||||
if (! sgp.IAQmeasure()) {
|
if (! sgp.IAQmeasure()) {
|
||||||
Serial.println("Measurement failed");
|
Serial.println("Measurement failed");
|
||||||
return;
|
return;
|
2
lib/Adafruit_SGP30-1.0.0.13/library.properties → lib/Adafruit_SGP30-1.0.3/library.properties
Normal file → Executable file
2
lib/Adafruit_SGP30-1.0.0.13/library.properties → lib/Adafruit_SGP30-1.0.3/library.properties
Normal file → Executable file
@ -1,5 +1,5 @@
|
|||||||
name=Adafruit SGP30 Sensor
|
name=Adafruit SGP30 Sensor
|
||||||
version=1.0.2
|
version=1.0.3
|
||||||
author=Adafruit
|
author=Adafruit
|
||||||
maintainer=Adafruit <info@adafruit.com>
|
maintainer=Adafruit <info@adafruit.com>
|
||||||
sentence=This is an Arduino library for the Adafruit SGP30 Gas / Air Quality Sensor
|
sentence=This is an Arduino library for the Adafruit SGP30 Gas / Air Quality Sensor
|
0
lib/Adafruit_SGP30-1.0.0.13/license.txt → lib/Adafruit_SGP30-1.0.3/license.txt
Normal file → Executable file
0
lib/Adafruit_SGP30-1.0.0.13/license.txt → lib/Adafruit_SGP30-1.0.3/license.txt
Normal file → Executable file
Loading…
x
Reference in New Issue
Block a user