How to fix Arduino I2C Wire error: call of overloaded 'begin(const int&, const int&, int)' is ambiguous
Problem:
You are trying to call Wire.begin()
for I2C using
Wire.begin(Pin_I2C_SDA, Pin_I2C_SCL, 400000);
but you see an error message like
src/MyI2C.cpp: In function 'void MyInitI2C()':
src/NyI2C.cpp:139:47: error: call of overloaded 'begin(const int&, const int&, int)' is ambiguous
Wire.begin(Pin_I2C_SDA,Pin_I2C_SCL, 400000);
^
In file included from include/MyIO.hpp:2:0,
from src/MyI2C.cpp:2:
/home/uli/.platformio/packages/framework-arduinoespressif32/libraries/Wire/src/Wire.h:79:10: note: candidate: bool TwoWire::begin(int, int, uint32_t)
bool begin(int sda=-1, int scl=-1, uint32_t frequency=0); // returns true, if successful init of i2c bus
^
/home/uli/.platformio/packages/framework-arduinoespressif32/libraries/Wire/src/Wire.h:80:10: note: candidate: bool TwoWire::begin(uint8_t, int, int, uint32_t)
bool begin(uint8_t slaveAddr, int sda=-1, int scl=-1, uint32_t frequency=0);
Solution
This happens with specific versions of the Arduino framework. For me it happened specifically when upgrading to arduino-esp32 version 2.0.1
.
You need to explicitly cast the third argument (400000
) to uint32_t
in order to tell the compiler which of the two functions you want to call:
Wire.begin(Pin_I2C_SDA, Pin_I2C_SCL, 400000);