Code Monkey home page Code Monkey logo

sensirion / gas-index-algorithm Goto Github PK

View Code? Open in Web Editor NEW
16.0 7.0 10.0 2.94 MB

Sensirion's Gas Index Algorithm provides a VOC and NOx Index output signal calculated from the SGP40/41 raw signals

Home Page: https://sensirion.github.io/gas-index-algorithm/

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

Shell 1.14% Python 20.71% Makefile 0.56% Batchfile 0.70% SWIG 2.64% C 74.24%
sensirion sgp voc nox sgp4x sgp41 sgp40 algorithm gas gas-index

gas-index-algorithm's Introduction

Sensirion Gas Index Algorithm

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. In case, a different sampling interval should be used the definition of the sampling interval in the h.file of the algorithm must be changed, too.

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.

Quick Start

Steps to calculate a VOC/NOx gas index value:

  1. Allocate a struct of type GasIndexAlgorithmParams and initialize the parameters to their default values.

    a. For VOC Engine Algorithm initialize with:

    GasIndexAlgorithmParams params;
    GasIndexAlgorithm_init(&params, GasIndexAlgorithm_ALGORITHM_TYPE_VOC);
    

    b. For NOx Engine Algorithm initialze with

    GasIndexAlgorithmParams params;
    GasIndexAlgorithm_init(&params, GasIndexAlgorithm_ALGORITHM_TYPE_NOX);
    
  2. Read RH and T values, e.g. from a SHT4x sensor

  3. Read VOC or NOx raw value (ticks) from SGP4x sensor. Provide RH and T values as ticks from step 2 to the VOC read function to get temperature and humidity compensated raw index value. NOTE: do consider that e.g. the RH ticks for SHT4x are specified differently than the RH ticks requested by SGP41, checkout the sensor datasheets for more details.

  4. Process raw signal to get index value

    int32_t voc_raw_value; // read from sensor in step 2-3
    int32_t voc_index_value; 
    GasIndexAlgorithm_process(&params, voc_raw_value, &voc_index_value)
    

Fix point version

If your platform does not support floating point you can use the fixpoint version of the algorithm. The code can be found in the folder sensirion_gas_index_algorithm_fixpoint.

This version does not provide an interface to change the sampling rate from code to allow minimal code size. The sampling rate can be change in the header file sensirion_gas_index_algorithm_fixpoint/sensirion_gas_index_algorithm.h by changing the define GasIndexAlgorithm_SAMPLING_INTERVAL on line 69-

Raspberry Pi Example VOC and NOx Index

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/.

Steps to run the example on your Raspberry Pi:

  1. Connect a SGP41 and SHT4x sensor over I2C to your Raspberry Pi
  2. Download this package from Sensirion Github Page. Extract the ZIP file and navigate to the subfolder examples/raspberry-pi
  3. Get additional source files:
    1. Run make download
    2. If the download with make does not work, you can manually get the needed source files:
  4. Copy the examples/raspberry-pi folder to your Raspberry Pi
  5. Compile the example on your Raspberry Pi
    1. Open a terminal
    2. Navigate to the example directory. E.g. cd ~/examples/raspberry-pi
    3. Run make all to compile the driver
  6. Run the example with ./algorithm_example_usage

Python Example

Find the Python usage and documentation in the Python README.

Algorithm usage with SGP40 in low power mode

The provided low power examples (python+raspberry) 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 precedes the actual measurement call by 170ms.

To achieve further power consumption reduction, the sampling interval can be increased to 10s (from the default 1s). Note that the sampling frequency needs to be passed to the VOC algorithm at initialization.

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 .c 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 */*.c */*.h

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

License

See LICENSE.

gas-index-algorithm's People

Contributors

leoniefierz avatar mbjoern avatar psachs avatar qfisch avatar rnestler avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

gas-index-algorithm's Issues

Micropython port?

Hello,

I was intending to use this sensor for my air quality monitor system on a raspberry pi pico and noticed is already available for python, how likely is it that this will get ported to micropython/circuitpython?

Sorry if this is not the place to discuss this.

Add extern "C" blocks in header files for C++ compatibility

The header files of the library currently lack extern "C" {} block, making it tricky to use in C++ projects. To improve compatibility, I propose adding the following to the library's header files:

#ifdef __cplusplus
extern "C" {
#endif

// existing header content

#ifdef __cplusplus
}
#endif

This change ensures that the library can be linked in C++ projects without encountering name mangling issues.

Reference: Stack Overflow - Explanation of extern "C".

SGP41 VOC NOx index algorithm in low power mode

I have been using SGP41 sensors in combination with SHT41 for two or three years now. It works really well with a raspberry pi zero 2 with the algorithm provided by Sensirion. However, the self-heating is quite significant and I would like to use them in a "low power" mode. Such an algorithm seems to be provided for the SGP40 (VOC) but I can't find one for the SGP41 (VOC and NOx). Is there one and, if so, where can I find it? Thanks, Jerome CANDAU

VOC algo backend

Hi, we have been trying to use this sensor for the last few weeks. We are confused about the sensor working principle. Our final product will be battery power. This means we have to turn off the sensor while we are not reading the sensor.
From what we understand, the sensor sets up a new baseline after every few hours.
This means it can be used as a VOC alarm system, but cant be used as a sensor that can read VOC over time.

How to install package on Ubuntu Linux system

Hi, I have tried to evaluate the SGP41 on a desktop PC with ubuntu 22.04.4

I have installed a virtual environment and tried:

pip install sensiron-gas-algorithm

The Error I got then was:
ERROR: Could not find a version that satisfies the requirement sensiron-gas-algorithm (from versions: none)
ERROR: No matching distribution found for sensiron-gas-algorithm

Is there a way to solve this error?

kind regards
David

Help Needed

Hi, i've followed steps for using Sensirion Gas Index Algorithm python module as described here:
https://github.com/Sensirion/gas-index-algorithm/blob/master/python-wrapper/README.rst

I've properly installed module using 'pip install sensirion-gas-index-algorithm' > OK

And then tried a VOC python script with the code provided for SGP40 chip (demo code):

            from sensirion_gas_index_algorithm.voc_algorithm import VocAlgorithm
            voc_algorithm = VocAlgorithm()
            s_voc_raw = 27000  # read out from SGP41
            for _ in range(100):
                voc_index = voc_algorithm.process(s_voc_raw)
                print(voc_index)

BUT whatever s_voc_raw is set to (27000/18000...), voc_index return is always '0' instead of VOC value (0-500).

I've spent hours to find a way to get it working... but haven't resolved it until now.

Does anybody faced the same problem ? Did i missed something ?

Any help would be greatly appreciated !

Thanks a lot, Sebastien

how to convert voc index to ppm

Hi sirs, thanks for this great chip as well as the libraries your company provided. I did tried chip SGP40, acquired VOC index through your company's gas-index-algorithm and it works just fine. However, as we would like to the air quality in PPM unit and have no idea to convert with each other. could you please help for that. Thanks in advanced.

MicroPython

Would it be possible to make a MicroPython wrapper for the SGP41 sensor?

Low Power implementation SGP41

Hi guys

We are using SGP41 together with ESP32(ESP-IDF framework) and everything is working fine for powered devices.

Now we are looking into implementing the SGP41 on low power mode. The ESP32 has an ULP(ultra low power processor) that runs while the uC is in deep sleep, this ULP can comunicate usign i2c but is is limitated in what it can do since it is programmed in assembler and has a set amount of memory avaiable.

Our workflow would be the following

uC goes to deep sleep -> ulp reads values from SGP41 every certain time(1s or 10s) and saves the SRAW values -> after 5 minutes uC wakes up from deep sleep retrieves those values and inject them in the algorithm.

Firstable is this viable? Can the SRAW values be injected as a "batch" once the uC is preparing the sample?

Do you have any experience with best approach to implement SGP41 with ESP32 or similar uC?

Thanks
Regards
Pedro

NOX index stuck on 1

Hi,

I can communicate with the SGP41, get raw results (also with valid CRC) VOC like 27000-30000 raw and NOX 16000-17000 raw).

When I process them with GasIndexAlgorithm_process() I get nice VOC indexes which also alter with ventilation. I live next to a busy point in a middle sized city and the NOX index starts at 0, but always stays at 1. With a 24hr check, it is never changed.

How can we verify the algoritm? (like with VOC i sometimes spray some ethanol in the room to check the VOC)

I made two structs:

GasIndexAlgorithmParams VocPar;
GasIndexAlgorithmParams NoxPar;

They are initialised with:

GasIndexAlgorithm_init(&VocPar, GasIndexAlgorithm_ALGORITHM_TYPE_VOC);
GasIndexAlgorithm_init(&NoxPar, GasIndexAlgorithm_ALGORITHM_TYPE_NOX);

And processed:

GasIndexAlgorithm_process(&VocPar, (int)rawticks, &VOCI);
and
GasIndexAlgorithm_process(&NoxPar, (int)rawticks, &NOXI); (in another function)

The raw value of NOX changes, isn't fixed at one specific number.

LIBRARY_VERSION_NAME "3.1.0"

VOC index gets stuck at 400+ value

Hi,

We have this device that does air quality monitoring utilizing several sensors from Sensirion including the SGP40. Everything seems to be working fine when booted but VOC index value gets stuck at a certain value (400+) after some time. The value goes up 400+ when tested with Alcohol so the SGP40 is working, but it never goes down below 400 approx. SGP40 works fine if the device is rebooted. We are testing 4 devices and all of them shows the same result. Our device includes the following sensors:

* CO2 - SCD4X
* Temp/Hum  - SHT
* TOF - Other vendor
* Particulate Matter - SPS30

Further details:
* The device runs on a 32 bit microcontroller
* Same problems occurs when using the previous VOC index algorithm and the new GAS index Algorithm
* The device has a very small and compact form factor with proper ventilation through holes all over its body
* Sample code provided was used, no modification of the Gas index algorithm source code was done.
* No humidity compensation (Default compensation was used) so I skipped step 2 of this sample code https://github.com/Sensirion/gas-index-algorithm/blob/master/examples/raspberry-pi/low_power_example.c
* All other sensors are working fine
* Communication: I2C

Questions:
* What might be causing this problem? (sgp40's internal temperature might be rising inside the enclosure? etc.)
* Is it an issue on our hardware?

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.