Skip to content

Commit 619ff48

Browse files
authored
refactor API, begin() (#25)
- refactor API, begin() - update readme.md
1 parent 04e0a0f commit 619ff48

File tree

23 files changed

+387
-132
lines changed

23 files changed

+387
-132
lines changed

AGS02MA.cpp

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
// FILE: AGS02MA.cpp
33
// AUTHOR: Rob Tillaart, Viktor Balint, Beanow
44
// DATE: 2021-08-12
5-
// VERSION: 0.3.4
5+
// VERSION: 0.4.0
66
// PURPOSE: Arduino library for AGS02MA TVOC sensor
77
// URL: https://github.com/RobTillaart/AGS02MA
88

@@ -26,25 +26,9 @@ AGS02MA::AGS02MA(const uint8_t deviceAddress, TwoWire *wire)
2626
}
2727

2828

29-
#if defined (ESP8266) || defined(ESP32)
30-
bool AGS02MA::begin(uint8_t dataPin, uint8_t clockPin)
31-
{
32-
_startTime = millis(); // PREHEAT
33-
if ((dataPin < 255) && (clockPin < 255))
34-
{
35-
_wire->begin(dataPin, clockPin);
36-
} else {
37-
_wire->begin();
38-
}
39-
return isConnected();
40-
}
41-
#endif
42-
43-
4429
bool AGS02MA::begin()
4530
{
4631
_startTime = millis(); // PREHEAT TIMING
47-
_wire->begin();
4832
return isConnected();
4933
}
5034

AGS02MA.h

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
// FILE: AGS02MA.h
44
// AUTHOR: Rob Tillaart, Viktor Balint, Beanow
55
// DATE: 2021-08-12
6-
// VERSION: 0.3.4
6+
// VERSION: 0.4.0
77
// PURPOSE: Arduino library for AGS02MA TVOC sensor
88
// URL: https://github.com/RobTillaart/AGS02MA
99
//
@@ -13,7 +13,7 @@
1313
#include "Wire.h"
1414

1515

16-
#define AGS02MA_LIB_VERSION (F("0.3.4"))
16+
#define AGS02MA_LIB_VERSION (F("0.4.0"))
1717

1818
#define AGS02MA_OK 0
1919
#define AGS02MA_ERROR -10
@@ -51,9 +51,6 @@ class AGS02MA
5151
// address 26 = 0x1A
5252
explicit AGS02MA(const uint8_t deviceAddress = 26, TwoWire *wire = &Wire);
5353

54-
#if defined (ESP8266) || defined(ESP32)
55-
bool begin(uint8_t sda, uint8_t scl);
56-
#endif
5754
bool begin();
5855
bool isConnected();
5956
void reset();
@@ -102,7 +99,7 @@ class AGS02MA
10299

103100
float lastPPM() { return _lastPPB * 0.001; };
104101
uint32_t lastPPB() { return _lastPPB; }; // fetch last PPB measurement
105-
uint32_t lastUGM3() { return _lastUGM3; }; // fetch last UGM3 measurement
102+
uint32_t lastUGM3() { return _lastUGM3; }; // fetch last UGM3 measurement
106103

107104

108105
// STATUS

CHANGELOG.md

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,17 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/)
66
and this project adheres to [Semantic Versioning](http://semver.org/).
77

88

9+
## [0.4.0] - 2023-12-06
10+
- refactor API, begin()
11+
- update readme.md
12+
13+
----
14+
915
## [0.3.4] - 2023-09-25
1016
- add Wire1 support for ESP32
1117
- update readme.md
1218
- minor edits
1319

14-
1520
## [0.3.3] - 2023-01-21
1621
- update GitHub actions
1722
- update license 2023

README.md

Lines changed: 17 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,23 @@
1313

1414
Arduino library for AGS02MA TVOC sensor.
1515

16+
17+
#### Description
18+
1619
This library is still experimental, so please use with care.
1720
Note the warning about the I2C low speed, the device works at max 30 KHz.
1821
Since 0.3.1 this library uses 25 KHz.
1922

2023

24+
#### 0.4.0 Breaking change
25+
26+
Version 0.4.0 introduced a breaking change.
27+
You cannot set the pins in **begin()** any more.
28+
This reduces the dependency of processor dependent Wire implementations.
29+
The user has to call **Wire.begin()** and can optionally set the Wire pins
30+
before calling **begin()**.
31+
32+
2133
## I2C
2234

2335
### PIN layout from left to right
@@ -101,12 +113,11 @@ with the sensor and this (or other) library.
101113
#include "AGS02MA.h"
102114
```
103115

104-
105116
#### Constructor
106117

107-
- **AGS02MA(uint8_t deviceAddress = 26, TwoWire \*wire = &Wire)** constructor, with default address and default I2C interface.
108-
- **bool begin(uint8_t sda, uint8_t scl)** begin for ESP32 and ESP8266.
109-
- **bool begin()** initializer for Arduino UNO a.o.
118+
- **AGS02MA(uint8_t deviceAddress = 26, TwoWire \*wire = &Wire)** constructor,
119+
with default address and default I2C interface.
120+
- **bool begin()** initialize the library.
110121
- **bool isConnected()** returns true if device address can be seen on I2C.
111122
- **void reset()** reset internal variables.
112123

@@ -157,6 +168,7 @@ The default mode at startup of the sensor is PPB = parts per billion.
157168
- **bool setUGM3Mode()** sets device in micro gram per cubic meter mode. Returns true on success.
158169
- **uint8_t getMode()** returns mode set. 0 = PPB, 1 = UGm3, 255 = not set.
159170

171+
160172
#### Air quality classification
161173

162174
| ppm | Class |
@@ -171,6 +183,7 @@ The default mode at startup of the sensor is PPB = parts per billion.
171183

172184
[Source](https://learn.kaiterra.com/en/resources/understanding-tvoc-volatile-organic-compounds)
173185

186+
174187
#### PPB versus UGM3
175188

176189
There is no 1 to 1 relation between the PPB and the uG/m3 readings as this relation depends

examples/AGS02MA_PPB/AGS02MA_PPB.ino

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
//
22
// FILE: AGS02MA_PPB.ino
33
// AUTHOR: Rob Tillaart
4-
// VERSION: 0.1.0
54
// PURPOSE: test application
6-
// DATE: 2021-08-12
75
// URL: https://github.com/RobTillaart/AGS02MA
8-
//
96

107

118
#include "AGS02MA.h"
@@ -16,24 +13,27 @@ AGS02MA AGS(26);
1613

1714
void setup()
1815
{
16+
// ESP devices typically miss the first serial log lines after flashing.
17+
// Delay somewhat to include all output.
18+
delay(1000);
19+
1920
Serial.begin(115200);
2021
Serial.println(__FILE__);
21-
22-
Wire.begin();
23-
2422
Serial.print("AGS02MA_LIB_VERSION: ");
2523
Serial.println(AGS02MA_LIB_VERSION);
2624
Serial.println();
2725

26+
Wire.begin();
27+
2828
bool b = AGS.begin();
2929
Serial.print("BEGIN:\t");
3030
Serial.println(b);
3131

3232
Serial.print("VERSION:\t");
3333
Serial.println(AGS.getSensorVersion());
3434

35-
// pre-heating improves measurement quality
36-
// can be skipped
35+
// pre-heating improves measurement quality
36+
// can be skipped
3737
Serial.println("\nWarming up (120 seconds = 24 dots)");
3838
while (AGS.isHeated() == false)
3939
{
@@ -70,4 +70,4 @@ void loop()
7070
}
7171

7272

73-
// -- END OF FILE --
73+
// -- END OF FILE --

examples/AGS02MA_PPB_TIMING/AGS02MA_PPB_TIMING.ino

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,27 @@ AGS02MA AGS(26);
1515

1616
void setup()
1717
{
18+
// ESP devices typically miss the first serial log lines after flashing.
19+
// Delay somewhat to include all output.
20+
delay(1000);
21+
1822
Serial.begin(115200);
1923
Serial.println(__FILE__);
20-
21-
Wire.begin();
22-
2324
Serial.print("AGS02MA_LIB_VERSION: ");
2425
Serial.println(AGS02MA_LIB_VERSION);
2526
Serial.println();
2627

28+
Wire.begin();
29+
2730
bool b = AGS.begin();
2831
Serial.print("BEGIN:\t");
2932
Serial.println(b);
3033

3134
Serial.print("VERS:\t");
3235
Serial.println(AGS.getSensorVersion());
3336

34-
// pre-heating improves measurement quality
35-
// can be skipped
37+
// pre-heating improves measurement quality
38+
// can be skipped
3639
Serial.println("\nWarming up (120 seconds = 24 dots)");
3740
while (AGS.isHeated() == false)
3841
{
@@ -69,5 +72,5 @@ void loop()
6972
}
7073

7174

72-
// -- END OF FILE --
75+
// -- END OF FILE --
7376

examples/AGS02MA_PPM/AGS02MA_PPM.ino

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -15,24 +15,27 @@ AGS02MA AGS(26);
1515

1616
void setup()
1717
{
18+
// ESP devices typically miss the first serial log lines after flashing.
19+
// Delay somewhat to include all output.
20+
delay(1000);
21+
1822
Serial.begin(115200);
1923
Serial.println(__FILE__);
20-
21-
Wire.begin();
22-
2324
Serial.print("AGS02MA_LIB_VERSION: ");
2425
Serial.println(AGS02MA_LIB_VERSION);
2526
Serial.println();
2627

28+
Wire.begin();
29+
2730
bool b = AGS.begin();
2831
Serial.print("BEGIN:\t");
2932
Serial.println(b);
3033

3134
Serial.print("VERSION:\t");
3235
Serial.println(AGS.getSensorVersion());
3336

34-
// pre-heating improves measurement quality
35-
// can be skipped
37+
// pre-heating improves measurement quality
38+
// can be skipped
3639
Serial.println("\nWarming up (120 seconds = 24 dots)");
3740
while (AGS.isHeated() == false)
3841
{
@@ -65,5 +68,5 @@ void loop()
6568
}
6669

6770

68-
// -- END OF FILE --
71+
// -- END OF FILE --
6972

examples/AGS02MA_UGM3/AGS02MA_UGM3.ino

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,8 @@
11
//
22
// FILE: AGS02MA_UGM3.ino
33
// AUTHOR: Rob Tillaart
4-
// VERSION: 0.1.0
54
// PURPOSE: test application
6-
// DATE: 2021-08-12
75
// URL: https://github.com/RobTillaart/AGS02MA
8-
//
96

107

118
#include "AGS02MA.h"
@@ -16,21 +13,24 @@ AGS02MA AGS(26);
1613

1714
void setup()
1815
{
16+
// ESP devices typically miss the first serial log lines after flashing.
17+
// Delay somewhat to include all output.
18+
delay(1000);
19+
1920
Serial.begin(115200);
2021
Serial.println(__FILE__);
21-
22-
Wire.begin();
23-
2422
Serial.print("AGS02MA_LIB_VERSION: ");
2523
Serial.println(AGS02MA_LIB_VERSION);
2624
Serial.println();
2725

26+
Wire.begin();
27+
2828
bool b = AGS.begin();
2929
Serial.print("BEGIN:\t");
3030
Serial.println(b);
3131

32-
// pre-heating improves measurement quality
33-
// can be skipped
32+
// pre-heating improves measurement quality
33+
// can be skipped
3434
Serial.println("\nWarming up (120 seconds = 24 dots)");
3535
while (AGS.isHeated() == false)
3636
{
@@ -67,4 +67,4 @@ void loop()
6767
}
6868

6969

70-
// -- END OF FILE --
70+
// -- END OF FILE --

examples/AGS02MA_calibrate/AGS02MA_calibrate.ino

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,13 @@
11
//
22
// FILE: AGS02MA_calibrate.ino
33
// AUTHOR: Rob Tillaart, Beanow
4-
// VERSION: 0.2.0
54
// PURPOSE: test application
6-
// DATE: 2021-08-12
75
// URL: https://github.com/RobTillaart/AGS02MA
8-
//
6+
97

108
#include "AGS02MA.h"
119

12-
// You can decrease/disable warmup when you're certain the chip already warmed up.
10+
// You can decrease/disable warmup when you're certain the chip already warmed up.
1311
#define WARMUP_MINUTES 6
1412
#define READ_INTERVAL 3000
1513

@@ -22,13 +20,12 @@ AGS02MA AGS(26);
2220

2321
void setup()
2422
{
25-
// ESP devices typically mis the first serial log lines after flashing.
26-
// Delay somewhat to include all output.
23+
// ESP devices typically miss the first serial log lines after flashing.
24+
// Delay somewhat to include all output.
2725
delay(1000);
2826

2927
Serial.begin(115200);
3028
Serial.println(__FILE__);
31-
3229
Serial.print("AGS02MA_LIB_VERSION: ");
3330
Serial.println(AGS02MA_LIB_VERSION);
3431
Serial.println();
@@ -49,7 +46,7 @@ void setup()
4946
Serial.println(version);
5047
int err = AGS.lastError();
5148

52-
// Reading version correctly matters, as we display additional comments based on it.
49+
// Reading version correctly matters, as we display additional comments based on it.
5350
if(err != AGS02MA_OK)
5451
{
5552
Serial.print("Error reading version:\t");
@@ -101,7 +98,7 @@ void setup()
10198

10299
delay(1000);
103100

104-
// returns 1 if successful written
101+
// returns 1 if successful written
105102
b = AGS.zeroCalibration();
106103
Serial.println();
107104
Serial.print("CALIB:\t");
@@ -123,8 +120,8 @@ void setup()
123120

124121
Serial.println();
125122
Serial.println("Showing what PPB values look like post calibration.");
126-
// A 125 status is typically shown on v118's after they've been powered off.
127-
// Either having this version at all, or seeing this status, we'll display a notice.
123+
// A 125 status is typically shown on v118's after they've been powered off.
124+
// Either having this version at all, or seeing this status, we'll display a notice.
128125
if (version == 118 || initialValue.status == 125)
129126
{
130127
Serial.println("NOTICE: v118 sensors are known to give different results after powering off!");
@@ -162,4 +159,5 @@ void printPPB()
162159
Serial.println();
163160
}
164161

165-
// -- END OF FILE --
162+
163+
// -- END OF FILE --

0 commit comments

Comments
 (0)