Connecting to Wi-fi using ESP8266

Hi!
I’m trying to connect my Wifi module ESP8266 to wi-fi. The module is plugged into my Arduino Uno and this is the code that I’ve used for trying to connect, but all I’m getting is mirrored question marks in the serial monitor. What am I doing wrong?:

#include “WiFiEsp.h”

#ifndef HAVE_HWSERIAL1
#include “SoftwareSerial.h”
SoftwareSerial Serial1(5, 6); // RX, TX
#endif

char ssid = “xxx”; // your network SSID (name)
char pass = “xxx”; // your network password
int status = WL_IDLE_STATUS; // the Wifi radio’s status

#include <WiFiEsp.h>

//************************

void setup()
{
// initialize serial for debugging
Serial.begin(115200);
// initialize ESP module
WiFi.init(&Serial);

// check for the presence of the shield
if (WiFi.status() == WL_NO_SHIELD) {
// don’t continue
while (true);
}

// attempt to connect to WiFi network
while ( status != WL_CONNECTED) {
Serial.print("Attempting to connect to WPA SSID: ");
Serial.println(ssid);
// Connect to WPA/WPA2 network
status = WiFi.begin(ssid, pass);
Serial.print(status);
}

}

void loop()
{

}

is the esp module connected to serial or to softwareserial pins 5,6?
if it is connected to hw serial (0, 1) then you can't use serial monitor, because it is using the Serial

The WiFiEsp library is made to work at 9600 baud rate due to its timings, to change your esp,s baud rate connect rx to rx , tx to tx using pins 0 and 1 on the arduino, then open the serial monitor at 115200 and type AT you should get the responce “OK”, then type AT+UART_DEF=9600,8,1,0,0 and change the serial monitor rate to 9600 and type AT again you should see “OK” again. now connect to pin “6 and 7” on the arduino via tx to rx and rx and tx. and try the WiFiEsp example WebClient sketch with your routers ssid and password.

Note you must use your routers 2g network, as the esp8266 does not support 5g.

Just as a note your code is wrong, regarding your Serial setup. I fixed it for you:

#include "WiFiEsp.h"

#ifndef HAVE_HWSERIAL1
#include "SoftwareSerial.h"
SoftwareSerial Serial1(5, 6); // RX, TX i use 6 -7 on a Uno but 5 -6 is fine
#endif

char ssid[] = "xxx";            // your network SSID (name) 
char pass[] = "xxx";        // your network password
int status = WL_IDLE_STATUS;     // the Wifi radio's status

#include <WiFiEsp.h>

//************************

void setup()
{
  // initialize serial for debugging
  Serial.begin(115200);  // FOR Serial debugging only not esp
  Serial1.begin(9600);  // Serial for ESP8266 on pins set above - Note its Serial1 < see the 1
  // initialize ESP module
  WiFi.init(&Serial1); // Serial1 !

  // check for the presence of the shield
  if (WiFi.status() == WL_NO_SHIELD) {
    // don't continue
    while (true);
  }

  // attempt to connect to WiFi network
  while ( status != WL_CONNECTED) {
    Serial.print("Attempting to connect to WPA SSID: "); // Print title to serial monitor
    Serial.println(ssid); // print SSID
    // Connect to WPA/WPA2 network
    status = WiFi.begin(ssid, pass); // connect to router - network 
    Serial.print(status); // print connection status 
  }
  
}

void loop()
{

}

KawasakiZx10r:
The WiFiEsp library is made to work at 9600 baud

the limit is for the SoftwareSerial, not for the WiFiEsp library

I’m aware that this is an older post, but there came never a formal answer.

I struggled with the same issue and find a solution on an other forum.

The problem: You want to use an Arduino uno or nano with an ESP-01, but you have no other I/O left to use! So the ESP-01 needs to be connected to PIN 0 & 1 by hardware serial. (TX & RX)

Note to the presented code: You are using serial as well as for debugging (text and status) as for communication with the ESP8266. (AT commands) The ESP8266 can’t handle the debugging information and is blocking there. By using two different serialnames but defining as the same (see below) you can choose which one you would like to write on the hardware serial pins.

The solution:
“I would recommend you to use this library:

It’s very good and does support software as hardware serial but unfortunately the author insists on leaving debug output turned on, which prints to Serial. Since the ESP8266 is also connected to the Serial pins (PIN 0 & 1) this causes the library to not work unless you make the following change in your library file debug.h: (Use notepad / Notepad++ to open the *.h file)
Logging disabled by default by per1234 · Pull Request #46 · bportaluri/WiFiEsp · GitHub

Furthermore you need to comment the software serial definition and the serial (debugging) communication and define serial1 as serial in your sketch.

#define Serial1 Serial
/*
#ifndef HAVE_HWSERIAL1
#include "SoftwareSerial.h"
SoftwareSerial Serial1(1, 0); // RX, TX
#endif*/

void setup() {
//Serial.begin(115200);
Serial1.begin(115200);  //YES HARDWARE SERIAL AT 115200 IS NOW USEABLE!

Finally and important you need to upload the sketch to the Arduino without the ESP-01 RX & TX connected!