Help understanding where Wire I2C gets inititalized

I am just trying to understand how the pieces fit together. If I look at the ESP32_i2c Dual Bus Example (pasted below), It is not clear where “Wire” gets initialized or created or where begin is called. I have searched the repository and cannot find any other references. Am I missing something?

  Serial.begin(115200);
  _delay(750);

  Wire.setClock(400000);
  Wire1.setClock(400000);

  // Normally SimpleFOC will call begin for i2c but with esp32 begin() is the only way to set pins!
  // It seems safe to call begin multiple times
  Wire1.begin(19, 23, (uint32_t)400000);

  sensor0.init();
  sensor1.init(&Wire1);

Hi @slamjammin ,

the Wire.begin() is called from MagneticSensorI2C::init().

Initializing the wire object (e.g. setting pins, etc) is out of scope for SimpleFOC and has to be done by the application code beforehand. If you want to use a custom I2C port instance, you can initialize it and then pass it to sensor.init(), like in your code example.

Note: in Arduino framework, some MCU like the I2C clock speed to be set before calling wire.begin(), while other MCUs like you to set if afterwards. If you’re experiencing crashes, try moving the wire.setClock() to be after the sensor.init().

Note also: I2C sensors are much too slow to get good FOC control, especially not for 2 sensors at the same time. You may get it working eventually, esp. for higher ohm gimbal type motors, but the performance will never be good. You’ll save a lot of time if you don’t bother with I2C, and switch to ABZ or SPI type sensors from the start…