# ESP32 Inter-Chip Serial Communication

**URL:** <https://forum.arduino.cc/t/esp32-inter-chip-serial-communication/1406489>\
**Category:** Networking, Protocols, and Devices\
**Created:** [September 16, 2025, 2:26pm UTC](https://forum.arduino.cc/t/esp32-inter-chip-serial-communication/1406489 "2025-09-16T14:26:49Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![dinesha77](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/dinesha77/32/1100172_2.png) [@dinesha77](https://forum.arduino.cc/u/dinesha77)\
**Post date:** [September 16, 2025, 2:26pm UTC](https://forum.arduino.cc/t/esp32-inter-chip-serial-communication/1406489/1 "2025-09-16T14:26:49Z")

</div>

Hi there,

I'm trying to connect two ESP32 DOIT DevKit V1 boards (AliExpress) through a serial connection. My intention is for the master board to send a command over serial to the slave board, which would then start its Bluetooth functionality. This would allow a device to connect and stream audio to an external DAC via I2S.

With the test code below, I was simulating this, but it doesn't work as expected. I only see "Master -\> hello" on the slave's serial monitor, but nothing appears on the master's serial monitor. However, if I change the code to use a string instead of the structured data, it works perfectly.

Any clues as to what I might be doing wrong here?

**Physical Wiring:**  
Master TX (GPIO17) → Slave RX (GPIO16)  
Master RX (GPIO16) ← Slave TX (GPIO17)  
GND → GND

Master code

```arduino
HardwareSerial CommSerial(2);

const int MASTER_RX_PIN = 16;
const int MASTER_TX_PIN = 17;

unsigned long last_ms = 0;
const int interval_ms = 1000;

typedef struct struct_message {
  byte command;
  char device_name[50];
} struct_message;

void setup() {
  Serial.begin(9600);
  CommSerial.begin(9600, SERIAL_8N1, MASTER_RX_PIN, MASTER_TX_PIN);
}

void loop(){ 
  if (millis() - last_ms > interval_ms) {
    last_ms = millis();

    SendBTCommands(1, "Master -> hello");
  }

  handleBTIncomingDate();
}

void SendBTCommands(byte cmd, const char* name) {
  struct_message myMessage;
  myMessage.command = cmd;
  strcpy(myMessage.device_name, name);

  CommSerial.write((byte*)&myMessage, sizeof(myMessage));
}

void handleBTIncomingDate() {
  if (CommSerial.available()) {
    struct_message rx_msg_struct;

    uint8_t incomingData[sizeof(rx_msg_struct)];
    size_t rx_msg_length;

    rx_msg_length = CommSerial.readBytesUntil('\n', incomingData, sizeof(incomingData));

    if (rx_msg_length == sizeof(incomingData)) { // got a msg from a sensor
      memcpy(&rx_msg_struct, incomingData, sizeof(rx_msg_struct));

      Serial.println(rx_msg_struct.device_name);
    }
  }
}

```

Slave code

```arduino
HardwareSerial CommSerial(2);

const int SLAVE_RX_PIN = 16;
const int SLAVE_TX_PIN = 17;

unsigned long last_ms = 0;
const int interval_ms = 1000;

typedef struct struct_message {
  byte command;
  char device_name[50];
} struct_message;

void setup() {
  Serial.begin(9600);
  CommSerial.begin(9600, SERIAL_8N1, SLAVE_RX_PIN, SLAVE_TX_PIN);
}

void loop(){ 
  if (millis() - last_ms > interval_ms) {
    last_ms = millis();

    CommSerial.println("Slave -> hello");
  }

  handleBTIncomingDate();
}

void SendBTCommands(byte cmd, const char* name) {
  struct_message myMessage;
  myMessage.command = cmd;
  strcpy(myMessage.device_name, name);

  CommSerial.write((byte*)&myMessage, sizeof(myMessage));
}

void handleBTIncomingDate() {
  if (CommSerial.available()) {
    struct_message rx_msg_struct;

    uint8_t incomingData[sizeof(rx_msg_struct)];
    size_t rx_msg_length;

    rx_msg_length = CommSerial.readBytesUntil('\n', incomingData, sizeof(incomingData));

    if (rx_msg_length == sizeof(incomingData)) { // got a msg from a sensor
      memcpy(&rx_msg_struct, incomingData, sizeof(rx_msg_struct));

      Serial.println(rx_msg_struct.device_name);
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![BitSeeker](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/bitseeker/32/1241632_2.png) [@BitSeeker](https://forum.arduino.cc/u/BitSeeker)\
**Post date:** [September 16, 2025, 2:52pm UTC](https://forum.arduino.cc/t/esp32-inter-chip-serial-communication/1406489/2 "2025-09-16T14:52:23Z")

</div>

The `memcpy` function does not null terminate a character sequence and the buffer is not initialised. You also presumably should be copying to the character buffer i.e. to `rx_mgs_struct.device_name`, rather then the struct itself.

Initialise the message buffer to null.

```arduino
memset(rx_msg_struct.device_name, 0, sizeof(rx_msg_struct.device_name));

```

Use strncpy or strlcpy to copy the incoming data.

> [@dinesha77](#):
>
> `if (rx_msg_length == sizeof(incomingData))`

The length needs to be `sizeof(incomingData) - 1` to accomodate the NULL terminator. Your message cannot be longer than 49 characters + NULL.

---

<div class="post-metadata">

**Author:** ![dinesha77](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/dinesha77/32/1100172_2.png) [@dinesha77](https://forum.arduino.cc/u/dinesha77)\
**Post date:** [September 17, 2025, 3:05am UTC](https://forum.arduino.cc/t/esp32-inter-chip-serial-communication/1406489/3 "2025-09-17T03:05:58Z")

</div>

Thank you for your reply,

however I am confused as to where I should correct my code.

---

<div class="post-metadata">

**Author:** ![dinesha77](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/dinesha77/32/1100172_2.png) [@dinesha77](https://forum.arduino.cc/u/dinesha77)\
**Post date:** [September 17, 2025, 3:53am UTC](https://forum.arduino.cc/t/esp32-inter-chip-serial-communication/1406489/4 "2025-09-17T03:53:27Z")

</div>

There was a small mistake in my slave side code. I wasn’t using the SendBTCommands() function to send the message, which I corrected as show below.

wrong code:

```arduino
void loop(){ 
  if (millis() - last_ms > interval_ms) {
    last_ms = millis();

    CommSerial.println("Slave -> hello");
  }

  handleBTIncomingDate();
}

```

corrected code:

```arduino
void loop(){ 
  if (millis() - last_ms > interval_ms) {
    last_ms = millis();

    SendBTCommands(1, "Slave -> hello");
  }

  handleBTIncomingDate();
}

```

However, it still didn’t give me the outputs as I expected. meaning I did not see a fullduplext communication between the board visually on both the serial monitors.

So just test I changed the delay on the slave side of the code. Both had 1 second delay, I increased the slave to 2 seconds.

```arduino
const int interval_ms = 2000;

```

And now I can visually see both boards are communicating. And the above changes are all I did to my originally posted codes.

master monitor. See the 2 seconds gap as per the delay change. previously, I did not see anything here.

 ![image](https://europe1.discourse-cdn.com/arduino/original/4X/5/9/4/594dffcbf3eaac5af670cc54f9c51ba3237fb7f3.png)

slave monitor. 1 second messages.

 ![image](https://europe1.discourse-cdn.com/arduino/original/4X/0/b/b/0bb30c25f87a4df51668bb4c05f695fe43aa962b.png)

so, can I prasume that, hardware serial is NOT full duplex?

Or my understanding of the serial communication is wrong.

Thanks.

---

<div class="post-metadata">

**Author:** ![cattledog](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/cattledog/32/217816_2.png) [@cattledog](https://forum.arduino.cc/u/cattledog)\
**Post date:** [September 17, 2025, 4:21am UTC](https://forum.arduino.cc/t/esp32-inter-chip-serial-communication/1406489/5 "2025-09-17T04:21:09Z")

</div>

> [@dinesha77](#):
>
> `CommSerial.readBytesUntil('\n', incomingData, sizeof(incomingData));`

I think you are not terminating the message in the struct and you are seeing a timeout.

`CommSerial.println("Slave -> hello");`

.println will add the termination expected.

Try

```arduino
SendBTCommands(1, "Slave -> hello\n");

```

> [@dinesha77](#):
>
> so, can I prasume that, hardware serial is NOT full duplex?

All the documentation I see says that Serial2 is full duplex.

---

<div class="post-metadata">

**Author:** ![Deva\_Rishi](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/deva_rishi/32/227254_2.png) [@Deva\_Rishi](https://forum.arduino.cc/u/Deva_Rishi)\
**Post date:** [September 17, 2025, 10:38am UTC](https://forum.arduino.cc/t/esp32-inter-chip-serial-communication/1406489/6 "2025-09-17T10:38:11Z")

</div>

> [@dinesha77](#):
>
> I'm trying to connect two ESP32 DOIT DevKit V1 boards (AliExpress) through a serial connection. My intention is for the master board to send a command over serial to the slave board, which would then start its Bluetooth functionality. This would allow a device to connect and stream audio to an external DAC via I2S.

You are aware that the ESP32 has 2 cores that can be used individually. I don't think you need 2 boards.

> [@dinesha77](#):
>
> so, can I prasume that, hardware serial is NOT full duplex?

hwSerial is full-duplex.

> [@dinesha77](#):
>
> Or my understanding of the serial communication is wrong.

That is possible. What are the complete recent codes you are using.

---

<div class="post-metadata">

**Author:** ![dinesha77](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/dinesha77/32/1100172_2.png) [@dinesha77](https://forum.arduino.cc/u/dinesha77)\
**Post date:** [September 17, 2025, 4:53pm UTC](https://forum.arduino.cc/t/esp32-inter-chip-serial-communication/1406489/7 "2025-09-17T16:53:11Z")

</div>

> [@Deva\_Rishi](#):
>
> You are aware that the ESP32 has 2 cores that can be used individually. I don't think you need 2 boards.

Yes sir, but the issue is that as soon as I use the libraries, the sketch becomes huge, more than the available memory in the board.

```arduino
#include "AudioTools.h"
#include "BluetoothA2DPSink.h"

```

---

<div class="post-metadata">

**Author:** ![dinesha77](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/dinesha77/32/1100172_2.png) [@dinesha77](https://forum.arduino.cc/u/dinesha77)\
**Post date:** [September 17, 2025, 4:53pm UTC](https://forum.arduino.cc/t/esp32-inter-chip-serial-communication/1406489/8 "2025-09-17T16:53:49Z")

</div>

> [@cattledog](#):
>
> `CommSerial.println("Slave -> hello");`
> 
> .println will add the termination expected.
> 
> Try

thanks sir, but didn’t work for me.

---

<div class="post-metadata">

**Author:** ![horace](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/horace/32/1014299_2.png) [@horace](https://forum.arduino.cc/u/horace)\
**Post date:** [September 17, 2025, 7:01pm UTC](https://forum.arduino.cc/t/esp32-inter-chip-serial-communication/1406489/9 "2025-09-17T19:01:02Z")

</div>

> [@dinesha77](#):
>
> sketch becomes huge, more than the available memory in the board.

some libraries are certainly very large, e.g. BLE  
you can increase the available flash by using _Tools\>Partition Scheme_ and selecting _Hugh APP_

---

<div class="post-metadata">

**Author:** ![dinesha77](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/dinesha77/32/1100172_2.png) [@dinesha77](https://forum.arduino.cc/u/dinesha77)\
**Post date:** [September 17, 2025, 10:48pm UTC](https://forum.arduino.cc/t/esp32-inter-chip-serial-communication/1406489/10 "2025-09-17T22:48:37Z")

</div>

> [@horace](#):
>
> you can increase the available flash by using _Tools\>Partition Scheme_ and selecting _Hugh APP_

did that already with Huge App partition scheme, but still it was way above the available memory size.

---

<div class="post-metadata">

**Author:** ![horace](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/horace/32/1014299_2.png) [@horace](https://forum.arduino.cc/u/horace)\
**Post date:** [September 18, 2025, 5:57am UTC](https://forum.arduino.cc/t/esp32-inter-chip-serial-communication/1406489/11 "2025-09-18T05:57:28Z")

</div>

> [@dinesha77](#):
>
> did that already with Huge App partition scheme, but still it was way above the available memory size.

interesting - I have implemented projects using Hugh APP on ESP32 microcontrollers using WiFi, BLE and LoRaWAN plus various sensors and other IO devices without problems  
perhaps we need more details of the project?  
if it is too large for ESP32 microcontrollers you may need to move to something an order of magnitude more powerful, e.g. Raspberry Pi 5

---

<div class="post-metadata">

**Author:** ![cattledog](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/cattledog/32/217816_2.png) [@cattledog](https://forum.arduino.cc/u/cattledog)\
**Post date:** [September 19, 2025, 2:25am UTC](https://forum.arduino.cc/t/esp32-inter-chip-serial-communication/1406489/12 "2025-09-19T02:25:06Z")

</div>

```arduino
SendBTCommands(1, "Slave -> hello\n");

```

> thanks sir, but didn’t work for me.

For some reason the '\n' did not append correctly into the message in the struct.

With this modification to your code I am getting good bidirectional full duplex communication with a 100 ms period.

```arduino
const int interval_ms = 100;

```

```arduino
if (millis() - last_ms > interval_ms) {
    last_ms = millis();
    SendBTCommands(1, "Slave -> hello");
    CommSerial.write('\n');
  }

```

```arduino
if (millis() - last_ms > interval_ms) {
    last_ms = millis();

    SendBTCommands(1, "Master -> hello");
    CommSerial.write('\n');
  }

```

```arduino
Slave Print Out

19:02:30.053 -> Master -> hello
19:02:30.147 -> Master -> hello
19:02:30.243 -> Master -> hello
19:02:30.338 -> Master -> hello
19:02:30.433 -> Master -> hello
19:02:30.576 -> Master -> hello
19:02:30.670 -> Master -> hello
19:02:30.766 -> Master -> hello
19:02:30.861 -> Master -> hello
19:02:31.003 -> Master -> hello
19:02:31.094 -> Master -> hello
19:02:31.188 -> Master -> hello
19:02:31.283 -> Master -> hello
19:02:31.426 -> Master -> hello
19:02:31.521 -> Master -> hello
19:02:31.617 -> Master -> hello
19:02:31.712 -> Master -> hello
19:02:31.854 -> Master -> hello
19:02:31.949 -> Master -> hello

```

```arduino
Master Print Out

19:02:30.087 -> Slave -> hello
19:02:30.179 -> Slave -> hello
19:02:30.274 -> Slave -> hello
19:02:30.417 -> Slave -> hello
19:02:30.512 -> Slave -> hello
19:02:30.607 -> Slave -> hello
19:02:30.703 -> Slave -> hello
19:02:30.845 -> Slave -> hello
19:02:30.940 -> Slave -> hello
19:02:31.031 -> Slave -> hello
19:02:31.125 -> Slave -> hello
19:02:31.267 -> Slave -> hello
19:02:31.362 -> Slave -> hello
19:02:31.457 -> Slave -> hello
19:02:31.552 -> Slave -> hello
19:02:31.696 -> Slave -> hello
19:02:31.791 -> Slave -> hello
19:02:31.886 -> Slave -> hello
19:02:31.981 -> Slave -> hello

```

---

<div class="post-metadata">

**Author:** ![system](https://dub1.discourse-cdn.com/arduino/user_avatar/forum.arduino.cc/system/32/1140315_2.png) [@system](https://forum.arduino.cc/u/system)\
**Post date:** [March 18, 2026, 2:25am UTC](https://forum.arduino.cc/t/esp32-inter-chip-serial-communication/1406489/13 "2026-03-18T02:25:25Z")

</div>

Closed on March 18, 2026, 2:25am UTC

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.
