Adafruit SGP-40 Library
Adafruit_SGP40.h
Go to the documentation of this file.
1 
21 #ifndef ADAFRUIT_SGP40_H
22 #define ADAFRUIT_SGP40_H
23 
24 #include "Arduino.h"
25 #include <Adafruit_BusIO_Register.h>
26 #include <Adafruit_I2CDevice.h>
27 extern "C" {
28 #include "sensirion_arch_config.h"
29 #include "sensirion_voc_algorithm.h"
30 };
31 
32 // the i2c address
33 #define SGP40_I2CADDR_DEFAULT 0x59
34 
35 // commands and constants
36 #define SGP40_FEATURESET 0x0020
37 #define SGP40_CRC8_POLYNOMIAL 0x31
38 #define SGP40_CRC8_INIT 0xFF
39 #define SGP40_WORD_LEN 2
40 
41 
46 public:
48  bool begin(TwoWire *theWire = &Wire);
49  bool selfTest(void);
50 
51  bool softReset();
52  bool heaterOff();
53  uint16_t measureRaw(float temperature = 25, float humidity = 50);
54  int32_t measureVocIndex(float temperature = 25, float humidity = 50);
55 
58  uint16_t serialnumber[3];
59 
60 private:
61  Adafruit_I2CDevice *i2c_dev = NULL;
62  void write(uint8_t address, uint8_t *data, uint8_t n);
63  void read(uint8_t address, uint8_t *data, uint8_t n);
64  bool readWordFromCommand(uint8_t command[], uint8_t commandLength,
65  uint16_t delayms, uint16_t *readdata = NULL,
66  uint8_t readlen = 0);
67  uint8_t generateCRC(uint8_t data[], uint8_t datalen);
68 
69  VocAlgorithmParams voc_algorithm_params;
70 };
71 #endif // ndef ADAFRUIT_SGP40_H
bool softReset()
Commands the sensor to perform a soft reset using the "General Call" mode. Take note that this is not...
Definition: Adafruit_SGP40.cpp:83
bool heaterOff()
Request the sensor to turn off heater to lower curent consumption. Launching a measurement automatica...
Definition: Adafruit_SGP40.cpp:96
bool begin(TwoWire *theWire=&Wire)
Setups the hardware and detects a valid SGP40. Initializes I2C then reads the serialnumber and checks...
Definition: Adafruit_SGP40.cpp:46
uint16_t serialnumber[3]
Definition: Adafruit_SGP40.h:58
uint16_t measureRaw(float temperature=25, float humidity=50)
Return the raw gas measurement.
Definition: Adafruit_SGP40.cpp:146
Adafruit_SGP40()
Instantiates a new SGP40 class.
Definition: Adafruit_SGP40.cpp:36
int32_t measureVocIndex(float temperature=25, float humidity=50)
Combined the measured gasses, temperature, and humidity to calculate the VOC Index.
Definition: Adafruit_SGP40.cpp:131
bool selfTest(void)
Request the sensor to perform a self-test, returning the result.
Definition: Adafruit_SGP40.cpp:108
Class that stores state and functions for interacting with SGP40 Gas Sensor.
Definition: Adafruit_SGP40.h:45