I2C
The ESP32 has two I2C channels and any pin can be set as SDA or SCL. When using the ESP32 with the Arduino IDE, the default I2C pins are:
- GPIO 21 (SDA)
- GPIO 22 (SCL)
If you want to use other pins, when using the wire library, you just need to call:
Wire.begin(SDA, SCL);
So, if I’m working on a project that is already using 21 and 22 (like the DS3231 RTC) and I want to add another I2C sensor/device, I would use the Wire function call like
Wire.begin(12,13);
which would assign SDA = 12 and SCL = 13?
I think I got a handle on it now.
If you want to use other pins, when using the wire library, you #define the pins, like this:
#define SDA 33
#define SCL 32
and in the setup() you use them with this:
Wire.begin(SDA, SCL)
Hi.
If the sensors have different I2C addresses, which is probable, you can use the same pins.
Alternatively, you can use different pins without any problem.
We have a guide about I2C with the ESP32 that you might find useful:
ESP32 I2C Communication: Set Pins, Multiple Bus Interfaces and Peripherals (Arduino IDE)
Regards,
Sara