Skip to content

Commit affdf95

Browse files
committed
Fix I2C Pinout on RP2040 Variants
1 parent 5ac35f3 commit affdf95

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

src/components/i2c/hardware.cpp

+8-5
Original file line numberDiff line numberDiff line change
@@ -76,18 +76,19 @@ void I2cHardware::InitBus(bool is_default, const char *sda, const char *scl) {
7676

7777
// Assign I2C bus pins
7878
if (is_default) {
79+
#ifndef ARDUINO_ARCH_RP2040
7980
pin_sda = SDA;
8081
pin_scl = SCL;
82+
#else
83+
// RP2040 BSP uses a different naming scheme than Espressif for I2C pins
84+
pin_sda = PIN_WIRE0_SDA;
85+
pin_scl = PIN_WIRE0_SCL;
86+
#endif
8187
} else {
8288
pin_sda = atoi(sda);
8389
pin_scl = atoi(scl);
8490
}
8591

86-
WS_DEBUG_PRINT("I2C Bus SDA: ");
87-
WS_DEBUG_PRINTLN(pin_sda);
88-
WS_DEBUG_PRINT("I2C Bus SCL: ");
89-
WS_DEBUG_PRINTLN(pin_scl);
90-
9192
// Enable pullups
9293
pinMode(pin_scl, INPUT_PULLUP);
9394
pinMode(pin_sda, INPUT_PULLUP);
@@ -123,6 +124,8 @@ void I2cHardware::InitBus(bool is_default, const char *sda, const char *scl) {
123124
_bus->setClock(50000);
124125
#elif defined(ARDUINO_ARCH_RP2040)
125126
_bus = &WIRE;
127+
_bus->setSDA(pin_sda);
128+
_bus->setSCL(pin_scl);
126129
_bus->begin();
127130
#elif defined(ARDUINO_ARCH_SAM)
128131
_bus = new TwoWire(&PERIPH_WIRE, pin_sda, pin_scl);

0 commit comments

Comments
 (0)