Sensirion / arduino-i2c-sgp41

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.
BSD 3-Clause "New" or "Revised" License
7 stars 6 forks source link

Sensirion I2C SGP41 lib - measureRawSignals() error #2

Closed Plombir18 closed 1 year ago

Plombir18 commented 2 years ago

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

include

include

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

Plombir18 commented 2 years ago

any feedback is greatly appreciated...

Plombir18 commented 2 years ago

Dear Sirs,

After thorough analysis I found a problem with the delivered SGP41 sensors.

Initial situation: new project in VS code PlatformIO ESP32-S3 with the included Sensirion library Sensirion I2C SGP41@^0.1.0, code and serial output attached. All sensors were used on the same hardware with the same wiring and same code.

Serial number OK: SerialNumber:0x000003D8DB01

Serial numbers NOK: 1) SerialNumber:0x000001936FB5 2) SerialNumber:0x0000019371B1 3) SerialNumber:0x0000019373E1 4) SerialNumber:0x0000019370AD 5) SerialNumber:0x000001937505

Please review why the configured NOK sensors do not provide any data values. The function SensirionI2CCommunication::receiveFrame() returns a zero in the variable _numBytes for the NOK sensors. Debug_NOK Serial_monitor_NOK Serial_monitor_OK SGP41_ESP32.zip

psachs commented 2 years ago

Hi @Plombir18

Thanks for the request. Most of the time "Not enough data received" is due to some kind of unstable I2C connection.

Since one sensor works, but in general your connection is very unstable your connection might have a lot of noise or insufficient/unstable power supply. This would also explain why reading the serial number works and the measurements not. When you start the measurement (e.g. through self-test or measure) the heater on the sensor will be activated which draw much more peak current. A capacitor of 1uF for decoupling as described on the SGP41 datasheet on Page 8 might help.

Sensirion_Gas_Sensors_Datasheet_SGP41.pdf

The standard I2C pins for ESP32 are 21 (SDA) and 22 (SCL). We always take this pins for testing. I am not sure how your hardware setup looks like. An easier solution might be to test with another connection cable and check if you have the same behavior if you use the default I2C pins for ESP32.

With the code itself I don't see any issue. When time permits I will also test if I can reproduce the issue when I connect an SGP41 to the pins 37 and 38.

Plombir18 commented 1 year ago

The problem could be identified. The cause is the assembly of development parts instead of production parts by the PCB assembly service provider.