MEGA and ESP8266 communication between modules

What is the minimalistic way of establishing proper communication between MEGA and ESP8266 modules of this board MEGA and ESP8266? I'm fighting with addressing board pins from ESP8266. Thank you.

//Arduino MEGA+WiFi ATmega2560+ESP8266 4Mb CH340G
#include <ESP8266WiFi.h>
#include <WiFiClient.h>
#include <ESP8266WebServer.h>
/* Set these to your desired credentials. */
const char *ssid = "XXX"; //Enter your WIFI ssid
const char *password = "PPP"; //Enter your WIFI password

int myLED = 14;

ESP8266WebServer server(80);
void handleRoot() {
 server.send(200, "text/html", "<form action=\"/myLED_on\" method=\"get\" id=\"form1\"></form><button type=\"submit\" form=\"form1\" value=\"On\">On</button><form action=\"/myLED_off\" method=\"get\" id=\"form2\"></form><button type=\"submit\" form=\"form2\" value=\"Off\">Off</button>");
}
void handleSave() {
 if (server.arg("pass") != "") {
   Serial.println(server.arg("pass"));
 }
}
void setup() {
 pinMode(myLED, OUTPUT);
 delay(3000);
 Serial.begin(115200); //74880 , 115200
 Serial.println();
 Serial.print("Configuring access point...");
 WiFi.begin(ssid, password);
 while (WiFi.status() != WL_CONNECTED) {
   delay(500);
   Serial.print(".");
 }
 Serial.println("");
 Serial.println("WiFi connected");
 Serial.println("IP address: ");
 Serial.println(WiFi.localIP());
 server.on ( "/", handleRoot );
 server.on ("/save", handleSave);
 server.begin();
 Serial.println ( "HTTP server started" );
 server.on("/myLED_on", []() {
   digitalWrite(myLED, HIGH);
   delay(300);
   Serial.println("on");
   handleRoot();
 });
 server.on("/myLED_off", []() {
   digitalWrite(myLED, LOW);
   delay(300);
   Serial.println("off");
   handleRoot();
 });
}
void loop() {
 server.handleClient();
} 

they are connected by Serial or Serial3. you have 3 options:

  1. sketch for ATmega and sketch for esp8266. you have to code the Serial communication.
  2. firmware for esp8266 and sketch for ATmega.
  3. Firmata in ATmega and sketch in esp8266 using FirmataMaster library

in case 2) you can use for example AT firmware and my WiFiEspAT library in ATmega

using firmware has usually some limitations. but developing two cooperating sketches is more work.

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.

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