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 <Adafruit_BusIO_Register.h>
25 #include <Adafruit_I2CDevice.h>
26 
27 #include "Arduino.h"
28 extern "C" {
29 #include "sensirion_arch_config.h"
30 #include "sensirion_voc_algorithm.h"
31 };
32 
33 // the i2c address
34 #define SGP40_I2CADDR_DEFAULT 0x59
35 
36 // commands and constants
37 #define SGP40_FEATURESET 0x0020
38 #define SGP40_CRC8_POLYNOMIAL 0x31
39 #define SGP40_CRC8_INIT 0xFF
40 #define SGP40_WORD_LEN 2
41 
42 
47  public:
49  bool begin(TwoWire* theWire = &Wire);
50  bool selfTest(void);
51 
52  bool softReset();
53  bool heaterOff();
54  uint16_t measureRaw(float temperature = 25, float humidity = 50);
55  int32_t measureVocIndex(float temperature = 25, float humidity = 50);
56 
59  uint16_t serialnumber[3];
60 
61  private:
62  Adafruit_I2CDevice* i2c_dev = NULL;
63  void write(uint8_t address, uint8_t* data, uint8_t n);
64  void read(uint8_t address, uint8_t* data, uint8_t n);
65  bool readWordFromCommand(uint8_t command[], uint8_t commandLength,
66  uint16_t delayms, uint16_t* readdata = NULL,
67  uint8_t readlen = 0);
68  uint8_t generateCRC(uint8_t data[], uint8_t datalen);
69 
70  VocAlgorithmParams voc_algorithm_params;
71 };
72 #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:84
bool heaterOff()
Request the sensor to turn off heater to lower curent consumption. Launching a measurement automatica...
Definition: Adafruit_SGP40.cpp:97
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:47
uint16_t serialnumber[3]
Definition: Adafruit_SGP40.h:59
uint16_t measureRaw(float temperature=25, float humidity=50)
Return the raw gas measurement.
Definition: Adafruit_SGP40.cpp:147
Adafruit_SGP40()
Instantiates a new SGP40 class.
Definition: Adafruit_SGP40.cpp:37
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:132
bool selfTest(void)
Request the sensor to perform a self-test, returning the result.
Definition: Adafruit_SGP40.cpp:109
Class that stores state and functions for interacting with SGP40 Gas Sensor.
Definition: Adafruit_SGP40.h:46