ESP32 serial port forwarding implementation (Arduino)

Let's first look at the pin diagram
insert image description here
of the ESP32 development board. Here we use UART 2 as a serial port to communicate with the MCU ( TX : GPIO17, RX : GPIO16). The Arduino code is as follows:

void setup() {
    
    
  Serial.begin(115200);
  Serial2.begin(115200);
}

void loop() {
    
    
  if (Serial2.available()) {
    
    
    int inByte = Serial2.read();
    Serial.write(inByte);
  }

  if (Serial.available()) {
    
    
    int inByte = Serial.read();
    Serial2.write(inByte);
  }
}

Guess you like

Origin blog.csdn.net/Cloud_1234_5678/article/details/112237057