Using ESP8266 WiFi Shield with Arduino Microcontrollers

I am using the “ESP8266_Shield_Demo” sketch directly from Sparkfun’s library download.

  • I mounted the shield onto an UNO and the sketch worked perfectly.
  • I mounted the same shield onto an Arduino MEGA 2560 and ran the exact same sketch (changed the Board to MEGA and the port number used) in the Arduino IDE. Errorsa displayed in the Serial Monitor are:

Press any key to begin.

Error talking to ESP8266.

Error talking to ESP8266.

Error talking to ESP8266.

Error talking to ESP8266.

Error talking to ESP8266.

Error talking to ESP8266.

Error talking to ESP8266.

Error talking to ESP8266.

Error talking to ESP8266.

Error talking to ESP8266.

Error talking to ESP8266.

Error talking to ESP8266.


which tells me the error occurs in the following code:

void initializeESP8266()

{

// esp8266.begin() verifies that the ESP8266 is operational

// and sets it up for the rest of the sketch.

// It returns either true or false – indicating whether

// communication was successul or not.

// true

int test = esp8266.begin();

while( test == 0)

{

Serial.println(F(“Error talking to ESP8266.”));

delay(250);

test = esp8266.begin();

}

Serial.println(F(“ESP8266 Shield Present”));

}

Shield is set to use SoftwareSerial!

I need to get the Arduino MEGA (or something equivalent memory-wise and processing power-wise) to work with this shield for my Weather Station.

Any suggestions or is there something I forgot when going from UNO to MEGA?

Hello Professor.

The Mega isn’t capable of software serial RX on the pin the shield uses. You’d need to switch RX to a pin that is RX capable on the Mega and then alter your code and library to use that pin. The [Arduino Software Serial Reference has a list of pins that will work. :-)](https://www.arduino.cc/en/Reference/softwareSerial)

Thank you. I will try that.

Hi,

I am using Pin 10 for RX and Pin 11 for TX on the Mega. I have disconnected the WiFi shield’s RX and TX pins from the Mega. I used jumper cables to connect Mega pins 10 and 11 to the shield’s RX and TX pins. I am running the same sketch, having changed the Software Serial RX and TX pins to 10 & 11. I have tried switching the Mega RX jumper to the shield’s TX pin and vice versa for the Mega’s TX pin.

None of these changes and attempt have changed the outcome. Same error messages as before.

I cannot use the Red Card because my sketch requires more memory than available on the Red Card. I am using the Sparkfun Weather Shield on top of the WiFi Shield.

Any suggestions? Thank you.

Hi Professor.

I’d advise testing the shield on an Arduino Uno or [SparkFun RedBoard first and use our example sketch ESP8266_Shield_Demo to verify you have things working first.

The library hard codes the software serial pins to D8 and D9 so you’d need to modify the library to make the shield work with a Mega. the SparkFunESP8266WiFi.h file is where you need to make edits in the Pin Definitions section to get the code talking to the shield on the new pair of pins.](SparkFun RedBoard Qwiic - DEV-15123 - SparkFun Electronics)