RAK12047 Gas Sensor data too long errors

Hello, I’m trying to get the RAK 12047 VOC Gas Sensor module to function. However I’m getting “Data too long to fit in transmit buffer” errors from the Sensirion SGP40 / Arduino Wire library and have run out of ideas on what could cause this.

We use the 2nd generation RAK19007 base board with the RAK 11200 ESP32 core. The only other module connected is the RAK12047 Gas Sensor, which is connected to Slot A. I have confirmed that my development environment using the Arduino IDE functions correctly and have also tried the RAK18001 Buzzer module (now temporarily disconnected) before successfully. So I’m quite confident the problem shouldn’t be in the compilation of flashing stages.

For the RAK12047 I’m just trying to get the example from the official Quick Start Guide working. I have only modified the WB_IO variable to refer to slot A. Just to confirm, below is the exact .ino file I use:

/**
   @file RAK12047_SGP40_GetVOCIndex.ino
   @author rakwireless.com
   @brief Get the VOC index data from the sensor SGP40 and print it out through the serial port.
          The voc index can directly indicate the quality of the air. The higher the value, the worse the air quality.
   @version 0.1
   @date 2022-1-22
   @copyright Copyright (c) 2020
**/

#include <SensirionI2CSgp40.h> // Click here to get the library: http://librarymanager/All#SensirionI2CSgp40
#include <Wire.h>

SensirionI2CSgp40 sgp40;

void setup()
{
  uint16_t error;
  char errorMessage[256];
  uint16_t serialNumber[13];
  uint8_t serialNumberSize = 3;

  pinMode(WB_IO1, OUTPUT);
  digitalWrite(WB_IO1, HIGH);

  // Initialize Serial for debug output
  time_t timeout = millis();
  Serial.begin(115200);
  while (!Serial)
  {
    if ((millis() - timeout) < 5000)
    {
      delay(100);
    }
    else
    {
      break;
    }
  }

  Serial.println("RAK12047 SGP40 example");

  Wire.begin();
  sgp40.begin(Wire);

  error = sgp40.getSerialNumber(serialNumber, serialNumberSize);
  if (error)
  {
    Serial.print("Error trying to execute getSerialNumber(): ");
    errorToString(error, errorMessage, 256);
    Serial.println(errorMessage);
  }
  else
  {
    Serial.print("Serial Number:");
    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 = sgp40.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  srawVoc   = 0;
  float     vocIndex  = 0;
  /*
   * @brief Set the relative humidity and temperature in the current environment.
   *        Temperature and humidity calibration has been performed inside the sensor.
   *        RH/ticks=RH/%×65535/100
   *        T/ticks=(T/°C + 45)×65535/175
   */
  uint16_t  defaultRh = 0x8000;  // 50 %RH
  uint16_t  defaultT  = 0x6666;  // 25 ℃

  delay(1000);

  error = sgp40.measureRawSignal(defaultRh, defaultT, srawVoc);
  if (error)
  {
    Serial.print("Error trying to execute measureRawSignal(): ");
    errorToString(error, errorMessage, 256);
    Serial.println(errorMessage);
  }
  else
  {
    Serial.print("SRAW_VOC:");
    Serial.print(srawVoc);
    vocIndex = (float)srawVoc/131.07 ;

   /* VOC index.
    * The voc index can directly indicate the quality of the air. The higher the value, the worse the air quality.
    *   0-100,no need to ventilate,purify.
    *   100-200,no need to ventilate,purify.
    *   200-400,ventilate,purify.
    *   400-500,ventilate,purify intensely.
    */
    Serial.print("  VOC Index:");
    Serial.println(vocIndex);
  }
}

But when I run the code I only get the following output:

-> RAK12047 SGP40 example
-> Error trying to execute getSerialNumber(): Data too long to fit in transmit buffer
-> Error trying to execute executeSelfTest(): Data too long to fit in transmit buffer
-> Error trying to execute measureRawSignal(): Data too long to fit in transmit buffer
-> Error trying to execute measureRawSignal(): Data too long to fit in transmit buffer
-> Error trying to execute measureRawSignal(): Data too long to fit in transmit buffer
...

Could someone help tell me what am I doing wrong here?

Welcome to the forum @airuser

You must not change the WB_IO2 to WB_IO1.
WB_IO2 is controlling the power supply of 3V3_S one every slot.

RAK12047 is using 3V3_S, so you have to set WB_IO2 to high to get it working.

Hi @airuser ,

The default example you are trying to run should work without any modification just like what beegee said that WB_IO2 must not be changed to WB_IO1.

However, when I tried to run it on RAK11200, I also got the same error you have even with the correct WB_IO2 setting.

Checking things out, I found out that if you change the buffer of Wire.h of RAK11200, it remove that buffer sizer error.

This modification is not needed on RAK4630 which makes the behavior of RAK11200 weird. Here’s the reading of my VOC sensor. RAK11200 and RAK4630 shows both readings but I am not sure if my sensors is still ok since putting lots of Isopropyl Alcohol doesn’t change the VOC dramatically (I expect it to rise up in value).

image

Thank you both for the help! After lowering the I2C_BUFFER_LENGTH to 255 and changing WB_IO back to 2 the module indeed started working. I must have gotten confused with the WB_IO settings when I initially didn’t get it to function with 2.

Haven’t seen any problems with very light testing thus far. I hope you can publish an update for the RAKwireless board library to address this issue so we don’t always have to manually edit the Wire.h file for all future development environments when using RAK12047 with the RAK11200.