I purchased two "Addicore" ESP8266 (ESP-01) modules from Amazon (link) a few years ago and am just now trying to see if I can get one of them to work with my Arduino Mega.
I first searched this forum for instructions/libraries/examples and in (this) thread, I was sent over to GitHub (here).
The README.md indicates that this library is for the ESP-01 module (which is what (I believe) I have).
I have installed (this) 3.3 <-> 5v logic level converter between the Arduino and the ESP8266.
My connections from the ESP8266 through the logic level converter to the Arduino are as follows:
Ground -> Ground (below pin53)
GPIO2 -> (not connected)
GPIO0 -> (not connected)
TX -> Serial1 RX (Pin7)
RX -> Serial1 TX (Pin6)
CH_PD -> 3.3v (via Pin38)
RST -> (not connected)
VCC -> 3.3v (via Pin38)
Here is my code:
/*
/*
WiFiEsp example: WebClient
This sketch connects to google website using an ESP8266 module to
perform a simple web search.
For more details see: http://yaab-arduino.blogspot.com/p/wifiesp-example-client.html
*/
#include "WiFiEsp.h"
// Emulate Serial1 on pins 6/7 if not present
#ifndef HAVE_HWSERIAL1
#include "SoftwareSerial.h"
SoftwareSerial Serial1(7, 6); // RX, TX
#endif
char ssid[] = "FBI Field Operations"; // your network SSID (name)
char pass[] = "5634Brier"; // your network password
int status = WL_IDLE_STATUS; // the Wifi radio's status
int wifiPower = 38;
char server[] = "arduino.cc";
// Initialize the Ethernet client object
WiFiEspClient client;
void setup()
{
// Take pin 38 "HIGH" to turn on WiFi module
pinMode(wifiPower, OUTPUT);
digitalWrite(wifiPower, HIGH);
// initialize serial for debugging
Serial.begin(115200);
// initialize serial for ESP module
Serial1.begin(9600);
// initialize ESP module
WiFi.init(&Serial1);
// check for the presence of the shield
if (WiFi.status() == WL_NO_SHIELD) {
Serial.println("WiFi shield not present");
// 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);
}
// you're connected now, so print out the data
Serial.println("You're connected to the network");
printWifiStatus();
Serial.println();
Serial.println("Starting connection to server...");
// if you get a connection, report back via serial
if (client.connect(server, 80)) {
Serial.println("Connected to server");
// Make a HTTP request
client.println("GET /asciilogo.txt HTTP/1.1");
client.println("Host: arduino.cc");
client.println("Connection: close");
client.println();
}
}
void loop()
{
// if there are incoming bytes available
// from the server, read them and print them
while (client.available()) {
char c = client.read();
Serial.write(c);
}
// if the server's disconnected, stop the client
if (!client.connected()) {
Serial.println();
Serial.println("Disconnecting from server...");
client.stop();
// do nothing forevermore
while (true);
}
}
void printWifiStatus()
{
// print the SSID of the network you're attached to
Serial.print("SSID: ");
Serial.println(WiFi.SSID());
// print your WiFi shield's IP address
IPAddress ip = WiFi.localIP();
Serial.print("IP Address: ");
Serial.println(ip);
// print the received signal strength
long rssi = WiFi.RSSI();
Serial.print("Signal strength (RSSI):");
Serial.print(rssi);
Serial.println(" dBm");
}
The code compiles fine with no errors.
The light on the Logic level converter is on (as expected).
The light (red) on the ESP8266 turns on as long as pin38 is set to "HIGH".
On the serial monitor when running the code, I am getting the following error(s):
[WiFiEsp] Initializing ESP module
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] Cannot initialize ESP module
[WiFiEsp] >>> TIMEOUT >>>
[WiFiEsp] No tag found
WiFi shield not present
I have tried the following:
- Changing the baud rate for Serial1 (ESP8266 TX/RX) (300, 1200, ... , 250000)
- Flipping the RX/TX pin assignment in my code
- Applying 3.3v to the RST pin (via Pin38)
Do you have any idea what I'm doing wrong?
PS - sorry that this post got so long - I wanted to add all the info and provide all of the answers to the obvious questions that will undoubtedly come...