Connecting Arduino Mega with ESP8266 via Software serial and McuFriend Touch screen installed SOLVED

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="";
      }
}```

Topic moved. Please do mot post in "Uncategorized"; see the sticky topics in Uncategorized - Arduino Forum.

And your 5V to/from 3.3V level translation circuitry is?

I find it hard to believe that all of the hardware serial ports on a Mega would simply "not work".

Software, which you haven't shown us, or hardware, which you haven't shown us, or wiring, which you haven't shown us.

Thanks for quick reply I have added the code in the post

I am not clear on this question can you polease elaborate

What is unclear? You have a 5V board hooked up to a 3.3V board. What are you using for level translation?

My Mega board was connected with USB port and my Esp8266 was also connected to USB port of my same computer no External Power for now

I did not ask about power, external or otherwise.

I did ask what you were using for level translation between the 5V Mega and 3.3V ESP8266.

I don't think I can help you any further. Good luck with your project.

Iam not using any Level Translator b/w Mega and Esp8266

This issue is resolved I am still using Software serial and adding "\n ; to the Print statement, which solved the problem on my TFT screen code
Arduino_SoftSerial.print("<T 0 1 1> \n");

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