4

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

James Burgess
  • 487
  • 1
  • 4
  • 12
  • the esp32 arduino boards package doesn't have a SoftwaeSerial library bundled. try EspSoftwareSerial library. install it in Library Manager – Juraj Feb 06 '20 at 12:19

2 Answers2

11

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

Adriano
  • 1,743
  • 15
  • 28
  • Thank You for ask my question. –  Jul 07 '20 at 20:48
  • Well I think ESP32 has only 1 usable Hardware Serial (Serial2) – mehmet Feb 19 '22 at 14:08
  • @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. – Adriano Feb 21 '22 at 09:11
3

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

matheusrfd
  • 31
  • 2