I would like to use pins 8 and 9 for PIN_WIRE0_SDA and PIN_WIRE0_SCL. The only way I have been able to make this happen is to change the pins_arduino.h and restart the IDE. This does work, but it seems heavy-handed; not only will it impose this pin mapping on all of my projects that use a KB2040, I suspect that this change will need to be done again if a new version of the rp2040 firmware is released.
It feels like there should be a way to do this inside of a sketch, but I have not been able to figure it out.
First, apparently this is easy if you are using MicroPython:
Code: Select all
import machine
sda=machine.Pin(8)
scl=machine.Pin(9)
i2c=machine.I2C(0,sda=sda, scl=scl, freq=400000)
Second, the SerialPIO library seems to be able to dynamically set the pins used for TX0 and RX0 without having to modify pins_arduino.h:
Code: Select all
using Transport = MIDI_NAMESPACE::SerialMIDI<SerialPIO>;
SerialPIO pins(4, 5);
Transport serialMIDI(pins);
MIDI_NAMESPACE::MidiInterface<Transport> MIDI((Transport&)serialMIDI);