1+ /* !
2+ * @file readGasConcentration.ino
3+ * @brief Obtain gas concentration corresponding to the current environment, output as concentration value
4+ * @n Experimental mode: connect sensor communication pin to the main controller and burn
5+ * @n Communication mode select, DIP switch SEL: 0: I2C, 1: UART
6+ * @n Group serial number Address in the group
7+ * @n A0 A1 DIP level 00 01 10 11
8+ * @n 1 0x60 0x61 0x62 0x63
9+ * @n 2 0x64 0x65 0x66 0x67
10+ * @n 3 0x68 0x69 0x6A 0x6B
11+ * @n 4 0x6C 0x6D 0x6E 0x6F
12+ * @n 5 0x70 0x71 0x72 0x73
13+ * @n 6 (Default address group) 0x74 0x75 0x76 0x77 (Default address)
14+ * @n 7 0x78 0x79 0x7A 0x7B
15+ * @n 8 0x7C 0x7D 0x7E 0x7F
16+ * @n i2c address select, default to 0x77, A1 and A0 are grouped into 4 I2C addresses.
17+ * @n | A0 | A1 |
18+ * @n | 0 | 0 | 0x74
19+ * @n | 0 | 1 | 0x75
20+ * @n | 1 | 0 | 0x76
21+ * @n | 1 | 1 | 0x77 default i2c address
22+ * @n Experimental phenomenon: view the gas concentration corresponding to the current environment through serial port printing
23+ * @copyright Copyright (c) 2010 DFRobot Co.Ltd (http://www.dfrobot.com)
24+ * @license The MIT License (MIT)
25+ * @author PengKaixing(kaixing.peng@dfrobot.com)
26+ * @version V1.0
27+ * @date 2021-03-28
28+ * @url https://github.com/DFRobot/DFRobot_MultiGasSensor
29+ */
30+ #include " DFRobot_MultiGasSensor.h"
31+ #include < Arduino.h>
32+
33+ // Turn on by default, using I2C communication at the time, switch to serial port communication after turning off
34+ // #define I2C_COMMUNICATION
35+
36+ // #ifdef I2C_COMMUNICATION
37+ // #define I2C_ADDRESS 0x77
38+ DFRobot_GAS_I2C nh3 (&Wire,0x7A );
39+ DFRobot_GAS_I2C co (&Wire,0x78 );
40+ DFRobot_GAS_I2C no2 (&Wire,0x7B );
41+ DFRobot_GAS_I2C o3 (&Wire,0x79 );
42+
43+ void setup () {
44+ // Serial port init for viewing printing output
45+ Serial.begin (115200 );
46+
47+ // Change i2c address group
48+ while (no2.changeI2cAddrGroup (7 )==0 )
49+ {
50+ Serial.println (" IIC addr change fail!" );
51+ delay (1000 );
52+ }
53+ Serial.println (" IIC addr change success!" );
54+
55+ // Sensor init, used to init serial port or I2C, depending on the communication mode currently used
56+ while (!nh3.begin ())
57+ {
58+ Serial.println (" No Devices NH3 !" );
59+ delay (1000 );
60+ }
61+ // Mode of obtaining data: the main controller needs to request the sensor for data
62+ nh3.changeAcquireMode (nh3.PASSIVITY );
63+ delay (1000 );
64+
65+ nh3.setTempCompensation (nh3.ON );
66+
67+ Serial.println (" The device nh3 0x7A is connected successfully!" );
68+
69+ while (!co.begin ())
70+ {
71+ Serial.println (" No Devices CO !" );
72+ delay (1000 );
73+ }
74+
75+ co.changeAcquireMode (co.PASSIVITY );
76+ delay (1000 );
77+
78+ co.setTempCompensation (co.ON );
79+
80+ Serial.println (" The device CO 0x78 is connected successfully!" );
81+
82+ while (!no2.begin ())
83+ {
84+ Serial.println (" No Devices NO2 !" );
85+ delay (1000 );
86+ }
87+
88+ no2.changeAcquireMode (no2.PASSIVITY );
89+ delay (1000 );
90+
91+ no2.setTempCompensation (no2.ON );
92+
93+ Serial.println (" The device NO2 0x7B is connected successfully!" );
94+
95+ while (!o3.begin ())
96+ {
97+ Serial.println (" No Devices O3 !" );
98+ delay (1000 );
99+ }
100+
101+ o3.changeAcquireMode (o3.PASSIVITY );
102+ delay (1000 );
103+
104+ o3.setTempCompensation (o3.ON );
105+
106+ Serial.println (" The device O3 0x79 is connected successfully!" );
107+ }
108+
109+ void loop () {
110+ String gastypeNH3 = nh3.queryGasType ();
111+ /* *
112+ *Fill in the parameter readGasConcentration() with the type of gas to be obtained and print
113+ *The current gas concentration
114+ *Print with 1s delay each time
115+ */
116+ Serial.print (" Ambient " );
117+ Serial.print (gastypeNH3);
118+ Serial.print (" concentration is: " );
119+ Serial.print (nh3.readGasConcentrationPPM ());
120+ if (gastypeNH3 == " O2" )
121+ Serial.println (" %vol" );
122+ else
123+ Serial.println (" PPM" );
124+ Serial.println ();
125+ delay (1000 );
126+
127+ String gastypeCO = co.queryGasType ();
128+ /* *
129+ *Fill in the parameter readGasConcentration() with the type of gas to be obtained and print
130+ *The current gas concentration
131+ *Print with 1s delay each time
132+ */
133+ Serial.print (" Ambient " );
134+ Serial.print (gastypeCO);
135+ Serial.print (" concentration is: " );
136+ Serial.print (co.readGasConcentrationPPM ());
137+ if (gastypeCO == " O2" )
138+ Serial.println (" %vol" );
139+ else
140+ Serial.println (" PPM" );
141+ Serial.println ();
142+ delay (1000 );
143+
144+ String gastypeNO2 = no2.queryGasType ();
145+ /* *
146+ *Fill in the parameter readGasConcentration() with the type of gas to be obtained and print
147+ *The current gas concentration
148+ *Print with 1s delay each time
149+ */
150+ Serial.print (" Ambient " );
151+ Serial.print (gastypeNO2);
152+ Serial.print (" concentration is: " );
153+ Serial.print (no2.readGasConcentrationPPM ());
154+ if (gastypeNO2 == " O2" )
155+ Serial.println (" %vol" );
156+ else
157+ Serial.println (" PPM" );
158+ Serial.println ();
159+ delay (1000 );
160+
161+ String gastypeO3 = o3.queryGasType ();
162+ /* *
163+ *Fill in the parameter readGasConcentration() with the type of gas to be obtained and print
164+ *The current gas concentration
165+ *Print with 1s delay each time
166+ */
167+ Serial.print (" Ambient " );
168+ Serial.print (gastypeO3);
169+ Serial.print (" concentration is: " );
170+ Serial.print (o3.readGasConcentrationPPM ());
171+ if (gastypeO3 == " O2" )
172+ Serial.println (" %vol" );
173+ else
174+ Serial.println (" PPM" );
175+ Serial.println ();
176+ delay (1000 );
177+ }
178+
0 commit comments