1010
1111Arduino library for AGS02MA TVOC sensor.
1212
13- This library is experimental, so please use with care.
14- Note the warning about the I2C speed, the device works at only 30 KHz.
13+ This library is still experimental, so please use with care.
14+ Note the warning about the I2C low speed, the device works at max 30 KHz.
15+ Since 0.3.1 this library uses 25 KHz.
1516
1617
17- ## I2C - warning low speed
18+ ## I2C
19+
20+ ### PIN layout from left to right
21+
22+ | Front L->R | Description |
23+ | :----------:| :------------|
24+ | pin 1 | VDD + |
25+ | pin 2 | SDA data |
26+ | pin 3 | GND |
27+ | pin 4 | SCL clock |
28+
29+
30+ ### WARNING - LOW SPEED
1831
1932The sensor uses I2C at very low speed <= 30 KHz.
20- For an Arduino UNO the lowest speed possible is about 30.4KHz (TWBR = 255) which works.
33+ For an Arduino UNO the lowest speed supported is about 30.4KHz (TWBR = 255) which works.
34+ First runs with Arduino UNO indicate 2 failed reads in > 500 Reads, so less than 1%
35+
2136Tests with ESP32 / ESP8266 at 30 KHz look good,
22- tests with lower clock speeds are to be done but expected to work.
23- First runs indicate 2 failed reads in > 500 Reads, so less than 1%
37+ tests with ESP32 at lower clock speeds are to be done but expected to work.
2438
2539The library sets the clock speed to 30 KHz (for non AVR) during operation
26- and resets it to 100 KHz after operation.
40+ and resets it default to 100 KHz after operation.
2741This is done to minimize interference with the communication of other devices.
28- The reset clock speed can be changed with ** setI2CResetSpeed()** e.g. to 200 or 400 KHz.
42+ The reset clock speed can be changed with ** setI2CResetSpeed(speed)** e.g. to 200 or 400 KHz.
43+
44+
45+ #### 0.3.1 fix.
46+
47+ Version 0.3.1 sets the ** I2C prescaler TWSR** register of the Arduino UNO to 4 so the lowest
48+ speed possible is reduced to about 8 KHz.
49+ A test run 4 hours with 6000++ reads on an UNO at 25 KHz gave 0 errors.
50+ So the communication speed will be set to 25 KHz, also for other boards, for stability.
51+ After communication the clock (+ prescaler) is reset again as before.
2952
3053
3154## Version 118 problems
@@ -62,7 +85,6 @@ Note: the version 0.2.0 determines the version in the calibration function so
6285it won't calibrate any non 117 version.
6386
6487
65-
6688### Please report your experiences.
6789
6890If you have a AGS20MA device, version 117 or 118 or other,
@@ -111,7 +133,7 @@ Serial.println(dd, HEX); // prints YYYYMMDD e.g. 20210203
111133
112134### I2C clock speed
113135
114- The library sets the clock speed to 30 KHz during operation
136+ The library sets the clock speed to 25 KHz during operation
115137and resets it to 100 KHz after operation.
116138This is done to minimize interference with the communication of other devices.
117139The following function can change the I2C reset speed to e.g. 200 or 400 KHz.
@@ -148,27 +170,27 @@ Simplified formula for 1 atm @ 25°C:
148170
149171Some known gasses
150172
151- | gas | Common name | ratio | molecular weight M |
152- | :-----| :--------------| :--------------------| :------------------:|
153- | SO2 | | 1 ppb = 2.62 μg/m3 | 64 |
154- | NO2 | | 1 ppb = 1.88 μg/m3 | 46 |
155- | NO | | 1 ppb = 1.25 μg/m3 | 30 |
156- | O3 | | 1 ppb = 2.00 μg/m3 | 48 |
157- | CO | | 1 ppb = 1.145 μg/m3 | 28 |
158- | C6H6 | Benzene | 1 ppb = 3.19 μg/m3 | 78 |
173+ | gas | Common name | ratio ppb-μg/m3 | molecular weight M |
174+ | :-----| :------------------ | :--------------------| :------------------:|
175+ | SO2 | Sulphur dioxide | 1 ppb = 2.62 μg/m3 | 64 gr/mol |
176+ | NO2 | Nitrogen dioxide | 1 ppb = 1.88 μg/m3 | 46 gr/mol |
177+ | NO | Nitrogen monoxide | 1 ppb = 1.25 μg/m3 | 30 gr/mol |
178+ | O3 | Ozone | 1 ppb = 2.00 μg/m3 | 48 gr/mol |
179+ | CO | Carbon Monoxide | 1 ppb = 1.145 μg/m3 | 28 gr/mol |
180+ | C6H6 | Benzene | 1 ppb = 3.19 μg/m3 | 78 gr/mol |
159181
160182
161- ### Reading
183+ ### Read the sensor
162184
163185WARNING: The datasheet advises to take 3 seconds between reads.
164- You might be able to squeeze time down to 1.5 second at your own risk.
186+ Tests gave stable results at 1.5 second intervals.
187+ Use this faster rate at your own risk.
165188
166189- ** uint32_t readPPB()** reads PPB (parts per billion) from device.
167190Typical value should be between 1 .. 999999.
168191Returns ** lastPPB()** value if failed so one does not get sudden jumps in graphs.
169192Check ** lastStatus()** and ** lastError()** to get more info about success.
170193Time needed is ~ 35 milliseconds.
171-
172194- ** uint32_t readUGM3()** reads UGM3 (microgram per cubic meter) current value from device.
173195Typical values depend on the molecular weight of the TVOC.
174196Returns ** lastUGM3()** if failed so one does not get sudden jumps in graphs.
@@ -179,6 +201,8 @@ Typical value should be between 0.01 .. 999.99
179201- ** float readUGF3()** returns microgram per cubic feet.
180202
181203
204+ ### Error Codes
205+
182206| ERROR_CODES | value |
183207| :---------------------------| :-----:|
184208| AGS02MA_OK | 0 |
@@ -195,16 +219,20 @@ Typical value should be between 0.01 .. 999.99
195219- ** uint32_t lastUGM3()** returns last read UGM3 (microgram per cubic meter) value (cached).
196220
197221
198- ### Other
222+ ### Calibration
199223
200224- ** bool zeroCalibration()** to be called after at least 5 minutes in fresh air.
201225See example sketch.
202226- ** bool manualZeroCalibration(uint16_t value = 0)** Set the zero calibration value manually.
203227To be called after at least 5 minutes in fresh air.
204- For v117: 0-65535 = automatic calibration.
205- For v118: 0 = automatic calibration, 1-65535 manual calibration.
228+ - For v117: 0-65535 = automatic calibration.
229+ - For v118: 0 = automatic calibration, 1-65535 manual calibration.
206230- ** bool getZeroCalibrationData(ZeroCalibrationData &data)** fills a data struct with the current zero calibration status and value.
207231Returns true on success.
232+
233+
234+ ### Other
235+
208236- ** bool readRegister(uint8_t address, RegisterData ®)** fills a data struct with the chip's register data at that address.
209237Primarily intended for troubleshooting and analysis of the sensor. Not recommended to build applications on top of this method's raw data.
210238Returns true when the struct is filled, false when the data could not be read.
@@ -217,11 +245,11 @@ Read datasheet or table below for details. A new read is needed to update this.
217245
218246#### Status bits.
219247
220- | bit | description | notes |
221- | :----:| :----------------------------------| : ------|
222- | 7-4 | internal use |
223- | 3-1 | 000 = PPB 001 = uG/M3 |
224- | 0 | RDY bit 0 = ready 1 = not ready | 1 == busy
248+ | bit | description | notes |
249+ | :----- :| :------------------------------------ | :-- ------|
250+ | 7-4 | internal use |
251+ | 3-1 | 000 = PPB 001 = uG/M3 |
252+ | 0 | RDY bit 0 = ready 1 = not ready | 1 == busy
225253
226254
227255## Future
@@ -231,4 +259,8 @@ Read datasheet or table below for details. A new read is needed to update this.
231259- add indicative table for PPB health zone
232260- check the mode bits of the status byte with internal \_ mode.
233261- elaborate error handling.
262+ - create an async interface for ** readPPB()** if possible
263+ - put the I2C speed code in 2 inline functions
264+ - less repeating conditional code places
265+ - setLowSpeed() + setNormalSpeed()
234266
0 commit comments