Connecting ESP8266 with Arduino Mega 2560

Im trying to use de ESP8266WiFi.h with the arduino mega and it is alway returning the following error:

In file included from C:\Users\Márcia\Desktop\AAAAAAAAAAAAAAAAAA\AAAAAAAAAAAAAAAAAA.ino:33:0:
c:\Users\M�rcia\Documents\Arduino\libraries\ESP8266WiFi\src/ESP8266WiFi.h:28:10: fatal error: wl_definitions.h: No such file or directory
 #include <wl_definitions.h>
          ^~~~~~~~~~~~~~~~~~
compilation terminated.

exit status 1

Compilation error: exit status 1

Code:

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>

#ifndef APSSID
#define APSSID "aaaa"
#define APPSK "bbbb"
#endif

/* Set these to your desired credentials. */
const char *ssid = APSSID;
const char *password = APPSK;

ESP8266WebServer server(80);

/* Just a little test message.  Go to http://192.168.4.1 in a web browser
   connected to this access point to see it.
*/
void handleRoot() {
  server.send(200, "text/html", "<h1>You are connected</h1>");
}

void setup() {
  delay(1000);
  Serial.begin(115200);
  Serial.println();
  Serial.print("Configuring access point...");
  /* You can remove the password parameter if you want the AP to be open. */
  WiFi.softAP(ssid, password);

  IPAddress myIP = WiFi.softAPIP();
  Serial.print("AP IP address: ");
  Serial.println(myIP);
  server.on("/", handleRoot);
  server.begin();
  Serial.println("HTTP server started");
}

void loop() {
  server.handleClient();
}

It looks like you have some non-standard characters in your path - that could be a problem...

Presumably, that should be the same user path - yet it seems to have a different character in it? :thinking:

(might be a red herring - just a feature of the forum - but...)

oh it use special characters in path, but it dont cause any problem, i created other codes in the same computer and usually they work well

1 Like

Can you please describe in more words what exactly you are trying to do.

trying to compile ESP8266-code that shall run on the arduino-mega-2560 does not make sense.

ESP8266-code can only run on a ESP8266-microcontroller
Arduino-Mega-code can only run on a arduino-mega-controller

The code that you have posted I mean this one

#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>

#ifndef APSSID
#define APSSID "aaaa"
#define APPSK "bbbb"
#endif

/* Set these to your desired credentials. */
const char *ssid = APSSID;
const char *password = APPSK;

ESP8266WebServer server(80);

/* Just a little test message.  Go to http://192.168.4.1 in a web browser
   connected to this access point to see it.
*/
void handleRoot() {
  server.send(200, "text/html", "<h1>You are connected</h1>");
}

void setup() {
  delay(1000);
  Serial.begin(115200);
  Serial.println();
  Serial.print("Configuring access point...");
  /* You can remove the password parameter if you want the AP to be open. */
  WiFi.softAP(ssid, password);

  IPAddress myIP = WiFi.softAPIP();
  Serial.print("AP IP address: ");
  Serial.println(myIP);
  server.on("/", handleRoot);
  server.begin();
  Serial.println("HTTP server started");
}

void loop() {
  server.handleClient();
}

to what microcontroller is your arduino-IDE adjusted if you try to compile this code?

If your arduino-IDE is adjusted to board-type arduino-mega-2560
then of course this error will be shown because an Arduino-mega-2560 has no WiFi.

For a more detailed analysis please set the preferences like shown in this tutorial

best regards Stefan

I apologize for the lack of details... yes im using the board type mega2560, but how i will run the code in other if i try it it will return the error of compatibility?

i mean i have the esp-01s connected to my arduino mega and the arduino is running the code. (sorry about my grammar, so much time without training english, and it is not my native language)

please with your next posting give this a try:
write all your text in your native language and let do google translate do the translation.
This works very well. The grammar won't be brilliant but the more detailed description will make the text much better understandable than a short and poor self-written english posting.

The ESP01 is not a simple "sensor".
The ESP8266-01 is a more complex microcontroller than the arduino mega 2560!

There are two ways to make the Arduino-Mega communicate with your ESP8266-01

not recommended:
having a big hassle and trouble by using the original AT-firmware that is on your ESP-01

recommended:
writing your own code that is running on the ESP-01 by using the Arduino-IDE.

The most comfortable way would be to use an ESP8266 or an ESP32
stand-alone and leave away the arduino Mega 2560.

If this is really the best way depends on your project.
If you don't use more than 10 IO-pins and no ADC a ESP8266 nodeMCU can be used stand-alone.

You should at least describe what you want to do with the Wifi-connection.

best regards Stefan

To tell the truth, I use all pins from 22 to 53 of the digital ones and I also use others for buttons, displays, among others, so for what I need to do I need to use the mega 2560, so for me it is extremely important that they at least interact with each other

I want to make it emit a signal so I can connect with my cell phone, and I also want to use http post to send records to the database

Oh, I almost forgot to say, it will send information and retrieve it from a VPS on one of my domains

Sorry to say that. I do not understand what you want to say with that.
Very very unclear what you want to do.

my suggestion click here to see a text in language urdu

Use google translate to translate the urdu text into your native language.
آپ پنگ پونگ گیم کھیلتے ہوئے درجنوں مختصر الفاظ والی پوسٹنگ آگے پیچھے کر سکتے ہیں اور دو ہفتوں میں اس کا حل نکال سکتے ہیں۔
یا

میری تجویز:
بہت تفصیل سے لکھ رہے ہیں کہ آپ اپنے میں کیا کرنا چاہتے ہیں۔
علاقائی زبان
اور گوگل کو ترجمہ کرنے دیں۔
اور چند گھنٹوں میں ایک حل ہے.

یہ آپ پر منحصر ہے کہ آپ اس پروجیکٹ کو کتنی تیزی سے ختم کرنا چاہتے ہیں۔

Let's see if you have enough flexibilty to use google-translate

best regards Stefan

click here and then use google translate

اگر ESP8266-01 اور آپ کے سمارٹ فون کے درمیان کنکشن اسی مقامی وائی فائی نیٹ ورک سے قائم ہے، تو چھوٹے ویب سرور کو پروگرام کرنا نسبتاً آسان ہے۔

اگر آپ دنیا میں کہیں سے بھی جڑنا چاہتے ہیں، تو آپ کے ESP8266-01 کو یا تو ایک مستحکم IP ایڈریس کی ضرورت ہے یا آپ کو ایسی سروس استعمال کرنے کی ضرورت ہے جو ایک متحرک IP ایڈریس فراہم کرتی ہو۔

"میرے اسمارٹ فون سے جڑیں" کی تفصیل بہت غلط ہے۔ اس پر منحصر ہے کہ آپ بالکل کیا کرنا چاہتے ہیں، ویب سائٹ کے علاوہ کسی ٹیکنالوجی کا استعمال کرنا بہت آسان ہو سکتا ہے۔
لیکن آپ نے تفصیل سے بیان نہیں کیا۔ اس لیے آپ کوئی تجویز نہیں دے سکتے۔

آپ نے یہ بھی نہیں بتایا کہ آیا آپ صرف اسمارٹ فون پر کچھ ظاہر کرنا چاہتے ہیں یا آپ Arduino کو دور سے کنٹرول کرنا چاہتے ہیں۔ یہ تمام چیزیں اثر انداز ہوتی ہیں کہ کون سا حل بہترین ہے۔

مجھے نہیں معلوم کہ "VPS" کیا ہے۔

تو یا تو آپ بالکل واضح طور پر بیان کر سکتے ہیں کہ آپ کیا کرنا چاہتے ہیں یا آپ کو اسے خود ہی کرنا ہے۔

جب تک آپ اسے غلط طریقے سے بیان کرتے ہیں، کوئی بھی آپ کی مدد نہیں کر سکتا۔ یہاں تک کہ ایک AI بھی نہیں۔

ایک AI یقینی طور پر آپ کو جواب دے گا۔ لیکن جواب کام نہیں کرے گا۔ یا جواب میں ایک مختلف فعالیت ہے۔
ٹھیک ہے، کچھ لوگوں کو حقیقت میں کچھ غلط راستے آزمانے پڑتے ہیں جب تک کہ وہ واقعی یہ سمجھ نہ لیں کہ کیا اہم ہے۔

my bad about my issues with comunication:

Firstly, the VPS is a virtual machine that a server gives me access to and I can configure it via IP, I can also link a website to it to access any data there through it (of course considering the hierarchy of what that login is allowed to do)

the arduino mega 2560 is capturing temperatures from 10 different sensors and it will be able to record them, saving everything in a csv on an sd card, if it has an internet connection it will send all the records to the database in the cloud, and From this database I will pull it into a Power BI project to do analysis and graphs

Oh, before I forget, an I2C LCD is also used to be able to see the values on the screen and carry out calibration if necessary.

So this means your Mega 2560 will read in lines of text from an SD-Card and send these lines of text over a serial interface to the ESP8266.
The ESP8266 will send the data into the cloud.

You can do that with an ESP8266-01
image
but you have to either use the AT-firmware which is a big hassle
or you have to write your code with the arduino-IDE that runs
inside the ESP8266.

If you use an ESP8266-01 it is a big hassle to flash each new code-version into the ESP8266
Things will become much more comfortable if you use a
ESP8266-node MCU

or
even better
an ESP32

The reason is ESP8266-nodeMCU and ESP32-nodeMCU have their own USB-to-serial-adapter
You simply run two instances of the Arduino-IDEone for programming the Mega2560
one for programming the ESP

Mega-2560 and ESP communicate over a serial connection.

It will need some time to write your own code for the ESP32 but then you have the full flexibility to design the communication in the way you want it.
Much better than with using the AT-firmware

by the way
the code you have posted in your post #1
is more or less that code that will run inside the ESP

best regards Stefan

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