Sensirion / embedded-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
1 stars 2 forks source link

Not enough data received in sam21d boards #1

Closed JavaldeUB closed 10 months ago

JavaldeUB commented 1 year ago

Hi, I'm been trying to get any reading from my sgp41 sensor with a seeeduino xiao and no success. I'm using the example in this library. It gives the serial number but in the selfTest answers "not enough data received". The board is based on the sam21d microcontroller and I've seen around that with esp boards the library has the same problem. All the best, Javi

psachs commented 1 year ago

Hi

I am not very familiar with the SAM21 microcontroller. The I2C interfaces ususally require a pull-up resistor to work. Most higher end platforms like Raspberry PI and Arduino have built-in pull up resistors for the dedicated I2C interfaces.

Unfortunately the "not enough data received" error is not always conclusive. The I2c interfacing might not work at all, the signals have too much noise (e.g. pull-up resistor is not designed right for the sensor) or any other error leading to failures in data transmission.

What implementation are you exactly using? (e.g. sample implementation of this driver) And do you have by any chance the link to the exact board you are using?

JavaldeUB commented 1 year ago

Hi Pascal, Good to hear from you. Here is the link to the board I'm using. It's similar to the esp266 but with some differences (the type of things that mess with your code). https://www.seeedstudio.com/Seeeduino-XIAO-Arduino-Microcontroller-SAMD21-Cortex-M0+-p-4426.html Regarding the pull-up resistors this is the type of connection I have @.** where R11 and R12 are 4.7KOhm each. The transistor is attached to the SDA and SCL coming out from the sam21d. Here is the code I'm using /

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.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);
}

}

And it comes from here: https://github.com/Sensirion/arduino-i2c-sgp41

I hope this helps, Regards, Javier

psachs commented 1 year ago

Hi Javier

Thanks for the info. According to the Seed Studio, the SAMD21 operates at 3.3V I2C levels. SGP41 operates between 1.7V and 3.6V. Therefore you don't need any level shifter. Source: https://wiki.seeedstudio.com/Seeeduino-XIAO-by-Nanase#i2c

The 4k7 pull-ups you use should be fine. We recommend 10k pull-ups (depending on the frequency and operating voltage). If it is easy for you to test that out you can try it. If you happen to have access to a scope or logic analyzer you can also check the signal directly.

Without access to hardware I can not further help with debugging. The "not enough data received" error is most likely due to errors in signal detection, but it's just a blind guess from me. I will order a Seedstudio SAMD21 for testing but this will take a couple of days to arrive.

JavaldeUB commented 1 year ago

His Pascal, Thanks for the reply. I had new developments this morning. I placed a 4.7 resistor at the vdd input and the sensor started to give some data after the conditioning sequence. However, the sraw_vocx and the sraw_nocx are stuck at a value close to 65536 (which is the 2^16). I left the sensor more than an hour measuring to see if it changed but nothing happened. Any thoughts? All the best, Javier

Aquest missatge, i els fitxers adjunts que hi pugui haver, pot contenir informació confidencial o protegida legalment i s’adreça exclusivament a la persona o entitat destinatària. Si no consteu com a destinatari final o no teniu l’encàrrec de rebre’l, no esteu autoritzat a llegir-lo, retenir-lo, modificar-lo, distribuir-lo, copiar-lo ni a revelar-ne el contingut. Si l’heu rebut per error, informeu-ne el remitent i elimineu del sistema tant el missatge com els fitxers adjunts que hi pugui haver.

Este mensaje, y los ficheros adjuntos que pueda incluir, puede contener información confidencial o legalmente protegida y está exclusivamente dirigido a la persona o entidad destinataria. Si usted no consta como destinatario final ni es la persona encargada de recibirlo, no está autorizado a leerlo, retenerlo, modificarlo, distribuirlo o copiarlo, ni a revelar su contenido. Si lo ha recibido por error, informe de ello al remitente y elimine del sistema tanto el mensaje como los ficheros adjuntos que pueda contener.

This email message and any attachments it carries may contain confidential or legally protected material and are intended solely for the individual or organization to whom they are addressed. If you are not the intended recipient of this message or the person responsible for processing it, then you are not authorized to read, save, modify, send, copy or disclose any part of it. If you have received the message by mistake, please inform the sender of this and eliminate the message and any attachments it carries from your account.

psachs commented 1 year ago

Raw values around the max value of 65536 indicates that the hotplate is not running. Did you connect VDD and VDDH to the same source as instructed in the datasheet? Also make sure that peak current is supported.

You can also run the self test to see if all hotplates and MOx material are working correctly (command: 0x28 0x0E)

JavaldeUB commented 1 year ago

Hi Pascal, I don't think the peak current is an issue. Now, I have connected the sensor to a bench top power supply so the current shouldn't be a problem. Yes, the electronics and the heater are connected to that power supply. I've checked the board and it happens that the 4.7Ohm resistor is placed before bothe, vdd and vddh. Could be that the problem? All the best, Javier

El 21 abr. 2023 13:31, Pascal Sachs @.***> escribió:

Raw values around the max value of 65536 indicates that the hotplate is not running. Did you connect VDD and VDDH to the same source as instructed in the datasheet? Also make sure that peak current is supported.

You can also run the self test to see if all hotplates and MOx material are working correctly (command: 0x28 0x0E)

— Reply to this email directly, view it on GitHubhttps://github.com/Sensirion/embedded-i2c-sgp41/issues/1#issuecomment-1517686468, or unsubscribehttps://github.com/notifications/unsubscribe-auth/A2DPOV43VOMCHEGL355WTL3XCJV2JANCNFSM6AAAAAAXD3OFUI. You are receiving this because you authored the thread.Message ID: @.***>

Aquest missatge, i els fitxers adjunts que hi pugui haver, pot contenir informació confidencial o protegida legalment i s’adreça exclusivament a la persona o entitat destinatària. Si no consteu com a destinatari final o no teniu l’encàrrec de rebre’l, no esteu autoritzat a llegir-lo, retenir-lo, modificar-lo, distribuir-lo, copiar-lo ni a revelar-ne el contingut. Si l’heu rebut per error, informeu-ne el remitent i elimineu del sistema tant el missatge com els fitxers adjunts que hi pugui haver.

Este mensaje, y los ficheros adjuntos que pueda incluir, puede contener información confidencial o legalmente protegida y está exclusivamente dirigido a la persona o entidad destinataria. Si usted no consta como destinatario final ni es la persona encargada de recibirlo, no está autorizado a leerlo, retenerlo, modificarlo, distribuirlo o copiarlo, ni a revelar su contenido. Si lo ha recibido por error, informe de ello al remitente y elimine del sistema tanto el mensaje como los ficheros adjuntos que pueda contener.

This email message and any attachments it carries may contain confidential or legally protected material and are intended solely for the individual or organization to whom they are addressed. If you are not the intended recipient of this message or the person responsible for processing it, then you are not authorized to read, save, modify, send, copy or disclose any part of it. If you have received the message by mistake, please inform the sender of this and eliminate the message and any attachments it carries from your account.

psachs commented 1 year ago

I don't think the 4.7Ohm resistor should be a Problem. However, for full disclosure: I am a software engineer and no expert in hardware circuits when it comes to details.

From the datasheet: "The VDD pin must be decoupled with an RC element. The required decoupling for VDDH depends on the power supply network connected to the sensor, a capacitor of 1 uF is recommended."

For SGP41 you usually don't need an external power supply. Most development boards should be able to handle the requirements.

Are you still running the example we provide? And the self-test passes? This would be an indication that the sensor is working and gets enough power.

psachs commented 10 months ago

I could finally test the driver with a Seeed XIAO SAMD21 board using the a MicroE Envronment 2 click board which comes with all the necessary electronics installed. The default example runs without any issue with such a setup.