ESP32 - SoftwareSerial Library

20,153

Solution 1

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

Solution 2

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".

Share:
20,153

Related videos on Youtube

James Burgess
Author by

James Burgess

Updated on July 05, 2022

Comments

  • James Burgess
    James Burgess almost 2 years

    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

    • Juraj
      Juraj over 4 years
      the esp32 arduino boards package doesn't have a SoftwaeSerial library bundled. try EspSoftwareSerial library. install it in Library Manager
  • Admin
    Admin almost 4 years
    Thank You for ask my question.
  • Admin
    Admin almost 4 years
    Thank You for ask my question.
  • mehmet
    mehmet over 2 years
    Well I think ESP32 has only 1 usable Hardware Serial (Serial2)
  • Adriano
    Adriano over 2 years
    @mehmet UART = Serial. GPIO1,3,9 and 10 are not "virtual pins", but hardware pins. The ESP has 3 independent UARTs. You are free to configure the pin by yourself, but it remains a hardware UART.