but I used mega2560 and the TX RX ports I used were 18 and 19.... I added to Arduino a 12v 2A power supply to ensure enough power to this module.
#include <WiFiEspAT.h>
// Emulate Serial1 on pins 6/7 if not present
#if defined(ARDUINO_ARCH_AVR) && !defined(HAVE_HWSERIAL1)
#include <SoftwareSerial.h>
SoftwareSerial Serial1(19, 18); // RX, TX
#define AT_BAUD_RATE 9600
#else
#define AT_BAUD_RATE 115200
#endif
const char *server = "arduino.cc";
WiFiClient client;
void setup()
{
Serial.begin(115200);
while (!Serial)
;
Serial1.begin(AT_BAUD_RATE);
WiFi.init(Serial1);
if (WiFi.status() == WL_NO_MODULE)
{
Serial.println();
Serial.println("Communication with WiFi module failed!");
// don't continue
while (true)
;
}
// waiting for connection to Wifi network set with the SetupWiFiConnection sketch
Serial.println("Waiting for connection to WiFi");
while (WiFi.status() != WL_CONNECTED)
{
delay(1000);
Serial.print('.');
}
Serial.println();
Serial.println("Connected to WiFi network.");
Serial.println("Starting connection to server...");
if (client.connect(server, 80))
{
Serial.println("connected to server");
client.println("GET /asciilogo.txt HTTP/1.1");
client.print("Host: ");
client.println(server);
client.println("Connection: close");
client.println();
client.flush();
}
}
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)
;
}
}
This is my last try... I can upload the code without error, but it always fails to connect to this module. I'm stuck and I need any help or suggestions.
As indicated in previous replies, why does you wiring diagram show the ESP connected to pins 0 and 1 while using Serial1 on the Mega?
Your topic has been moved to a more suitable location on the forum. Installation and Troubleshooting is not for problems with (nor for advise on) your project See About the Installation & Troubleshooting category.
The voltage regulators have to drop this to 5volt for the Mega and 3.3volt for the ESP8266.
That makes a 12volt supply a poor choice (too high), because most of it has to be burned off as heat.
Better to power the Mega with a 5volt cellphone charger, connected to the USB socket.
You must have a very good reason to try to join two processors.
Can't you use a WeMos D1 mini, or NodeMCU, or ESP32 board (no Mega).
If you must use this kludge, then add at least a 470uF/6.3volt buffer capacitor on the 3.3volt pin, to bridge the ~400mA transmit peaks of the ESP-01 (assuming). And a level shifter (1:2 voltage divider) on the TX line of the Mega, to prevent 5volt logic being rammed op the backside of a 3.3volt processor.
Leo..
Probably I haven't chosen a good modul, because it's just my second project on Arduino ... I just searched for a WiFi module and bought this one. I need only to send some measured data to my server. @anon57585045 Yes I'm using these serial ports 18 & 19 and I don't have any additional hardware. @Juraj My USB chip is ATmega16u2. Yesterday, I tried to measure the voltage with the adapter and it has a stable 3.3V and without it drops below 3V. @sterretje I tried several code examples and after it didn't work I tried to define these ports. Sorry for this scheme. I just found a picture similar to my connections.
Thanks for the image. That does clear up a few doubts. But it is not possible to verify the connections from that. Please provide a complete wiring diagram of the actual circuit in the image.
There is no fuss about making a diagram. Just include everything, label everything, use pen and paper and take a picture of the sheet.
Can you see how you've forced people to speculate?
Also it seems that you went back and edited your original post to look like some questions were already answered there. Please don't do that!
I didn't edit the original post, I saw the edit mark, but the text is still the same. This may have happened because the post was moved from the Installation and Troubleshooting section.
Right. So now you know where to look. Have you verified the baud rates? An incorrect baud rate will stop the show. How did you decide that the ESP is set to 9600?
A screen shot of an actual AT command being sent, would have been more useful. Your send line is blank. What did you send? Can we see the results?
Also, you goofed up the program. You have merely repeated the transmission in one direction only.