ESP32-S2 I2C non default pins

Hello

I am trying to connect a a sensor with I2C, however I need to place this sensor in non default pins, however ESP32-S2 can use more pins for I2C, I have tried to define SCL and SCA in GPIO34 and GPIO33, but it doesn't work. At first I tried to use Wire.begin(SCA,SCL), but it didn't work. I did some research and I tried using TwoWire, however keeps not working.
I do not use libraries for comunicating with the sensor just "Wire.h"

Thanks in advance for your comments

//----------------------------------------------------
// LIBRARIES AND VARIABLES FOR IMU
//----------------------------------------------------
#include "Wire.h"
#define I2C_Freq 100000
const uint8_t I2C_SDA = 33;
const uint8_t I2C_SCL = 34;
TwoWire I2C_0 = TwoWire(0);

int IMUAddress = 0x6A;                                                // Device address LSM6DS3
#define ACC_CONFIG_CTRL1_G 0x10                                       // Accel configuration register address
#define GYR_CONFIG_CTRL2_G 0x11                                       // Gyro configuration register address
#define IMU_STATUS_REG 0x1E                                           // New data available register
#define IMU_OUTX_L_G 0x22                                             // X gyro data register address
#define IMU_OUTY_L_G 0x24                                             // Y gyro data register address
#define IMU_OUTZ_L_G 0x26                                             // Z gyro data register address
#define IMU_OUTX_L_A 0x28                                             // X accel data register address
#define IMU_OUTY_L_A 0x2A                                             // Y accel data register address
#define IMU_OUTZ_L_A 0x2C                                             // Z accel data register address

uint8_t rawAccX1, rawAccX2, rawAccY1, rawAccY2, rawAccZ1, rawAccZ2;
uint8_t rawGyrX1, rawGyrX2, rawGyrY1, rawGyrY2, rawGyrZ1, rawGyrZ2;

uint8_t dataAvailable;

int samplerate=104;                                                   // DEFAULT IMU sample rate
uint8_t regFS = 0x40;                                                 // Default 104Hz
uint8_t regScaleAcc = 0x04;                                           // Default 16g
uint8_t regScaleGyr = 0x0C;                                           // Default 2000dps
uint8_t regAcc;
uint8_t regGyr;
void setup(){
  regAcc=regFS+regScaleAcc;
  regGyr=regFS+regScaleGyr;
  I2C_0.begin(I2C_SDA, I2C_SCL, I2C_Freq);
  I2C_0.beginTransmission(IMUAddress); 
  I2C_0.endTransmission( false);                                         // no stop, to create a repeated start.
  
  //Acelerometer configuration
  I2C_0.beginTransmission(IMUAddress); 
  I2C_0.write(ACC_CONFIG_CTRL1_G);
  I2C_0.write(regAcc);                                                   //Set accelerometer sample rate at 104Hz and range to +-16g
  I2C_0.endTransmission();
  
  //Gyroscope configuration
  I2C_0.beginTransmission(IMUAddress); 
  I2C_0.write(GYR_CONFIG_CTRL2_G);                   
  I2C_0.write(regGyr);                                                   //Set gyroscope sample rate at 104Hz and range to +-2000dps
  I2C_0.endTransmission();
}

As described here

I think you are missing a Wire.begin(I2C_SDA, I2C_SCL); call.

Thanks for your comment Whandall

But I changed Wire.begin(SCA,SCL) for I2C_0.begin(SCA,SCL), as described there, but non of this options are working

I don't understand why you don't want to use the predefined Wire object,
which seems to work for others, but it should work also.

Good luck with your project.

Well If I could, I would. It is a custom made PCB and I don't have conections for the sensor in those pins.

I used debug mode and I get the following errors:

[  1884][E][esp32-hal-i2c-slave.c:224] i2cSlaveInit(): invalid pins sda=32, scl=-96
[  1885][E][Wire.cpp:167] begin(): Slave Init ERROR
[  1886][E][Wire.cpp:313] beginTransmission(): Unfinished Repeated Start transaction! Expected requestFrom, not beginTransmission! Clearing...
[  1898][E][esp32-hal-i2c.c:142] i2cWrite(): could not acquire lock
[  1904][E][esp32-hal-i2c.c:142] i2cWrite(): could not acquire lock

Found the solution

I have to delete the first beginTransmision