I have some problem with esp8266 module or SoftwareSerial

Hello everyone.

Before saying my problem, I'm using Arduino MEGA ADK and IDE 1.8.16.
I'm trying to test wi-fi module that uses esp8266 and esp-01 adapter. I connected wires each of one is from RX to port 10, and another one is from TX to port 11.
And the following is code.

#include <SoftwareSerial.h>

int wifiTx = 11;
int wifiRx = 10;

SoftwareSerial mySerial(wifiRx, wifiTx);

void setup() {
  Serial.begin(9600);
  Serial.println("hello");
  mySerial.begin(9600);
}

void loop() {
  // put your main code here, to run repeatedly:
  
  if (mySerial.available()) {
    Serial.write(mySerial.read());
    
  }
  if (Serial.available()) {
    mySerial.write(Serial.read());

  }
}

When I opened Serial Monitor with baudrate on 9600 and put command 'AT', It printed like this,
stdin:1: unexpected symbol near '⸮'
So I think it must be baudrate problem, changed Serial and mySerial' rate to 115200, and put it again, but there is no response.
I've been thinking for hours, and I've tried changing the RX and TX ports or even changing the baudrate accompanying them, but I haven't found an answer.

What can I do? Please.

There are a few things.
Firstly, you are using a Mega, which has 4 UARTs (hwSerial ports) and you should use one of those instead of swSerial.
Secondly, you will need to make sure you do not exceed the 3.3v logic level of the ESP-01 on it's RX line using either a voltage divider or level shifter. Since you've swapped RX & TX to try and resolve your issue, it is possible you have damaged your ESP.
Most ESP-01s come with AT-firmware that runs at 115200, Since swSerial is not reliable for reception at 115200, normally one would first send the command to change the baudrate to 9600 on the ESP.
When using hwSerial, you will not have that issue.
Show us your circuit schematic.
Oh yes, and make sure that you have 'line ending' set to 'Both CR & LF' in the Serial monitor, or the ESP will not respond properly.

here it is.

That is Fritzing ! not a schematic, but it is clear that you have not protected your RX-pin (or TX-pin for that matter)
My bet is that the ESP is not working properly anymore, with the TX in OUTPUT mode and 5v applied, it will almost certainly be damaged, but you may be lucky.
Anyway, i suggest you connect the Huzzah to Serial 1, cross TX & RX (Mega-TX to ESP-RX and vice versa) and add a voltage divider on the ESPs RX line. I use 3x 1K resistor from the Mega-TX to GND, and connect the ESP-RX between the first and second resistor (starting counting at Mega-TX) that way the 5v logic level will be reduced to 3.3333v which is well within the safe range of the ESP. There are some ESP's that have 5v tolerant RX-pins, but i don't think that the Huzzah is one of them.

You must have started out with some kind of tutorial, can you post a link ?

In fact, this is part of the pdf that my instructor gave me. And I don't know how this module will work because I borrowed it, but according to your answer, it's highly likely that the circuit is broken. Next time, I'll ask the instructor. Thank you.

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.