0

I have two boards, Uno and ESP32 and my goal is to send data from the Uno to the ESP. I made a voltage divider so my ESP doesn't get fried and I use the communication only in ONE way, strictly UNO -> ESP32. I use PIN 9 from my UNO to send data and RX2 (16) from my ESP to receive the data. How ever, I get errors and can't make it work.

This is my Uno code:

#include <SoftwareSerial.h>

SoftwareSerial softPort(-1, 9);

void setup() {
Serial.begin(9600);
softPort.begin(9600);
}

void loop() {
softPort.print("100");
delay(2000);

}

and my ESP code:

#include <SoftwareSerial.h>

#define RXD2 16
#define TXD2 -1

SoftwareSerial Serial2(RXD2, TXD2); // RX, TX

void setup() {
Serial.begin(115200);
Serial2.begin(9600, SERIAL_8N1, RXD2, TXD2);

}

void loop() {
Serial.println("Data received:");
Serial.println(Serial2.read());
delay(200);

}

I'm getting an error that says

no matching function for call to 'SoftwareSerial::begin(int, int, int, int)'

1
  • Um.... why would you use SoftwareSerial on the ESP32 to access the secondary hardware UART?
    – Majenko
    Aug 11 '20 at 15:04
0

On the ESP32 you would never use SoftwareSerial except under exceptional circumstances.

The ESP32 has three hardware UARTs that can be mapped to any pin combination on the board.

The general usage is:

HardwareSerial Serial2(1); // Use UART channel 1

void setup() {
    Serial2.begin(9600, SERIAL_8N1, RXD2, TXD2);
}

UARTs are numbered 0-2 where 0 is pre-assigned to the TX/RX (USB connection) pins and is used for debugging and programming. UARTs 1 and 2 are not normally assigned to anywhere and you can use them as you see fit.

4
  • Thank you for the answer sir. One question, in Serial2(1), 1 stands for RX1 and TX1? In my case, where I use RX2 and TX2, do I have to useSerial2(2)? And do I have to change my wiring in order to use HardwareSerial? This is my wiring right now: i.imgur.com/KvIZQdx.png @Majenko Aug 11 '20 at 18:47
  • No. 1 stands for UART 1. Where you connect it to is up to you. The UARTs don't have any standard pins (except UART 0 for the bootloader). It's only when you call begin() that you tell it which pins to use. Until then it has no pins. RX1 and TX1 are just labels that coincide with the bootloader / debug pins. You could use 1 or 2 in the constructor and it will make no difference - it'll just be using a different UART module inside the chip.
    – Majenko
    Aug 11 '20 at 18:51
  • I get it now, thank you once again and sorry for my ignorance :) Lastly, can you please confirm if my wiring is correct and if I can use it for HardwareSerial? Aug 11 '20 at 18:54
  • GPIO3 is the default for UART0 RX. That's the bootloader / USB connection on most boards. You should pick something else. Not one of the RTC pins though. Anything between 13 and 33 are good choices.
    – Majenko
    Aug 11 '20 at 18:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.