简体   繁体   中英

ESP32 - SoftwareSerial Livrary

I have a ESP32 and I need to work with more serial ports, but I can't be using the Software Serial Library into ESP32, because the Arduino IDE don't recognize the library.

How could I be using it?

   #include <Arduino.h>
   #include <SoftwareSerial.h>

   SoftwareSerial SoftSerial(4, 5);

   void setup() 
   {
     Serial.begin(9600);
     SoftSerial.begin(115200); 
   }

   void loop() 
   {
     while (Serial.available())
     {
       SoftSerial.write("on");
     }
   }

Thank You

The ESP32 has 3 different Serial Ports (UART). You can just use one of them:

Serial0: RX0 on GPIO3, TX0 on GPIO1
Serial1: RX1 on GPIO9, TX1 on GPIO10 (+CTS1 and RTS1)
Serial2: RX2 on GPIO16, TX2 on GPIO17 (+CTS2 and RTS2)

You don't need the Software Serial Port, since the ESP32 can unconfigurate internally the Serial port pin to other pins.

To do that, you need to use the <HardwareSerial.h> - library

This library is already installed with your board:
https://github.com/espressif/arduino-esp32/blob/master/cores/esp32/HardwareSerial.cpp

Edit: As said by Juraj, if you need more than 3 serial ports, you can use this library for the ESP:
https://github.com/plerup/espsoftwareserial

You may want to use EspSoftwareSerial library available in this repository .

If you are using the Arduino IDE, install the library by clicking the "Sketch" menu, "Include Library" and then "Manage Libraries".

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM