Coder Social home page Coder Social logo

sensirion / arduino-i2c-sgp41 Goto Github PK

View Code? Open in Web Editor NEW
5.0 5.0 5.0 433 KB

The SGP41 is Sensirion’s new digital VOC (volatile organic compounds) and NOx sensor designed for easy integration into air purifiers or demand-controlled ventilation.

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

C++ 100.00%
sensirion voc nox sgp arduino driver sensor arduino-library sgp4x svm4x

arduino-i2c-sgp41's Introduction

Sensirion I2C SGP41 Arduino Library

This is the Sensirion SGP41 library for Arduino using the modules I2C interface.

Click here to learn more about the SGP41 sensor.

Installation

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

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

Don't forget to install the dependencies listed below the same way via Add .ZIP Library

Note: Installation via the Arduino Library Manager is coming soon.

Dependencies

Quick Start

  1. Connect the SGP41 Sensor to your Arduino board's standard I2C bus. Check the pinout of your Arduino board to find the correct pins. The pinout of the SGP41 Sensor board can be found in the data sheet.

    • VDD of the SEK-SGP41 to the 3.3V of your Arduino board
    • GND of the SEK-SGP41 to the GND of your Arduino board
    • SCL of the SEK-SGP41 to the SCL of your Arduino board
    • SDA of the SEK-SGP41 to the SDA of your Arduino board
  2. Open the exampleUsage sample project within the Arduino IDE

     File => Examples => Sensirion I2C SGP41 => exampleUsage
    
  3. Click the Upload button in the Arduino IDE or

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

Contributing

Contributions are welcome!

We develop and test this driver 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-i2c-sgp41's People

Contributors

leoniefierz avatar mbjoern avatar psachs avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar

arduino-i2c-sgp41's Issues

Sensirion I2C SGP41 lib - measureRawSignals() error

Hello,

I have installed Sensirion I2C SGP41 lib in a new project, but still I don't manage to read any sensor values. The SGP41 is connected to ESP32-S3 with SDA pin 37 and SCL pin 38. I can read the serial number but the sensor data values are blank.

Does anyone have any idea what is going wrong here?

Thanks in advance
Alex

Code:

#include <Arduino.h>

#include <SensirionI2CSgp41.h>

#include <Wire.h>

SensirionI2CSgp41 sgp41;

// time in seconds needed for NOx conditioning

uint16_t conditioning_s = 10;

void setup() {

Serial.begin(115200);

while (!Serial) {

    delay(100);

}

Wire.setPins(37,38);

Wire.begin();

uint16_t error;

char errorMessage[256];

sgp41.begin(Wire);

uint16_t serialNumber[3];

uint8_t serialNumberSize = 3;

error = sgp41.getSerialNumber(serialNumber, serialNumberSize);

if (error) {

    Serial.print("Error trying to execute getSerialNumber(): ");

    errorToString(error, errorMessage, 256);

    Serial.println(errorMessage);

} else {

    Serial.print("SerialNumber:");

    Serial.print("0x");

    for (size_t i = 0; i < serialNumberSize; i++) {

        uint16_t value = serialNumber[i];

        Serial.print(value < 4096 ? "0" : "");

        Serial.print(value < 256 ? "0" : "");

        Serial.print(value < 16 ? "0" : "");

        Serial.print(value, HEX);

    }

    Serial.println();

}

uint16_t testResult;

error = sgp41.executeSelfTest(testResult);

if (error) {

    Serial.print("Error trying to execute executeSelfTest(): ");

    errorToString(error, errorMessage, 256);

    Serial.println(errorMessage);

} else if (testResult != 0xD400) {

    Serial.print("executeSelfTest failed with error: ");

    Serial.println(testResult);

}

}

void loop() {

uint16_t error;

char errorMessage[256];

uint16_t defaultRh = 0x8000;

uint16_t defaultT = 0x6666;

uint16_t srawVoc = 0;

uint16_t srawNox = 0;

delay(1000);

if (conditioning_s > 0) {

    // During NOx conditioning (10s) SRAW NOx will remain 0

    error = sgp41.executeConditioning(defaultRh, defaultT, srawVoc);

    conditioning_s--;

} else {

    // Read Measurement

    error = sgp41.measureRawSignals(defaultRh, defaultT, srawVoc, srawNox);

}

if (error) {

    Serial.print("Error trying to execute measureRawSignals(): ");

    errorToString(error, errorMessage, 256);

    Serial.println(errorMessage);

} else {

    Serial.print("SRAW_VOC:");

    Serial.print(srawVoc);

    Serial.print("\t");

    Serial.print("SRAW_NOx:");

    Serial.println(srawNox);

}

}

Monitor output:

ESP-ROM:esp32s3-20210327
Build:Mar 27 2021
rst:0x1 (POWERON),boot:0x8 (SPI_FAST_FLASH_BOOT)
SPIWP:0xee
mode:DIO, clock div:1
load:0x3fcd0108,len:0x39c
load:0x403b6000,len:0x9a4
load:0x403ba000,len:0x2868
entry 0x403b61c0
SerialNumber:0x000001936FB5
Error trying to execute executeSelfTest(): Not enough data received
Error trying to execute measureRawSignals(): Not enough data received
Error trying to execute measureRawSignals(): Not enough data received
Error trying to execute measureRawSignals(): Not enough data received
Error trying to execute measureRawSignals(): Not enough data received
Error trying to execute measureRawSignals(): Not enough data received
Error trying to execute measureRawSignals(): Not enough data received
Error trying to execute measureRawSignals(): Not enough data received
Error trying to execute measureRawSignals(): Not enough data received
Error trying to execute measureRawSignals(): Not enough data received
Error trying to execute measureRawSignals(): Not enough data received
Error trying to execute measureRawSignals(): Not enough data received
Error trying to execute measureRawSignals(): Not enough data received
Error trying to execute measureRawSignals(): Not enough data received
Error trying to execute measureRawSignals(): Not enough data received
Error trying to execute measureRawSignals(): Not enough data received
Error trying to execute measureRawSignals(): Not enough data received
Error trying to execute measureRawSignals(): Not enough data received
Error trying to execute measureRawSignals(): Not enough data received
Error trying to execute measureRawSignals(): Not enough data received
Error trying to execute measureRawSignals(): Not enough data received
Error trying to execute measureRawSignals(): Not enough data received
Error trying to execute measureRawSignals(): Not enough data received
Error trying to execute measureRawSignals(): Not enough data received
Error trying to execute measureRawSignals(): Not enough data received
Error trying to execute measureRawSignals(): Not enough data received
Error trying to execute measureRawSignals(): Not enough data received
Error trying to execute measureRawSignals(): Not enough data received
Error trying to execute measureRawSignals(): Not enough data received
Error trying to execute measureRawSignals(): Not enough data received
Error trying to execute measureRawSignals(): Not enough data received
Error trying to execute measureRawSignals(): Not enough data received
Error trying to execute measureRawSignals(): Not enough data received
Error trying to execute measureRawSignals(): Not enough data received
Error trying to execute measureRawSignals(): Not enough data received
Error trying to execute measureRawSignals(): Not enough data received
Error trying to execute measureRawSignals(): Not enough data received
Error trying to execute measureRawSignals(): Not enough data received

conditioning time in exampleUsage.ino

In the example, time of conditioning is based on the delay in void loop().
According to the datasheet, a 10 second conditioning time (=heating of the sensor)
is recommendet before the first measurement is taken, but that 10 seconds must not be exceeded as the sensor may be subjected to overheating and damage.

It may be better to use a timer and refer to the problem or even use a delay and take a measurement during setup to prevent damaging the senor if a user manipulates the code without minding this (shame on me).

Sensirion SGP41 I2C code for ESP32-S2

Hello,
I'm having trouble getting the following code from Sensirion working on my ESP32-S2 dev board. https://github.com/Sensirion/arduino-i2c-sgp41.

I've made the following addition to the Sensirion code to setup the correct GPIOs for the I2C bus

  • Wire.begin(6, 7);

I believe the hardware is connected correctly for the following reasons.

  1. I'm able to see the correct address on the I2C scanner
  2. I'm able to retrieve my components' serial number
  3. Another Sensirion sensor on the same I2C bus (different sensor model and address) is functioning correctly.

However I get the following error when running the above code
-"executeSelfTest failed with error: Not enough data received" and "Error trying to execute measureRawSignals(): Not enough data received"

I've added serialprints to self-test result, raw values, and conditioning countdown. Self-test is returning "42405"

Please let me know how I can debug and next steps, thanks for helping me out.

Code:

#include <Arduino.h>
#include <SensirionI2CSgp41.h>
#include <Wire.h>

SensirionI2CSgp41 sgp41;

// time in seconds needed for NOx conditioning
uint16_t conditioning_s = 10;

void setup() {

  Serial.begin(115200);
  while (!Serial) {
    delay(100);
  }

  Wire.begin(6, 7);

  uint16_t error;
  char errorMessage[256];

  sgp41.begin(Wire);

  uint16_t serialNumber[3];
  uint8_t serialNumberSize = 3;

  error = sgp41.getSerialNumber(serialNumber, serialNumberSize);

  if (error) {
    Serial.print("Error trying to execute getSerialNumber(): ");
    errorToString(error, errorMessage, 256);
    Serial.println(errorMessage);
  } else {
    Serial.print("SerialNumber:");
    Serial.print("0x");
    for (size_t i = 0; i < serialNumberSize; i++) {
      uint16_t value = serialNumber[i];
      Serial.print(value < 4096 ? "0" : "");
      Serial.print(value < 256 ? "0" : "");
      Serial.print(value < 16 ? "0" : "");
      Serial.print(value, HEX);
    }
    Serial.println();
  }

  uint16_t testResult;
  error = sgp41.executeSelfTest(testResult);
  Serial.println(testResult);
  if (error) {
    Serial.print("Error trying to execute executeSelfTest(): ");
    errorToString(error, errorMessage, 256);
    Serial.print(errorMessage);
  } else if (testResult != 0xD400) {
    Serial.print("executeSelfTest failed with error: ");
    Serial.println(testResult);
  }
}

void loop() {
  uint16_t error;
  char errorMessage[256];
  uint16_t defaultRh = 0x8000;
  uint16_t defaultT = 0x6666;
  uint16_t srawVoc = 0;
  uint16_t srawNox = 0;

  delay(1000);

  if (conditioning_s > 0) {
    // During NOx conditioning (10s) SRAW NOx will remain 0
    error = sgp41.executeConditioning(defaultRh, defaultT, srawVoc);
    conditioning_s--;
    Serial.println(conditioning_s);
  } else {
    // Read Measurement
    error = sgp41.measureRawSignals(defaultRh, defaultT, srawVoc, srawNox);
  }

  if (error) {
    Serial.print("Error trying to execute measureRawSignals(): ");
    errorToString(error, errorMessage, 256);
    Serial.println(errorMessage);
    Serial.println(srawVoc);
    Serial.println(srawNox);
  } else {
    Serial.print("SRAW_VOC:");
    Serial.print(srawVoc);
    Serial.print("\t");
    Serial.print("SRAW_NOx:");
    Serial.println(srawNox);
  }
}

Output:

10:18:20.930 -> ESP-ROM:esp32s2-rc4-20191025
10:18:20.930 -> Build:Oct 25 2019
10:18:20.930 -> rst:0x1 (POWERON),boot:0x9 (SPI_FAST_FLASH_BOOT)
10:18:20.930 -> SPIWP:0xee
10:18:20.930 -> mode:DIO, clock div:1
10:18:20.962 -> load:0x3ffe6100,len:0x524
10:18:20.962 -> load:0x4004c000,len:0xa70
10:18:20.962 -> load:0x40050000,len:0x298c
10:18:20.962 -> entry 0x4004c18c
10:18:21.027 -> SerialNumber:0x000003C83069
10:18:21.358 -> 42405
10:18:21.358 -> Error trying to execute executeSelfTest(): Not enough data received9
10:18:22.416 -> Error trying to execute measureRawSignals(): Not enough data received
10:18:22.416 -> 0
10:18:22.416 -> 0
10:18:23.468 -> 8
10:18:23.468 -> Error trying to execute measureRawSignals(): Not enough data received
10:18:23.468 -> 0
10:18:23.468 -> 0
10:18:24.512 -> 7
10:18:24.512 -> Error trying to execute measureRawSignals(): Not enough data received
10:18:24.512 -> 0
10:18:24.512 -> 0
10:18:25.565 -> 6
10:18:25.565 -> Error trying to execute measureRawSignals(): Not enough data received
10:18:25.565 -> 0
10:18:25.565 -> 0
10:18:26.620 -> 5
10:18:26.620 -> Error trying to execute measureRawSignals(): Not enough data received
10:18:26.620 -> 0
10:18:26.620 -> 0
10:18:27.677 -> 4
10:18:27.677 -> Error trying to execute measureRawSignals(): Not enough data received
10:18:27.677 -> 0
10:18:27.677 -> 0
10:18:28.727 -> 3
10:18:28.727 -> Error trying to execute measureRawSignals(): Not enough data received
10:18:28.727 -> 0
10:18:28.727 -> 0
10:18:29.780 -> 2
10:18:29.780 -> Error trying to execute measureRawSignals(): Not enough data received
10:18:29.780 -> 0
10:18:29.780 -> 0
10:18:30.828 -> 1
10:18:30.828 -> Error trying to execute measureRawSignals(): Not enough data received
10:18:30.828 -> 0
10:18:30.828 -> 0
10:18:31.948 -> 0
10:18:31.948 -> Error trying to execute measureRawSignals(): Not enough data received
10:18:31.948 -> 0
10:18:31.948 -> 0
10:18:33.065 -> Error trying to execute measureRawSignals(): Not enough data received
10:18:33.097 -> 0
10:18:33.097 -> 0

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.