Arduino and ESP32 cannot do 2-way communication at the same time?

Transfer data from ESP32 to Arduino Uno using UART - #51 by GigaNerdTheReckoning

Based on this answer, it says that Arduino and ESP32 cannot do 2-way communication at the same time cause it will do collision as software serial cannot handle simultaneous 2 way communication. Even if i used level shifter to convert 3,3v esp to 5v arduino, is it i still cannot do 2 way comms at the same time?

Note: My project is create Automatic AC based on Desired Temperature with IR transmitter. I used Arduino MEGA 2560 to do the proccessing and send the ir data (its just because esp32 cannot do ir transmit). Then Arduino MEGA 2560 will send some data to be uploaded by ESP32 to Blynk or ThingSpeak. Below is my hardware sequence:

*sorry for bad english, anyway its for college purpose

ESP-32 can send IR codes.

There is no reason to use SoftwareSerial with the Mega, as it has 4 hardware serial ports.

The ESP32 has 3, so it is entirely possible to have "simultaneous" two-way communications.

Even if i used level shifter to convert 3,3v esp to 5v arduino

If you even once connected the two without using a level shifter, you may have damaged one or both devices.

Can you tell me why? sorry i'm a beginner

because i was already do a serial communication to send data from arduino mega rx(0) tx(1) to esp32 rx2(16) tx2(17)

Very simple: manufacturer's device specifications. You MAY NOT connect a 3.3V input to a 5V source, or damage to one or both devices can be expected. The damage may not be enough to notice in the short term, but it can also be instantly fatal.

So, to do the comms simultaneously. I should do:

  1. Arduino rx(0) tx(1) Send to ESP32 rx2(16) tx2(17)
  2. ESP32 rx0 tx0 send to arduino rx1 tx1

Do i really need point no.2? or i can do it simultaneously by just using point no.1? Can you help me show the right way to code simultaneous two way comms?

@jremington

Any one of this two channels will.be enough.

Why do you need "simultaneous" exchange and what do you mean on it?
I recommended you to read a "Serial input basics" tutorial before you going further.

connection between Mega Serial 1 (pins 18 and 19) and ESP32 (pins 15 and 16)

note the potential divider to convert the Mega Tx 5V logic signal to a suitable level for the ESP32 3.3V logic - there no problem with the ESP32 3.3V Tx signal to the Mega RX

I don't understand what you "really" want to do. One two-way serial connection between two microprocessors should be enough.

Yes, If you're using a Mega and an ESP32, then both these MCU's have additional hardware ( full-duplex) serial UART ports. if available, HW ports should always be used over SW ports.

Therefore, you don't need to worry about my previous answer, as this involved the OP using a software serial ports (half-duplex) on the UNO.

In your case, you can communicate both ways simultaneously, without needing to program collision avoidance, as you have 2 full-duplex ports.

okay horace, thank you so much. I will try this connection

hey horace, im using esp32 dev module, i'll show u the pinout:

So, thats the pinout. should i use the gpio 16 and 15 as you said? or i should just use the 16 and 17 (rx2 ang tx2)? Cause i find different on your example board

I have used both 15 and 16 and 16 and 17 in various tests
this works using Serial2 (pins 16 and 17)

// ESP32 serial2 hardware loop back test - jumper GPIO16 (Rx) and GPIO17 (Tx)

// see https://circuits4you.com/2018/12/31/esp32-hardware-serial2-example/
/* There are three serial ports on the ESP known as U0UXD, U1UXD and U2UXD.
 * 
 * U0UXD is used to communicate with the ESP32 for programming and during reset/boot.
 * U1UXD is unused and can be used for your projects. Some boards use this port for SPI Flash access though
 * U2UXD is unused and can be used for your projects.
*/

#define RXD2 16
#define TXD2 17

void setup() {
  // Note the format for setting a serial port is as follows: Serial2.begin(baud-rate, protocol, RX pin, TX pin);
  Serial.begin(115200);
  Serial2.begin(115200, SERIAL_8N1, RXD2, TXD2);
  Serial.println("ESP32 hardware serial test on Serial2");
  Serial.println("Serial2 Txd is on pin: "+String(TXD2));
  Serial.println("Serial2 Rxd is on pin: "+String(RXD2));
}

void loop() { //Choose Serial1 or Serial2 as required
  while (Serial2.available()) {
    Serial.print(char(Serial2.read()));
  }
  while (Serial.available()) {
    Serial2.print(char(Serial.read()));
  }
}