I have Mcufriend touch screen that iw installed on Arduino Mega and it's working fine I need to communicate message from Mega to ESP8266 via software serial
The Serial Pins are on Arduino Mega its Pin 51 and 53, and In ESP8266 it is D1 and D2
This communication works fine without TFT screen installed but when I install the Touch screen it is not communicating, I can see the Data in Serial Monitor on the Mega from where I am sending the data but not on ESP8266
Please advise what seems to be issue I am not using hardware serial using Serial1.Print because It was not working without the Screen
here is the code for ESP8266 side THat has been working
/*
This sketch sends a string to a TCP server, and prints a one-line response.
You must run a TCP server in your local network.
For example, on Linux you can use this command: nc -v -l 3000
*/
#include <SoftwareSerial.h>
SoftwareSerial NodeMcu_SoftSerial (D1,D2); //RX, TX
//Declare Global Variable
char c;
String dataIn;
#include <ESP8266WiFi.h>
#include <ESP8266WiFiMulti.h>
#ifndef STASSID
#define STASSID "DCCEX_79dce1"
#define STAPSK "PASS_79dce1"
#endif
const char* ssid = STASSID;
const char* password = STAPSK;
const char* host = "192.168.4.1";
const uint16_t port = 2560;
ESP8266WiFiMulti WiFiMulti;
void setup() {
Serial.begin(57600);
//Open Serial communication (Arduino-NodeMcu
NodeMcu_SoftSerial.begin(9600);
// We start by connecting to a WiFi network
WiFi.mode(WIFI_STA);
WiFiMulti.addAP(ssid, password);
Serial.println();
Serial.println();
Serial.print("Wait for WiFi... ");
while (WiFiMulti.run() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println("");
Serial.println("WiFi connected");
Serial.println("IP address: ");
Serial.println(WiFi.localIP());
delay(500);
}
void loop() {
Serial.print("connecting to ");
Serial.print(host);
Serial.print(':');
Serial.println(port);
// Use WiFiClient class to create TCP connections
WiFiClient client;
if (!client.connect(host, port)) {
Serial.println("connection failed");
Serial.println("wait 5 sec...");
delay(5000);
// return;
}
// This will send the request to the server
client.println("hello from ESP8266");
// read back one line from server
Serial.println("receiving from remote server");
String line = client.readStringUntil('\r');
Serial.println(line);
Serial.println("closing connection");
client.stop();
Serial.println("wait 5 sec...");
delay(5000);
while(NodeMcu_SoftSerial.available()>0)
{
c = NodeMcu_SoftSerial.read();
if(c=='\n') {break;}
else {dataIn+=c;}
}
if(c=='\n')
{
//Show data in to Serial Monitor
Serial.println(dataIn);
//Send Data Back to Arduino
NodeMcu_SoftSerial.print("Yeah I'am Good Bro :) \n");
//Reset the variable
c=0;
dataIn="";
}
}
Here is the code at Arduino Mega side
#include <SoftwareSerial.h>
//SoftwareSerial Arduino_SoftSerial (10,11); //RX, TX
SoftwareSerial Arduino_SoftSerial (53,51); //RX, TX
//Declare Global Variable
char c;
String dataIn;
void setup() {
// put your setup code here, to run once:
//Open Serial Communication (Arduino-PC)
Serial.begin(57600);
//Open Serial communication (Arduino-NodeMcu
Arduino_SoftSerial.begin(9600);
}
void loop() {
// put your main code here, to run repeatedly:
Arduino_SoftSerial.print("Are You OK Guys? \n");
delay(500);
while(Arduino_SoftSerial.available()>0)
{
c = Arduino_SoftSerial.read();
if(c=='\n') {break;}
else {dataIn+=c;}
}
if(c=='\n')
{
//Show incoming data to Serial Monitor
Serial.println(dataIn);
//Reset the Variable
c=0;
dataIn="";
}
}```