Reasons for use: When using GPS, ESP32 needs to receive the serial port data of the GPS module from the serial port
Second serial port position: (marked as TX2 and RX2)
code:
String rev;
void setup() {
Serial.begin(115200);//这个是esp32与电脑的串口波特率
Serial2.begin(9600);//这个是esp32与其他模块的连接时的波特率(写的是其他模块的波特率)
}
void loop() {
//读到\n为止,然后结束缓冲区读取
rev=Serial2.readStringUntil('\n');
//数据打印
Serial.println(rev);
}
Similarly, if you want to output data to other modules, you can use:
Serial2.println();//或者.print();
Finally, attach the Arduino online simulation platform
https://wokwi.com/