1
1
#include < ESP8266WiFi.h>
2
2
#include < EEPROM.h>
3
3
4
- #define D2 4
5
4
#define DC_GAIN (8.5 ) // define the DC gain of amplifier
5
+ #define D3 0
6
+ #define D4 2
7
+ #define D7 13
8
+ #define D8 15
9
+ #define D5 14
10
+ #define D6 12
6
11
7
12
// These two values differ from sensor to sensor. user should derermine this value.
8
13
// #define ZERO_POINT_VOLTAGE (3.09 / DC_GAIN) //define the output of the sensor in volts when the concentration of CO2 is 400PPM
@@ -30,13 +35,26 @@ public:
30
35
31
36
UnitData systemData;
32
37
33
- bool USE_INFRA = true ;
38
+ bool USE_INFRA = false ;
39
+ bool INFRA_WITH_CORRECTION = true ;
34
40
unsigned long LOOP_DELAY = 30000 ;
35
41
42
+ bool USE_UART = true ;
43
+
44
+ byte cmd[9 ] = {0xFF , 0x01 , 0x86 , 0x00 , 0x00 , 0x00 , 0x00 , 0x00 , 0x79 };
45
+ char response[9 ];
46
+
47
+ #include < SoftwareSerial.h>
48
+
49
+ const int RX_PIN = D5;
50
+ const int TX_PIN = D6;
51
+ const int BAUD_RATE = 9600 ;
52
+
53
+ SoftwareSerial sensorUart (RX_PIN, TX_PIN);
54
+
36
55
void setup ()
37
56
{
38
57
Serial.begin (115200 );
39
- pinMode (D2, INPUT_PULLUP);
40
58
41
59
Serial.print (" Chip id " );
42
60
Serial.println (ESP.getChipId ());
@@ -65,6 +83,10 @@ void setup()
65
83
EEPROM.put(0, systemData);
66
84
EEPROM.end();
67
85
//*/
86
+
87
+ if (USE_UART) {
88
+ sensorUart.begin (BAUD_RATE);
89
+ }
68
90
}
69
91
70
92
void loop ()
@@ -78,14 +100,28 @@ void loop()
78
100
float voltsRaw = (volts1 + volts2 + volts3) / 3.0 ;
79
101
float volts = voltsRaw;
80
102
Serial.print (volts);
81
- Serial.print (" V (" );
82
- Serial.print (volts1 );
103
+ Serial.print (" V (C " );
104
+ Serial.print (volts2 );
83
105
Serial.print (" V) " );
84
106
85
107
float ppm = -1 ;
86
- if (USE_INFRA) {
108
+ if (USE_UART) {
109
+ sensorUart.write (cmd, 9 );
110
+ sensorUart.readBytes (response, 9 );
111
+
112
+ if (0xff == response[0 ] && 0x86 == response[1 ]) {
113
+ int responseHigh = (int ) response[2 ];
114
+ int responseLow = (int ) response[3 ];
115
+ ppm = (256 * responseHigh) + responseLow;
116
+ } else {
117
+ ppm = 100 ;
118
+ }
119
+ } else if (USE_INFRA) {
87
120
ppm = volts * 1000 ;
88
- ppm = ppm * (1 + ppm / 1000 );
121
+
122
+ if (INFRA_WITH_CORRECTION) {
123
+ ppm = ppm * (1 + ppm / 1250 );
124
+ }
89
125
} else {
90
126
volts = volts / DC_GAIN;
91
127
Serial.print (volts, 3 );
@@ -104,7 +140,6 @@ void loop()
104
140
Serial.print (" Time point: " );
105
141
Serial.print (millis () / 60000.0 );
106
142
Serial.print (" m " );
107
- // Serial.print(digitalRead(D2));
108
143
Serial.println ();
109
144
110
145
unsigned long now = millis ();
0 commit comments