Giter Site home page Giter Site logo

sensirion / arduino-gas-index-algorithm Goto Github PK

View Code? Open in Web Editor NEW
6.0 7.0 3.0 104 KB

Arduino Library for Sensirion's Gas Index Algorithm, providing a VOC and NOx Index output signal calculated from the SGP40/41 raw signals

License: BSD 3-Clause "New" or "Revised" License

C++ 29.14% C 70.86%
sensirion sgp voc nox sgp4x sgp41 sgp40 algorithm gas gas-index

arduino-gas-index-algorithm's Introduction

Sensirion Gas Index Algorithm Arduino Library

Sensirion's Gas Index Algorithm software provides a VOC and an NOx Index output signal calculated from the SGP40/41 raw signal inputs SRAW_VOC and SRAW_NOX. Note: for SGP40, only SRAW_VOC is available. This algorithm enables robust detection of ambient changes of VOCs and NOx with minimal sensor-to-sensor variation. The algorithm is based on a statistical gain-offset normalization and adapts both parameters constantly applying an exponentially decaying function of the learned parameters to be able to adapt to changing environments.

For the VOC Index output, the software must be instanced as VOC Algorithm while for the NOx Index output, the software must be instanced as NOx Algorithm. It is important to feed the raw signals to the corresponding algorithm (i.e., SRAW_VOC to the VOC Algorithm and SRAW_NOX to the NOx Algorithm) at a constant sampling interval which must coincide with the sampling interval that is used to read out the raw signals from the SGP40/41 sensor. The default sampling interval applied in the algorithm is 1 s. If your sampling interval is different, please use the constructor variant allowing you to pass the sampling interval. The VOC algorithm is tested for a sampling interval of 1s and 10s.

The algorithm calculates the VOC and NOx Index signals recursively from a single raw tick value of SRAW_VOC and SRAW_NOX, respectively, which are both measured by the SGP40/41 sensor at each time step, as well as internal states that are updated at each time step. These internal states are most importantly the recursively estimated mean and variance of the corresponding SRAW signal as well as some additional internal states such as uptime and other counters. After estimating the states, the algorithm converts the raw signals in ticks into either VOC or NOx Index, respectively, and applies an adaptive low-pass filter.

Installation

To install, download the latest release as .zip file and add it to your Arduino IDE via

Sketch => Include Library => Add .ZIP Library...

Dependencies

The dependency to the Sensirion I2C drivers are only needed to run the example, which uses a SGP40 resp SGP41 and a SHT4x sensor.

Quick Start to run the example

The example measures VOC and NOx ticks with a SGP41 sensor using a SHT4x to compensate temperature and humidity. The raw VOC and NOx measurement signals are then processed with the gas index algorithm to get VOC Index and NOx Index values.

For more details about the sensors and breakout boards check out http://sensirion.com/my-sgp-ek/.

  1. Install the driver dependencies listed above the same way as you installed this library (via Add .ZIP Library)

  2. Connect a SGP41 and SHT4x Sensor over I2C to your Arduino

  3. Open the exampleUsage sample project within the Arduino IDE

     File => Examples => Sensirion Gas Index Algorithm => exampleUsage
    
  4. Click the Upload button in the Arduino IDE or

     Sketch => Upload
    
  5. When the upload process has finished, open the Serial Monitor or Serial Plotter via the Tools menu to observe the measurement values and calculated Gas Index value. Note that the Baud Rate in the corresponding window has to be set to 115200 baud.

Low power example (SGP40)

The provided low power example demonstrate how to run the SGP40 sensor in low power mode and apply the VOC index algorithm to the acquired data.

Reduced power consumption is achieved by turning off the heater after each measurement. The heater is then turned back on by calling for a first ignored measurement that preceeds the actual measurement call by 170ms.

The following two low power modes have been tested:

Duty cycle Sampling interval Average power consumption at 1.8V
Continuous 1 s 6.3mW
20% 1 s <2.0mW
2% 10 s <0.2mW

Contributing

Contributions are welcome!

We develop and test this algorithm using our company internal tools (version control, continuous integration, code review etc.) and automatically synchronize the master branch with GitHub. But this doesn't mean that we don't respond to issues or don't accept pull requests on GitHub. In fact, you're very welcome to open issues or create pull requests :)

This Sensirion library uses clang-format to standardize the formatting of all our .cpp and .h files. Make sure your contributions are formatted accordingly:

The -i flag will apply the format changes to the files listed.

clang-format -i src/*.cpp src/*.h

Note that differences from this formatting will result in a failed build until they are fixed.

License

See LICENSE.

arduino-gas-index-algorithm's People

Contributors

leoniefierz avatar martgras avatar mbjoern avatar psachs avatar qfisch avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

arduino-gas-index-algorithm's Issues

Sample period in examples will be (slightly) longer than 1 second

While delay(1000) should block for around 1 second, the example doesn't take into account the use of delay() elsewhere. It would be more accurate to note the time of the last sample in loop(), and trigger a new sample when more than 1000ms have elapsed; while examples should be kept simple, this, along with a comment for why it is preferable to blindly using delay(), could be educational for the reader who is unfamiliar with that approach. The advice in the readme to change the default period in the algorithm from 1 second is also ill advised because this could be overwritten in an update, and the code could usefully mention the constructor variant that takes a sample period. Arguably better still, only have a constructor that takes a sample period, though this would now break existing code.

[Q] Low Power example doesn't allow setting NOx sample interval

When extending the Low Power example to use the SGP41 sensor, for NOxGasIndexAlgorithm there is no constructor available to set the sample interval. Shouldn't that constructor be added in the header file? (I've added in my local copy, just to have it consistent with the VOCGasIndexAlgorithm).
Or are there reasons that no interval, other than the default, should be used?

Minor typos in example

In a few places in the main example, debug output says "learing" rather than "learning".

Documentation 'Engineering_Guidelines_SEN5x' conflicting with implementation

In Sensirion_Engineering_Guidelines_SEN5x.pdf a "Gain factor" is discussed as follows:

(fresh-air and VOC events) at the same time. Note: this parameter may interfere with the gating behavior. The
gating threshold is fixed at VOC Index = 230 and thus, any event reaching this threshold will be treated
according to the setting of the “Gating Max Duration Minutes” or, in case the VOC Index output is always
below 230, the learning of offset and gain will always be active even during long VOC events.

My interpretation of this is that it describes the concepts of a gain and a gate, and that the gate with its fixed value of 230 would determine whether or not a VOC reading would influence the learning.

Q1: in the code there is a define for GasIndexAlgorithm_INDEX_GAIN of 230, which is the only occurrence of 230 that I found. Shouldn't this be something like GasIndexAlgorithm_INDEX_GATING_THRESHOLD given the discussion of Gain Factor and gating?

Q2: GasIndexAlgorithm_INDEX_GAIN is used as a default value for params->mIndex_Gain, which is then used as a multiplier in the process function. This would make sense were it actually a gain, however as the value of 230 appears to relate to the gating level, is this correct, or is there an unintentional gain of 230 being applied if using the default values?

Q3: Is 230 a sensible default value for the gain.

Q4: Is gating actually implemented, and if so, where/how? The value of 230 from GasIndexAlgorithm_INDEX_GAIN appears only to be only used as mentioned above, and not as a comparison test.

I may have multiple misunderstandings, in which case apologies for that, however on the face of it there do appear to be some implementation issues here.

[QUESTION] Using the sensor at lower duty cycles

Hi!

Thanks for the library for this SPG40 Sensor.
We would like to ask about the low power modes and the limitations about the Gas Index Algorithm.

In particular, in the datasheet, it's specified that the SRAW_VOC measurements need to be fed into the Gas Index Algorithm every second. However, the low power table in your README indicates 10s.

Questions are:

. Is it possible to set an arbitrary interval for this data? In other words, can the Gas Index Algorithm be fed with data every 60s, or more?
. If a hard reset happens on the MCU performing this algorithm, the current values are lost. How is this handled? In our particular application, a hard reset takes place ever 24h on the main MCU. Does it makes sense to use the sensor in this type of application (low cost sensor device for AQ monitoring).

Thank you in advance

How to get VOC signal in PPM

Dear All,

somebody know how to extract from the raw signal the ppb values? at least for the VOC.

Best Regards

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.