Untitled

 avatar
unknown
plain_text
3 years ago
952 B
5
Indexable
/*
 * HardwareSerial Example1
 */

/* ESP32 GPOI Pin 16 is RX 
 * ESP32 GPOI Pin 17 is TX
 * These two pins are UART2 which can be used. UART0 and UART1 with their respetive pins (RX and TX) cannot be used.
 * Any other pins can used for UART2, but they need to be declared. 
 * UART2 uses Serial2
*/

//Declaring UART2 Pins for HardwareSerial use
#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);
  //Serial1.begin(9600, SERIAL_8N1, RXD2, TXD2);  //We are not using UART1 which goes with Serial1
  Serial2.begin(9600, SERIAL_8N1, RXD2, TXD2);
  Serial.println("Serial Txd is on pin: "+String(TX));
  Serial.println("Serial Rxd is on pin: "+String(RX));
}

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