mirror of
https://github.com/RobTillaart/Arduino.git
synced 2024-09-20 00:55:58 -04:00
0.3.3 AGS02MA
This commit is contained in:
parent
2b5f49b2e3
commit
45f1941984
@ -6,7 +6,7 @@ jobs:
|
||||
lint:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
- uses: arduino/arduino-lint-action@v1
|
||||
with:
|
||||
library-manager: update
|
||||
|
@ -8,7 +8,7 @@ jobs:
|
||||
runs-on: ubuntu-latest
|
||||
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
- uses: ruby/setup-ruby@v1
|
||||
with:
|
||||
ruby-version: 2.6
|
||||
|
@ -10,7 +10,7 @@ jobs:
|
||||
test:
|
||||
runs-on: ubuntu-latest
|
||||
steps:
|
||||
- uses: actions/checkout@v2
|
||||
- uses: actions/checkout@v3
|
||||
- name: json-syntax-check
|
||||
uses: limitusus/json-syntax-check@v1
|
||||
with:
|
||||
|
@ -2,8 +2,8 @@
|
||||
// FILE: AGS02MA.cpp
|
||||
// AUTHOR: Rob Tillaart, Viktor Balint, Beanow
|
||||
// DATE: 2021-08-12
|
||||
// VERSION: 0.3.2
|
||||
// PURPOSE: Arduino library for AGS02MA TVOC
|
||||
// VERSION: 0.3.3
|
||||
// PURPOSE: Arduino library for AGS02MA TVOC sensor
|
||||
// URL: https://github.com/RobTillaart/AGS02MA
|
||||
|
||||
|
||||
@ -59,8 +59,10 @@ bool AGS02MA::isConnected()
|
||||
#else
|
||||
_wire->setClock(AGS02MA_I2C_CLOCK);
|
||||
#endif
|
||||
|
||||
_wire->beginTransmission(_address);
|
||||
bool rv = ( _wire->endTransmission(true) == 0);
|
||||
|
||||
#if defined (__AVR__)
|
||||
TWSR = 0x00;
|
||||
#endif
|
||||
@ -266,6 +268,7 @@ bool AGS02MA::readRegister(uint8_t address, AGS02MA::RegisterData ®) {
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
/////////////////////////////////////////////////////////
|
||||
//
|
||||
// PRIVATE
|
||||
@ -305,6 +308,7 @@ bool AGS02MA::_readRegister(uint8_t reg)
|
||||
#else
|
||||
_wire->setClock(AGS02MA_I2C_CLOCK);
|
||||
#endif
|
||||
|
||||
_wire->beginTransmission(_address);
|
||||
_wire->write(reg);
|
||||
_error = _wire->endTransmission(true);
|
||||
@ -359,16 +363,19 @@ bool AGS02MA::_writeRegister(uint8_t reg)
|
||||
return (_error == 0);
|
||||
}
|
||||
|
||||
|
||||
uint16_t AGS02MA::_getDataMSB()
|
||||
{
|
||||
return (_buffer[0] << 8) + _buffer[1];
|
||||
}
|
||||
|
||||
|
||||
uint16_t AGS02MA::_getDataLSB()
|
||||
{
|
||||
return (_buffer[2] << 8) + _buffer[3];
|
||||
}
|
||||
|
||||
|
||||
uint8_t AGS02MA::_CRC8(uint8_t * buf, uint8_t size)
|
||||
{
|
||||
uint8_t crc = 0xFF; // start value
|
||||
@ -392,3 +399,4 @@ uint8_t AGS02MA::_bin2bcd (uint8_t value)
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
@ -3,8 +3,8 @@
|
||||
// FILE: AGS02MA.h
|
||||
// AUTHOR: Rob Tillaart, Viktor Balint, Beanow
|
||||
// DATE: 2021-08-12
|
||||
// VERSION: 0.3.2
|
||||
// PURPOSE: Arduino library for AGS02MA TVOC
|
||||
// VERSION: 0.3.3
|
||||
// PURPOSE: Arduino library for AGS02MA TVOC sensor
|
||||
// URL: https://github.com/RobTillaart/AGS02MA
|
||||
//
|
||||
|
||||
@ -13,7 +13,7 @@
|
||||
#include "Wire.h"
|
||||
|
||||
|
||||
#define AGS02MA_LIB_VERSION (F("0.3.2"))
|
||||
#define AGS02MA_LIB_VERSION (F("0.3.3"))
|
||||
|
||||
#define AGS02MA_OK 0
|
||||
#define AGS02MA_ERROR -10
|
||||
@ -143,3 +143,4 @@ private:
|
||||
|
||||
|
||||
// -- END OF FILE --
|
||||
|
||||
|
34
libraries/AGS02MA/CHANGELOG.md
Normal file
34
libraries/AGS02MA/CHANGELOG.md
Normal file
@ -0,0 +1,34 @@
|
||||
# Change Log AGS02MA
|
||||
|
||||
All notable changes to this project will be documented in this file.
|
||||
|
||||
The format is based on [Keep a Changelog](http://keepachangelog.com/)
|
||||
and this project adheres to [Semantic Versioning](http://semver.org/).
|
||||
|
||||
|
||||
## [0.3.3] - 2023-01-21
|
||||
- update GitHub actions
|
||||
- update license 2023
|
||||
- update keywords
|
||||
- minor edit readme.md
|
||||
- minor edit code
|
||||
- add CHANGELOG.md (for real)
|
||||
|
||||
|
||||
## [0.3.2] - 2022-10-26
|
||||
- add CHANGELOG.md
|
||||
- add RP2040 in build
|
||||
|
||||
----
|
||||
|
||||
## no info
|
||||
|
||||
- 0.3.1
|
||||
- 0.3.0
|
||||
- 0.2.0
|
||||
- 0.1.4
|
||||
- 0.1.3
|
||||
- 0.1.2
|
||||
- 0.1.1
|
||||
- 0.1.0
|
||||
|
@ -1,6 +1,6 @@
|
||||
MIT License
|
||||
|
||||
Copyright (c) 2021-2022 Rob Tillaart
|
||||
Copyright (c) 2021-2023 Rob Tillaart
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||
of this software and associated documentation files (the "Software"), to deal
|
||||
|
@ -20,14 +20,14 @@ Since 0.3.1 this library uses 25 KHz.
|
||||
### PIN layout from left to right
|
||||
|
||||
| Front L->R | Description |
|
||||
|:----------:|:------------|
|
||||
|:------------:|:--------------|
|
||||
| pin 1 | VDD + |
|
||||
| pin 2 | SDA data |
|
||||
| pin 3 | GND |
|
||||
| pin 4 | SCL clock |
|
||||
|
||||
|
||||
### WARNING - LOW SPEED
|
||||
#### WARNING - LOW SPEED
|
||||
|
||||
The sensor uses I2C at very low speed <= 30 KHz.
|
||||
For an Arduino UNO the lowest speed supported is about 30.4KHz (TWBR = 255) which works.
|
||||
@ -58,7 +58,7 @@ My devices all report version 117 and this version is used to develop / test thi
|
||||
There are devices reported with version 118 which behave differently.
|
||||
|
||||
|
||||
### ugM3 not supported
|
||||
#### ugM3 not supported
|
||||
|
||||
See - https://github.com/RobTillaart/AGS02MA/issues/11
|
||||
|
||||
@ -69,7 +69,7 @@ If you encounter similar problems with setting the mode (any version), please le
|
||||
That will help indicating if this is a "structural change" or incident.
|
||||
|
||||
|
||||
### Calibrate problem!
|
||||
#### Calibrate problem!
|
||||
|
||||
See - https://github.com/RobTillaart/AGS02MA/issues/13
|
||||
|
||||
@ -85,7 +85,7 @@ Note: the version 0.2.0 determines the version in the calibration function so
|
||||
it won't calibrate any non 117 version.
|
||||
|
||||
|
||||
### Please report your experiences.
|
||||
#### Please report your experiences.
|
||||
|
||||
If you have a AGS20MA device, version 117 or 118 or other,
|
||||
please let me know your experiences
|
||||
@ -95,7 +95,7 @@ with the sensor and this (or other) library.
|
||||
## Interface
|
||||
|
||||
|
||||
### Constructor
|
||||
#### Constructor
|
||||
|
||||
- **AGS02MA(uint8_t deviceAddress = 26, TwoWire \*wire = &Wire)** constructor, with default address and default I2C interface.
|
||||
- **bool begin(uint8_t sda, uint8_t scl)** begin for ESP32 and ESP8266.
|
||||
@ -104,7 +104,7 @@ with the sensor and this (or other) library.
|
||||
- **void reset()** reset internal variables.
|
||||
|
||||
|
||||
### Timing
|
||||
#### Timing
|
||||
|
||||
- **bool isHeated()** returns true if 2 minutes have passed after startup (call of **begin()** ).
|
||||
Otherwise the device is not optimal ready.
|
||||
@ -115,7 +115,7 @@ This function allows to implement sort of asynchronous wait.
|
||||
One must keep reads at least 1.5 seconds but preferred 3 seconds apart according to the datasheet.
|
||||
|
||||
|
||||
### Administration
|
||||
#### Administration
|
||||
|
||||
- **bool setAddress(const uint8_t deviceAddress)** sets a new address for the sensor.
|
||||
If function succeeds the address changes immediately and will be persistent over a reboot.
|
||||
@ -131,7 +131,7 @@ Serial.println(dd, HEX); // prints YYYYMMDD e.g. 20210203
|
||||
```
|
||||
|
||||
|
||||
### I2C clock speed
|
||||
#### I2C clock speed
|
||||
|
||||
The library sets the clock speed to 25 KHz during operation
|
||||
and resets it to 100 KHz after operation.
|
||||
@ -142,7 +142,7 @@ The following function can change the I2C reset speed to e.g. 200 or 400 KHz.
|
||||
- **uint32_t getI2CResetSpeed()** returns the value set. Default is 100 KHz.
|
||||
|
||||
|
||||
### setMode
|
||||
#### setMode
|
||||
|
||||
The default mode at startup of the sensor is PPB = parts per billion.
|
||||
|
||||
@ -162,7 +162,7 @@ If the gas is unknown, PPB is in my opinion the preferred measurement.
|
||||
From an unverified source the following formula:
|
||||
M = molecular weight of the gas.
|
||||
|
||||
**μg/m3 = (ppb)\*(12.187)\*(M) / (273.15 + °C)**
|
||||
**μg/m3 = ppb \* M \* 12.187 / (273.15 + °C)**
|
||||
|
||||
Simplified formula for 1 atm @ 25°C:
|
||||
|
||||
@ -171,7 +171,7 @@ Simplified formula for 1 atm @ 25°C:
|
||||
Some known gasses
|
||||
|
||||
| gas | Common name | ratio ppb-μg/m3 | molecular weight M |
|
||||
|:-----|:------------------|:--------------------|:------------------:|
|
||||
|:-------|:--------------------|:----------------------|:--------------------:|
|
||||
| SO2 | Sulphur dioxide | 1 ppb = 2.62 μg/m3 | 64 gr/mol |
|
||||
| NO2 | Nitrogen dioxide | 1 ppb = 1.88 μg/m3 | 46 gr/mol |
|
||||
| NO | Nitrogen monoxide | 1 ppb = 1.25 μg/m3 | 30 gr/mol |
|
||||
@ -180,7 +180,7 @@ Some known gasses
|
||||
| C6H6 | Benzene | 1 ppb = 3.19 μg/m3 | 78 gr/mol |
|
||||
|
||||
|
||||
### Read the sensor
|
||||
#### Read the sensor
|
||||
|
||||
WARNING: The datasheet advises to take 3 seconds between reads.
|
||||
Tests gave stable results at 1.5 second intervals.
|
||||
@ -201,10 +201,10 @@ Typical value should be between 0.01 .. 999.99
|
||||
- **float readUGF3()** returns microgram per cubic feet.
|
||||
|
||||
|
||||
### Error Codes
|
||||
#### Error Codes
|
||||
|
||||
| ERROR_CODES | value |
|
||||
|:---------------------------|:-----:|
|
||||
|:----------------------------|:-------:|
|
||||
| AGS02MA_OK | 0 |
|
||||
| AGS02MA_ERROR | -10 |
|
||||
| AGS02MA_ERROR_CRC | -11 |
|
||||
@ -219,7 +219,7 @@ Typical value should be between 0.01 .. 999.99
|
||||
- **uint32_t lastUGM3()** returns last read UGM3 (microgram per cubic meter) value (cached).
|
||||
|
||||
|
||||
### Calibration
|
||||
#### Calibration
|
||||
|
||||
- **bool zeroCalibration()** to be called after at least 5 minutes in fresh air.
|
||||
See example sketch.
|
||||
@ -231,7 +231,7 @@ To be called after at least 5 minutes in fresh air.
|
||||
Returns true on success.
|
||||
|
||||
|
||||
### Other
|
||||
#### Other
|
||||
|
||||
- **bool readRegister(uint8_t address, RegisterData ®)** fills a data struct with the chip's register data at that address.
|
||||
Primarily intended for troubleshooting and analysis of the sensor. Not recommended to build applications on top of this method's raw data.
|
||||
@ -254,13 +254,28 @@ Read datasheet or table below for details. A new read is needed to update this.
|
||||
|
||||
## Future
|
||||
|
||||
- test test test ...
|
||||
#### Must
|
||||
|
||||
|
||||
#### Should
|
||||
|
||||
- improve documentation
|
||||
- add indicative table for PPB health zone
|
||||
- check the mode bits of the status byte with internal \_mode.
|
||||
- elaborate error handling.
|
||||
- create an async interface for **readPPB()** if possible
|
||||
- add indicative table for PPB health zone (source)
|
||||
- put the I2C speed code in 2 inline functions
|
||||
- less repeating conditional code places
|
||||
- setLowSpeed() + setNormalSpeed()
|
||||
- check the mode bits of the status byte with internal \_mode.
|
||||
- maximize robustness of state
|
||||
- test with hardware
|
||||
- different gasses ?
|
||||
|
||||
#### Could
|
||||
|
||||
- elaborate error handling.
|
||||
- create an async interface for **readPPB()** if possible
|
||||
- delay(30) blocks performance ==> async version of **readRegister()**
|
||||
- move code to .cpp?
|
||||
|
||||
|
||||
#### Wont
|
||||
|
||||
|
@ -11,29 +11,41 @@ isConnected KEYWORD2
|
||||
reset KEYWORD2
|
||||
|
||||
isHeated KEYWORD2
|
||||
lastRead KEYWORD2
|
||||
|
||||
|
||||
setAddress KEYWORD2
|
||||
getAddress KEYWORD2
|
||||
|
||||
getSensorVersion KEYWORD2
|
||||
getSensorDate KEYWORD2
|
||||
|
||||
setI2CResetSpeed KEYWORD2
|
||||
getI2CResetSpeed KEYWORD2
|
||||
|
||||
zeroCalibration KEYWORD2
|
||||
manualZeroCalibration KEYWORD2
|
||||
getZeroCalibrationData KEYWORD2
|
||||
|
||||
setPPBMode KEYWORD2
|
||||
setUGM3Mode KEYWORD2
|
||||
getMode KEYWORD2
|
||||
|
||||
readPPM KEYWORD2
|
||||
readPPB KEYWORD2
|
||||
readUGM3 KEYWORD2
|
||||
readPPM KEYWORD2
|
||||
readMGM3 KEYWORD2
|
||||
readUGF3 KEYWORD2
|
||||
|
||||
lastPPM KEYWORD2
|
||||
lastPPB KEYWORD2
|
||||
lastUGM3 KEYWORD2
|
||||
|
||||
zeroCalibration KEYWORD2
|
||||
lastRead KEYWORD2
|
||||
lastError KEYWORD2
|
||||
lastStatus KEYWORD2
|
||||
dataReady KEYWORD2
|
||||
|
||||
readRegister KEYWORD2
|
||||
|
||||
# Constants ( LITERAL1)
|
||||
AGS02MA_LIB_VERSION LITERAL1
|
||||
|
@ -21,7 +21,7 @@
|
||||
"type": "git",
|
||||
"url": "https://github.com/RobTillaart/AGS02MA.git"
|
||||
},
|
||||
"version": "0.3.2",
|
||||
"version": "0.3.3",
|
||||
"license": "MIT",
|
||||
"frameworks": "arduino",
|
||||
"platforms": "*",
|
||||
|
@ -1,5 +1,5 @@
|
||||
name=AGS02MA
|
||||
version=0.3.2
|
||||
version=0.3.3
|
||||
author=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
maintainer=Rob Tillaart <rob.tillaart@gmail.com>
|
||||
sentence=Arduino library for AGS02MA - TVOC sensor
|
||||
|
@ -2,7 +2,7 @@
|
||||
// FILE: unit_test_001.cpp
|
||||
// AUTHOR: Rob Tillaart
|
||||
// DATE: 2021-08-12
|
||||
// PURPOSE: unit tests for the AGS02NA tvoc sensor
|
||||
// PURPOSE: unit tests for the AGS02NA TVOC sensor
|
||||
// https://github.com/RobTillaart/AGS02MA
|
||||
// https://github.com/Arduino-CI/arduino_ci/blob/master/REFERENCE.md
|
||||
//
|
||||
@ -29,6 +29,7 @@
|
||||
// as millis() function is not implemented in
|
||||
// the Arduino-CI environment
|
||||
|
||||
|
||||
unittest_setup()
|
||||
{
|
||||
fprintf(stderr, "AGS02MA_LIB_VERSION: %s\n", (char *) AGS02MA_LIB_VERSION);
|
||||
@ -97,4 +98,4 @@ unittest(test_mode)
|
||||
|
||||
unittest_main()
|
||||
|
||||
// --------
|
||||
// -- END OF FILE --
|
||||
|
Loading…
Reference in New Issue
Block a user