Page 1 of 1

Connecting two ESP32s via I2C

Posted: Mon Apr 29, 2019 7:58 pm
by fodgeri
Hello,

Is there any solution to connect two or more esp32s via cable on i2c protocol? Unfortunately, the UART connection did not work for us because it was really unreliable e.g: when we restarted one esp device it caused a restart on the second device too.

Are the any other solutions (except I mentioned above) to connect two esp32s via cable?

Thank you for your help,
Gary

Re: Connecting two ESP32s via I2C

Posted: Tue Apr 30, 2019 1:36 am
by ESP_Sprite
Yes, you can set one as an I2C master and another one as an I2C slave. However, I'd look into what's going on with the UART restarting your 2nd ESP32 first... there's no intrinsic hardware-based way that can happen, so there's either a fault in your software or in your external hardware, and there's a good chance these carry over to an I2C-based solution as well.

Re: Connecting two ESP32s via I2C

Posted: Tue Apr 30, 2019 6:35 am
by fodgeri
Thank you for your quick reply! We did everything like in examples. Connected the rx/tx pins on the devices, initialize the UART1 ports, and we monitored the UART0.

This is the initialization:

Code: Select all

void init() {
    const uart_config_t uart_config = {
        .baud_rate = 115200,
        .data_bits = UART_DATA_8_BITS,
        .parity = UART_PARITY_DISABLE,
        .stop_bits = UART_STOP_BITS_1,
        .flow_ctrl = UART_HW_FLOWCTRL_DISABLE
    };
    uart_param_config(UART_NUM_1, &uart_config);
    uart_set_pin(UART_NUM_1, TXD_PIN, RXD_PIN, UART_PIN_NO_CHANGE, UART_PIN_NO_CHANGE);
    // We won't use a buffer for sending data.
    uart_driver_install(UART_NUM_1, RX_BUF_SIZE * 2, 0, 0, NULL, 0);
}
The connection working but it is really unreliable. Sometimes the devices randomly restarting, and as I mentioned earlier it does not matter what code is in the second device (we tried with getting started wifi example) if it restarts, the first device restarts too. It transmits something on the TX pin that triggers the restart on the first device.

Gary