serial communication arduino Mega and esp8266-01

I am really despaired.. I need help :frowning:

I am a beginner with the esp266-01 and I have a Project that must be done in this month..
I don't know if my problem is a big or a small one :frowning: but it's really annoying, I have an Arduino mega and a esp266-01 and I just need to send a string from the Arduino to the ESP via the serial communication.. to be clear, my Arduino can read data coming from the ESP and print it in the serial

but the abused is not working.. and I don't know where is the problem
I use serial1 of the Mega..

can someone help me with a clear code and schematics please :frowning:

you guys are my last hope to finish the project ..

post your code here and we will help you troubleshoot it, also wouldn't be a bad idea telling us what you have connected to what...

this is my arduino code

//#include <SoftwareSerial.h>
#define espSerial Serial1

#include <LiquidCrystal.h> // Inclusion de la librairie pour afficheur LCD
const int RS=4; //declaration constante de broche 
const int E=5; //declaration constante de broche 
const int D4=6; //declaration constante de broche 
const int D5=7; //declaration constante de broche 
const int D6=8; //declaration constante de broche 
const int D7=9; //declaration constante de broche 
LiquidCrystal lcd(RS, E, D4, D5, D6, D7);// Création d'un objet LiquidCrystal = initialisation LCD en mode 4 bits
//SoftwareSerial mySerial(10, 3); // RX, TX
String routestep ;
String operation ;

void setup()
{
 Serial.begin(9600);
espSerial.begin(9600);
 delay(5000);
lcd.begin(16,2); // Initialise le LCD avec 20 colonnes x 4 lignes 

delay(10); // pause rapide pour laisser temps initialisation

  lcd.print("LCD OK") ; // affiche la chaîne texte - message de test
delay(2000); // pause de 2 secondes

lcd.clear(); // // efface écran et met le curseur en haut à gauche
delay(10); // pour laisser temps effacer écran
 }
 
void loop(){
 espSerial.print("41842580065IR");
 delay(2000);
 String IncomingString="";
 boolean StringReady = false;
 
 while (espSerial.available()){
   IncomingString=espSerial.readString();
   StringReady= true;
   routestep=IncomingString.substring(27, 32);
   operation=IncomingString.substring(47, 50);

  }
 
  if (StringReady){
    Serial.println("Received String: " + IncomingString);
  lcd.setCursor(0,0);    
lcd.print("R_S:") ; // affiche la chaîne texte - message de test
lcd.setCursor(5,0);    
lcd.print(routestep) ;
delay(5000);
 
lcd.setCursor(0,1);    
lcd.print("OPE:") ; // affiche la chaîne texte - message de test
lcd.setCursor(5,1);    
lcd.print(operation) ; 
delay(5000);
lcd.clear(); // // efface écran et met le curseur en haut à gauche
  }
 }

and this is my esp code

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>


 String payload ;
const char* ssid = "globalnet";
const char* password = "******";
        
void setup () {
 
  Serial.begin(9600);

  WiFi.begin(ssid, password);
 
  while (WiFi.status() != WL_CONNECTED) {
 
    delay(1000);
    Serial.print("Connecting..");
 
  }
 
}
 
void loop() {
  
  if (WiFi.status() == WL_CONNECTED) { //Check WiFi connection status
      //if (Serial.available()) 
 
  if (Serial.available()) {
   String data =(Serial.readString());
  }
 delay(1000);
  
    HTTPClient http;  //Declare an object of class HTTPClient

    String stringthree=  "http://ioa-solution.fr/plateforme/praestoo.api/api/v1/find_order?ksk="+data;
 
    http.begin(stringthree);  //Specify request destination
    int httpCode = http.GET();                                                                  //Send the request
 
    if (httpCode > 0) { //Check the returning code
 
      payload = http.getString();   //Get the request response payload
      Serial.print(payload);                     //Print the response payload

    }
    
  
    http.end();   //Close connection
 
  }
 
  delay(1000);    //Send a request every 30 seconds
 
}

and for the Circuit : i just put the tx1 of arduino in the RX of esp and the RX1 of the arduino in tx of the esp

tatersalad:
post your code here and we will help you troubleshoot it, also wouldn't be a bad idea telling us what you have connected to what...

and i really appreciate that you answer me :smiley:

I don't suppose it is critical, but your loop appears to be two seconds long, not thirty.

Belive me it works now and i just put 2 resistance on the tx of the arduino

safa_1997:
Belive me it works now

So, problem solved?

pert:
So, problem solved?

yes :smiley: