Serial Communication between Arduino series , ESP32 , ESP8266 etc pin discussion

Need to get some proper Pipelines on Serial Communication between various MCUs including voltage conversion and other parameters

So let's get in to it from a very basic start !!!

In the above image
We have here 38 pin ESP32 model which has 3 UART labelled, from which
The GPIO 1 & GPIO 3 got finalized for serial communication which is shown in the image below

Now suppose if we want to take GPIO 9 & GPIO 10 into the account for serial communication with Arduino boards like MEGA or UNO or NANO etc

So is that a good choice ???

Ref. YouTube Link is here from where I got the snapshot from above pic !!

the UNO uses 5V logic the ESP32 3.3V logic - you will require a potential divider on the UNO Tx to ESP32 Rx signal
why use a UNO and ESP32 - cannot you do the whole project on the ESP32?

Hm ya while surfing I just came to know about this divider or convertor thing and found it online for few bucks too :blush:

Ya that is important thing that why all these ??
So coming to this part
Here I have requirements to connect
An LCD of 16x4
A TM1637
2 or 3 DF Players
A set of some 24

Well Sir
Other than all the discussions above, coming to the actual query
Can we finalize GPIO 9 & GPIO 10 for serial communication between ESP32 & Arduino via level shifter???

No issues with that ??

Please comment !!! :slight_smile:

Try this:

No, don't use gpio9/10 ( see here why )

OK le me go through this one !!!

Ya I am not applying that

So what if I try to establish a serial communication in between the ESP8266 and ESP32 ?

I mean without a level shifter is it possible directly ??

You can do the testing, but for production, using a level shifter is recommended. Otherwise, you could burn the esp32.

yes - both use 3.3V logic no requirement for a level shifter
With ESP32 use hardware serial with ESP8266 use EspSoftwareSerial
UNO to either ESP32 or ESP8266 use level shifter or a potential divider on UNO Tx to ESP Rx

ya this one is already installed

IDE is also saying that thing , I just checked

So now can i just connect TX with RX and RX with TX of both ESP32 and ESP8266 ?

on the ESP32 U0UXD is used to communicate with the ESP32 for programming and during reset/boot. U1UXD and U2UXD hardware serial ports are available for user projects

At boot, ESP8266 Serial uses UART0, which is mapped to pins GPIO1 (TX) and GPIO3 (RX).
UART1 is not easy to access so EspSoftwareSerial can be used, e.g. a simple program using EspSoftwareSerial

// ESP8266 EspSoftware Serial test

// At boot, Serial uses UART0, which is mapped to pins GPIO1 (TX) and GPIO3 (RX).

// using library manager download and instal EspSoftwareSerial or instal ZIP
// https://github.com/plerup/espsoftwareserial

#include <SoftwareSerial.h>

// pins Rx GPIO14 (D5) and Tx GPIO 12 (D6) 
 SoftwareSerial swSer(14, 12);  

 // for loopback test connect pin D5 to pin D6

// for RS232 shield connect
// ESP8266 pin D6 TXD to TTL/RS232 Tx
// ESP8266 pin D5 RXD to TTL/RS232 Rx
// for loopback test connect 9-pin D_type connector pins 2 Tx to 3 Rx (pin 5 is GND)
// connect GND pins together and VCC to 5V

void setup() {
  Serial.begin(115200);   //Initialize hardware serial with baudrate of 115200
  swSer.begin(9600);      //Initialize software serial with baudrate of 9600
  Serial.println("\nESP8266 Software serial test started");
  Serial.println("-  for loopback test connect pin D5 to pin D6\n");
 }

void loop() {
  while (swSer.available() > 0) {  //wait for data at software serial
    Serial.write(swSer.read()); //Send data recived from software serial to hardware serial    
  }
  while (Serial.available() > 0) { //wait for data at hardware serial
    swSer.write(Serial.read());     //send data recived from hardware serial to software serial
  }
}

similar program for ESP32

// ESP32  Serial1 test - for loopback test connect pins RXD1 and TXD1

#define RXD1 16 // can map Serial1 and Serial2 to many ESP32 GPIO pins
#define TXD1 17 // check pin usage https://randomnerdtutorials.com/esp32-pinout-reference-gpios/

// for RS232 shield connect
// ESP32 RXD1 to TTL/RS232 Rx
// ESP32 TXD1 to TTL/RS232 Tx
// connect GND pins together and VCC to 3.3V on ESP32 5V on UNO ect
// for loopback test connect 9-pin D_type connector pins 2 Tx to 3 Rx (pin 5 is GND)

void setup() {
  // initialize both serial ports:
  Serial.begin(115200);
  Serial1.begin(115200, SERIAL_8N1, RXD1, TXD1);
  Serial.printf("\n\nESP32 serial1  test RXD1 pin %d TXD1 pin %d\n", RXD1, TXD1);
  Serial.printf(" loopback test connect pin %d to pin %d\n", RXD1, TXD1);
  Serial.printf("RS232: ESP32 pin %d RXD1 to TTL/RS232 Rx and pin %d TXD1 to TTL/RS232 Tx\n", RXD1, TXD1);
  Serial.printf("RS232 - loopback connect 9-pin D-type pin 2 Tx to pin 3 Rx\n");
}

void loop() {
  // read from Serial1, send to Serial
  if (Serial1.available()) {
    int inByte = Serial1.read();
    Serial.write(inByte);
  }
  // read from Serial, send to Serial1
  if (Serial.available()) {
    int inByte = Serial.read();
    //Serial.write(inByte);     // local echo if required
    Serial1.write(inByte);
  }
}

try connecting (make sure baudrates are identical)
ESP32 RXD1 pin 16 to ESP8266 Tx GPIO 12 (D6)
ESP32 TXD1 pin 17 to ESP8266 Rx GPIO14 (D5)

text entered on ESP32 serial monitor should appear on the ESP8266 display etc

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