Question interfacing a master ESP32 with 13 slave ESP32's using I2C communication on alternate I2C Pins (33 & 32)

I am working on a senior design project where I am using multiple ESP32's to control multiple devices.
There will be another ESP32 which will serve as the master and control the peripheral ESP32's.

The issue is, I'm using the default I2C pins (21_SDA & 22_SCL) for other tasks (one pin is used in the serial programmer so I avoided using it).
I've decided to use the ESP32's second I2C pins (33_SDA & 32_SCL) for the connection between the slave ESP32's.

Now, I've got the Wire.h I2C library to work when connecting to an Arduino Uno (ESP=Master, Uno=Slave)

There doesn't seem to be an issue with the master because it does not require an address.
The issue is that I want to define the slave pins as 33_SDA and 32_SCL, as well as define an address for multiple slaves.
The issue is that I'm not entirely sure how to redefine the pins and set an address.

Master example: Wire.begin(I2C_SDA, I2C_SCL); //Using alternate I2C pins on ESP32 Master

Slave, example:
TwoWire SERVO1 = TwoWire(4);
SERVO1.begin(I2C_SDA, I2C_SCL);

I've been to a number of sites and the closest example I can find is this one from randomnerdtutorials:

I'm certain there has to be an easier way to do this rather than edit the ESP32 bords file (which I'm not really comfortable doing at my skill level).
Basically, if anyone knows the correct way to implement the Wire.h library to redefine the ESP32's I2C pins AND define a slave address, that would be amazing.

This is my first ever post on Arduino forum.
I normally avoid posting, preferring to read, but I have read everywhere I could think to look and still struggling to figure it out.

Thanks in advance.

Pictures of code are poo!.

I have used the ESP32's I2C API to put the I2C pins anywhere I like. Inter-Integrated Circuit (I2C) - ESP32 - โ€” ESP-IDF Programming Guide latest documentation (espressif.com)

The API does work under the Arduino IDE.

1 Like

Yeah, I'm fine with the I2C staying with the secondary pins, I just don't know the correct way to define them and address them.
It seems to address them, we're suppose to put them in
Wire.begin(address);

But, that also seems like the only place to redefine the SDA and SCL pins
Wire.begin(I2C_SDA, I2C_SCL);
where #define I2C_SDA 33
and #define I2C_SCL 32

Sorry, about the "poo" code picture.
I'm very new here, and I'm sure I'm going to make plenty of mistakes.

I have 13 ESP32's connected to a Raspberry Pi. The RPi is the MQTT Broker, runs a Python program on the ESP32's data, runs a FTP server, and does Image processing on the ESP32's image data.

Has the OP considered using ESPNOW and the wireless capabilities for inter-device communications?

1 Like

not sure what OP means...
Also, I'm not entirely sure how to implement the config "Configuration Example (Master)" process in the link you shared.
Is that in the Wire.cpp?

Sorry, I'm new to this stuff.
I apologize if I ask relatively simple questions.

I'd rather just stick to the Wire.h library if possible.
I'd rather not use Bluetooth or Wi-Fi.
Maybe I've overcomplicated a relatively simple question...
How do you address a slave I2C, when you also need to defining alternate pins?
The ESP32 alternate pins (32 & 33) are true I2C pins, and not software implemented.

ESP-NOW with ESP32: Send Data to Multiple Boards (one-to-many) | Random Nerd Tutorials

#include <Arduino.h>
#include <Wire.h>
#include <WireSlave.h>

#define SDA_PIN 21
#define SCL_PIN 22
#define I2C_SLAVE_ADDR 0x04

Seems like you have to be an I2C maven in the first place, not as "PnP" a solution as it may seem.

1 Like