Good day,
I have an Arduino MEGA 2560 With WiFi and "built in"/"on board" ESP8266EX. The only link I could find that remotely describes this board is at this link.
I can upload sketches to the ESP8266EX and the Mega seperately with no issues using the DIP switches. However, I cannot seem to get the ESP8266EX to "talk" to the Mega via one of the UARTS. I can TX and RX (WiFi) between other ESP8266 modules (WeMos D1) with no problem.
So, at the moment I have a WeMos D1 with an HC-SR505 P.I.R motion sensor hooked up to it. When movement is sensed it turns on a local L.E.D (on the WeMos D1) and then sends "01" (via WiFi) to the Mega ESP8266EX module which in turn turns on a local L.E.D on pin 12 (GPI012) of the ESP8266EX board. This all works fine.
However, when the "built in"/"on-board" ESP8266EX module receives the "01" from the WeMos D1, I want it to tell the Mega that it had received a "01" by means of serial communication.
At the moment the ESP8266EX code looks like this:
#include <ESP8266WiFi.h>
#include <WiFiUdp.h>
#include <WiFiClient.h>
#include <SPI.h>
int motionActivityLED = 12;
const char* ssid = "ssid";
const char* pass = "pass";
unsigned int localPort = 2390;
char packetBuffer[255];
WiFiUDP Udp;
void setup()
{
Serial.begin(9600);
Serial.println();
pinMode(motionActivityLED, OUTPUT);
//Disconnect previous WiFi configurations
WiFi.disconnect();
IPAddress ip(10,0,0,43);
IPAddress gateway(10,0,0,1);
IPAddress subnet(255,255,255,0);
IPAddress dns(10,0,0,1);
WiFi.config(ip, gateway, subnet,dns);
WiFi.begin(ssid, pass);
WiFi.mode(WIFI_STA);
Serial.print("Connecting");
while (WiFi.status() != WL_CONNECTED)
{
delay(500);
Serial.print(".");
}
Serial.println();
Serial.print("Connected, IP address: ");
Serial.println(WiFi.localIP());
Udp.begin(localPort);
}
void loop() {
// if there's data available, read a packet
int packetSize = Udp.parsePacket();
if (packetSize)
{
// read the packet into packetBuffer
int len = Udp.read(packetBuffer, 255);
if (len > 0)
{
packetBuffer[len] = 0;
}
Serial.println(packetBuffer);
if (strcmp(packetBuffer,"01")==0) //Motion is detected
{
digitalWrite(motionActivityLED, HIGH);
Serial.print("01"); //Send this to the UART
}
else if (strcmp(packetBuffer,"02")==0) //No motion detected
{
digitalWrite(motionActivityLED, LOW);
Serial.print("02"); //Send this to the UART
}
// ATMega2560.write(packetBuffer);
}
}
And then on the Mega I have the following code to receive the incoming communication
char RXIncoming;
int RXLed = 12;
void setup() {
Serial.begin(9600);
pinMode(RXLed, OUTPUT);
}
void loop() {
RXIncoming = Serial.read();
Serial.println(RXIncoming);
if ( RXIncoming == "01" )
{
digitalWrite(RXLed, HIGH);
Serial3.println(RXIncoming);
}
else if ( RXIncoming == "02")
{
digitalWrite(RXLed, LOW);
Serial3.println(RXIncoming);
}
}
At the moment it seems as if either the ESP8266EX is not sending or the Mega is not receiving.
Thank you