ABugNamedBeetle / MPU6050-and-Raspberry-Pi-Pico-on-Arduino-IDE

Read Data from MPU6050 with Pico (Arduino IDE)
6 stars 1 forks source link

error: no matching function for call to 'TwoWire::TwoWire(int, int)' #1

Open g-struchin opened 1 year ago

g-struchin commented 1 year ago

I get an error

mpu_test:9:26: error: no matching function for call to 'TwoWire::TwoWire(int, int)'
    9 | TwoWire CustomI2C0(10, 11); //important
      |                          ^
In file included from C:\Users\gstru\Documents\Arduino\libraries\Adafruit_BusIO/Adafruit_I2CDevice.h:5,
                 from C:\Users\gstru\Documents\Arduino\libraries\Adafruit_BusIO/Adafruit_BusIO_Register.h:9,
                 from C:\Users\gstru\Documents\Arduino\libraries\Adafruit_MPU6050/Adafruit_MPU6050.h:21,
                 from C:\Users\gstru\Documents\Arduino\pico test\mpu_test\mpu_test.ino:4:
C:\Users\gstru\Documents\ArduinoData\packages\rp2040\hardware\rp2040\2.7.1\libraries\Wire\src/Wire.h:39:5: note: candidate: 'TwoWire::TwoWire(i2c_inst_t*, pin_size_t, pin_size_t)'
   39 |     TwoWire(i2c_inst_t *i2c, pin_size_t sda, pin_size_t scl);
      |     ^~~~~~~
C:\Users\gstru\Documents\ArduinoData\packages\rp2040\hardware\rp2040\2.7.1\libraries\Wire\src/Wire.h:39:5: note:   candidate expects 3 arguments, 2 provided
C:\Users\gstru\Documents\ArduinoData\packages\rp2040\hardware\rp2040\2.7.1\libraries\Wire\src/Wire.h:37:7: note: candidate: 'constexpr TwoWire::TwoWire(const TwoWire&)'
   37 | class TwoWire : public HardwareI2C {
      |       ^~~~~~~
C:\Users\gstru\Documents\ArduinoData\packages\rp2040\hardware\rp2040\2.7.1\libraries\Wire\src/Wire.h:37:7: note:   candidate expects 1 argument, 2 provided
C:\Users\gstru\Documents\ArduinoData\packages\rp2040\hardware\rp2040\2.7.1\libraries\Wire\src/Wire.h:37:7: note: candidate: 'constexpr TwoWire::TwoWire(TwoWire&&)'
C:\Users\gstru\Documents\ArduinoData\packages\rp2040\hardware\rp2040\2.7.1\libraries\Wire\src/Wire.h:37:7: note:   candidate expects 1 argument, 2 provided
exit status 1
no matching function for call to 'TwoWire::TwoWire(int, int)'

I think the 3rd argument is missing. But I don't understand what type it should be. \ArduinoData\packages\rp2040\hardware\rp2040\2.7.1\libraries\Wire\src/Wire.h file:

TwoWire::TwoWire(i2c_inst_t *i2c, pin_size_t sda, pin_size_t scl) {
    _sda = sda;
    _scl = scl;
    _i2c = i2c;
    _clkHz = TWI_CLOCK;
    _running = false;
    _txBegun = false;
    _buffLen = 0;
}

arduino version:

1.8.19 (Windows Store 1.8.57.0)
JoeSiu commented 1 year ago

@g-struchin Got the same error, fixed it by removing the line TwoWire CustomI2C0(20, 21);, and add / update the following three line instead:

Wire.setSDA(20); // Add this
Wire.setSCL(21); // Add this
if (!mpu.begin(0x68, &Wire, 0)) { // Replace &CustomI2C0 with &Wire
...

Check the Arduino-Pico documentation for more infos.