Sensirion SPS30 dust sensor: I2C comms

HI David,

I have tried it on my Argon and with the following changes it works. You have to make sure you SET the new structure as well else you might get memory violations / buffer overrun.

Sketch changes

Globally define:

constexpr size_t I2C_BUFFER_SIZE_N = 128;

 hal_i2c_config_t config = {
        .size = sizeof(hal_i2c_config_t),
        .version = HAL_I2C_CONFIG_VERSION_1,
        .rx_buffer = new (std::nothrow) uint8_t[I2C_BUFFER_SIZE_N],
        .rx_buffer_size = I2C_BUFFER_SIZE_N,
        .tx_buffer = new (std::nothrow) uint8_t[I2C_BUFFER_SIZE_N],
        .tx_buffer_size = I2C_BUFFER_SIZE_N
};

Now you have a structure to upload.

In setup BEFORE SP30_COMMS.begin();
hal_i2c_init(HAL_I2C_INTERFACE1, &config);

This will set the new structure, assuming you use WIRE. If you use WIRE1 then it should be HAL_I2C_INTERFACE2

sps30.h

Change line 240 to
#define I2C_LENGTH 128

As you pointed out you have change else I2C_BUFFER_LENGTH will set it back
comment out lines 247 to 250

    //#if defined I2C_BUFFER_LENGTH       // ESP32
    //    #undef  I2C_LENGTH
    //    #define I2C_LENGTH  I2C_BUFFER_LENGTH
    //#endif

regards,
Paul