Unable to configure ESP32-WROOM-30 in I2C master mode with Wire.begin(2, 4)

GeraldLi
Posts: 3
Joined: Thu Jun 19, 2025 2:51 pm

Unable to configure ESP32-WROOM-30 in I2C master mode with Wire.begin(2, 4)

Postby GeraldLi » Thu Jun 19, 2025 3:01 pm

Unable to configure ESP32-WROOM-30 in I2C master mode with Wire.begin(2, 4)

My code is OK with Wire.begin(14, 15) or Wire.begin(21, 22)
Thanks in advance https://gelit.ch/

#include <Wire.h> // I2C library
#include <SparkFunSX1509.h> // http://librarymanager/All#SparkFun_SX1509
#define I2C_SDA 2 //14 // default=21
#define I2C_SCL 4 //15 // 22
SX1509 io; // Create object

void setup() {
Wire.begin(I2C_SDA, I2C_SCL);
Serial.begin(115200);
Serial.println("GL1-SX1509");

if (io.begin(0x3E) == false)
{
Serial.println("Failed to communicate. Check wiring and address of SX1509.");
while (1);
}
io.pinMode(1,OUTPUT);
}

void loop() {
io.digitalWrite(1,1); delay(2000);
io.digitalWrite(1,0); delay(2000);
}

lbernstone
Posts: 1132
Joined: Mon Jul 22, 2019 3:20 pm

Re: Unable to configure ESP32-WROOM-30 in I2C master mode with Wire.begin(2, 4)

Postby lbernstone » Sun Jun 22, 2025 8:21 am

gpio 2&4 have pulldowns on boot. This may confuse the connected device. Try to put a delay (maybe ~250ms) in your setup before you init the i2c. You can use the WireScan example to test how long a delay is needed.

GeraldLi
Posts: 3
Joined: Thu Jun 19, 2025 2:51 pm

Re: Unable to configure ESP32-WROOM-30 in I2C master mode with Wire.begin(2, 4)

Postby GeraldLi » Sun Jun 22, 2025 2:32 pm

Good idea but same error with delay(1000); at begin of setup

lbernstone
Posts: 1132
Joined: Mon Jul 22, 2019 3:20 pm

Re: Unable to configure ESP32-WROOM-30 in I2C master mode with Wire.begin(2, 4)

Postby lbernstone » Mon Jun 23, 2025 5:08 am

Well, it must be something electrical on your system. It works fine in emulation. Check if the scan example works.
https://wokwi.com/projects/434526065481900033

GeraldLi
Posts: 3
Joined: Thu Jun 19, 2025 2:51 pm

Re: Unable to configure ESP32-WROOM-30 in I2C master mode with Wire.begin(2, 4)

Postby GeraldLi » Mon Jun 23, 2025 7:55 am

Thanks I have tried with SSD1306 and test is OK

Who is online

Users browsing this forum: No registered users and 4 guests