Pico mbed-core wire.h: how to specify SDA / SCL-pins?

Hi everybody I was looking up the wire.h and the wire.cpp-file of the
Raspberry pico mbed-core
trying to understand how SDA / SCL-pins can be chosen.

There is this part of the code

class MbedI2C : public HardwareI2C
{
  public:
    MbedI2C(int sda, int scl);

which seems to deal with specifying the SDA / SCL-pins.
But I have no idea what I would have to write in my code because
using wire is done without any explicit constructor
there is only

wire.begin();

and that's it.

void arduino::MbedI2C::begin() {
	end();
	master = new mbed::I2C(_sda, _scl);
}

the begin-function uses _sca, _scl but the heck from where do the values come from?
where are the values for the SDA-pin / SCL-pin set???

Whenever I see a demo-code using I2C there is only

wire.begin();

with empty parenthesis
The Earl Philhower-core has explicit functions for this which I understand.
But I do not understand how to assign particular I2C pins in the mbed-core.

There is a public function in the library that takes the pin number as follows

class MbedI2C : public HardwareI2C
{
  public:
    MbedI2C(int sda, int scl);
    MbedI2C(PinName sda, PinName scl);
    virtual void begin();

Maybe try using that ?

Sure. What you have posted is the declaration.
But how does the code look like that makes use of this declaration?
How does the code look like that I write into my *.ino-file?

This declaration has again just a

without any parameters.

There is this mysterious

which has a completely different name.
In my *.ino-sketch: do I write

MbedI2C(6,7); 

??

There is no harm in trying it

I have installed the earl Philhower-core

I explicitly don't want to install the mbed-core

So I can't test it. You seem to not want to answer my question directly.
I guess I have to wait until somebody else gives a direct answer.

That is because I don't know the answer !

Well, if I'm not mistaken I think it's here (from "Wire.cpp"):

#if WIRE_HOWMANY > 0
arduino::MbedI2C Wire(I2C_SDA, I2C_SCL);
#endif
#if WIRE_HOWMANY > 1
arduino::MbedI2C Wire1(I2C_SDA1, I2C_SCL1);
#endif
#if WIRE_HOWMANY > 2
arduino::MbedI2C Wire2(I2C_SDA2, I2C_SCL2);
#endif

However custom SDA/SCL can be used using MbedI2C 2-parameters constructor overload.

Hi @docdoc

thank you for contributing to my thread.

Still your post does not explicitly show
how does the code in the

*.ino-file

look like that will specify certain IO-pins as SDA / SCL?

I'm sorry maybe I can't exactly get what you're asking for, especially because I never used mbed, but as far as I can see the MbedI2C class is defined on ArduinoCore-mbed/libraries/Wire/Wire.h you linked at first (and I think you already load), so what @UKHeliBob suggested before (give MbedI2C(6,7); a try) seems legit. What am I missing?

With this line of code you posted what I was asking for.

I was speculating if using MbedI2C(6,7); would work.

@UKHeliBob answered "give it a try"

Well I gave it a try by installing a second portable Arduino 1.8.19 ide and tried to compile the I2C-scanner-sketch without any modification.
Compilation aborted with an error-message.

Me personal I am done with the RP2040-mbed-core. I will NOT use the mbed-core.

You seem to prefer the Earl Phillhower-core too.

Well, without knowing the specific error it's hard to tell something.

Anyway, I'm not an expert about this topic so I now stop replying especially if you solved it using that Earl Phillhower-core. Good coding!

What I have done is to create a new TwoWire (arduino::MbedI2C) object as follows:

TwoWire myI2C(SDA_PIN,SCL_PIN);

Then in setup() it needs to be started:

myI2C.begin();

and lastly, you need to pass which I2C device to use to your device's object

Adafruit_GPS GPS(&myI2C);

if it takes it in the constructor or

mydevice.begin(&myI2C)

if the library you are using has a begin function that can take a different I2C device as an argument.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.