-
Notifications
You must be signed in to change notification settings - Fork 0
/
SGP30.h
74 lines (60 loc) · 2.04 KB
/
SGP30.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
/*
Project : LaLiMat project (https://www.youtube.com/playlist?list=PLJBKmE2nNweRXOebZjydkMEiq2pHtBMOS in Chinese)
file : SGP30.h
Author : ykchau
youtube : youtube.com/ykchau888
Licenese : GPL-3.0
Please let me know if you use it commercial project.
*/
#ifndef SGP30_H_
#define SGP30_H_
#include <Arduino.h>
#include <Wire.h>
#define SGP30_I2C_ADDRESS 0x58
// Feature Set
#define SGP30_IAQ_INIT 0x03
#define SGP30_MEASURE_IAQ 0x08
#define SGP30_GET_IAQ_BASELINE 0x15
#define SGP30_SET_IAQ_BASELINE 0x1E
#define SGP30_SET_ABSOLUTE_HUMIDITY 0x61
#define SGP30_MEASURE_TEST 0x32 // This use for product line testing, didn't implement
#define SGP30_GET_FEATURE_SET 0x2F
#define SGP30_MEASURE_RAW 0x50
#define SGP30_GET_TVOC_INCEPTIVE_BASELINE 0xB3
#define SGP30_SET_TVOC_BASELINE 0x77
#define SGP30_SOFT_RESET 0x06
// Checksum
#define SGP30_CRC8_INIT 0xFF
#define SGP30_CRC8_POLYNOMIAL 0x31
typedef struct GAS {
int TVOC = 0; // Calculated value
int CO2EQ = 0; // Calculated value
int Ethanol = 0;
int H2 = 0;
};
class SGP30 {
private:
void I2CWrite(byte data[], byte dataSize);
byte I2CRead(byte data[], byte byteToRead);
public:
GAS gas;
unsigned int SerialID[3];
unsigned int baseline_CO2eq = 0;
unsigned int baseline_TVOC = 0;
unsigned int baseline_TVOC_Inceptive = 0;
byte initCheckCounter = 0;
void init();
void iaq_init();
void measure();
void getBaseline();
void setBaseline(byte data[]);
void setAbsoluteHumidity(byte RH, byte Temp);
void getFeatureSet();
void measureRaw();
void getTVOCInceptiveBaseline();
void setTVOCBaseline(byte data[]);
void softReset();
void getSerialID();
byte checksum(byte data[], byte dataSize);
};
#endif // SGP30_H_